Hi there,
Can you pls help me with this, i am trying to implement this calendar an i cannot figure out what i am doing wrong.
This is my function which creates a new appointment in my own calendar file.
If i leave out the "CleanupStack::PopAndDestroy(&entryArray);" it seems to be working, but i am affraid of memory leaks.
Code:void CCallCalendar::NewApptL(const TDesC& aSubject, const TDesC& aStart, const TDesC& aEnd) { if(!iReady) //if this function is called too soon then return. Calendar opening { return; //must finish first. } TInt num = 0; TBuf8<16> newID; newID.Num(num); RPointerArray<CCalEntry> entryArray; CleanupStack::PushL(TCleanupItem(DestroyRPointerArray, &entryArray)); // Search for an ID not in use FillArray(entryArray); while(entryArray.Count() != 0) { num++; newID.Num(num); entryArray.ResetAndDestroy(); iCalEntryView->FetchL(newID, entryArray); } // Not necessary. because array.Count() is 0 // array.Reset(); // Set the new ID for the creating appointment HBufC8* guid = newID.AllocL(); CCalEntry* entry = CCalEntry::NewL(CCalEntry::EAppt, guid, CCalEntry::EMethodNone, 0); CleanupStack::PushL(entry); //Some data entry->SetSummaryL( _L("") ); entry->SetLocationL( _L("") ); //appt->SetDescriptionL( _L("limit") ); entry->SetDescriptionL(aSubject); TTime start,end; start.Set(aStart); end.Set(aEnd); TCalTime startCalTime; startCalTime.SetTimeUtcL(start); TCalTime endCalTime; //NullTTime() //Comment out the next line if you do not want to set end time endCalTime.SetTimeUtcL(end); //Set it entry->SetStartAndEndTimeL(startCalTime, endCalTime); //Store this new Entry entryArray.AppendL(entry); TInt success(0); iCalEntryView->StoreL(entryArray, success); //entryArray.Reset(); CleanupStack::PopAndDestroy(entry); CleanupStack::PopAndDestroy(&entryArray); }
Code:// Utility function to handle CCalEntry insert // Destroy the RPointerArray void DestroyRPointerArray(TAny* aPtr) { RPointerArray<CCalEntry>* self = static_cast<RPointerArray<CCalEntry>*> (aPtr); self->ResetAndDestroy(); }Code:// Fill the array with all the entries of the calendar void CCallCalendar::FillArray(RPointerArray<CCalEntry> &array) { TPtrC8 entryID; entryID.Set(iCalIter->FirstL()); while (entryID != KNullDesC8) { iCalEntryView->FetchL(entryID, array); entryID.Set(iCalIter->NextL()); } }

Reply With Quote

