There quite some mistakes in this article.
First:
// Open the default contacts database: CContactDatabase* contactsDb = CContactDatabase::OpenL(); CleanupStack::PushL(contactsDb);
// Get the ID of the own card and open the contact: TContactItemId ownCardId = contactsDb->OwnCardId(); CContactItem* ownCard = contactsDb->ReadContactL(ownCardId); CleanupStack::PushL(ownCard);
TInt count = ownCard->CardFields().Count(); contactsDb->CloseContactL(ownCard->Id()); CleanupStack::PopAndDestroy(); // ownCard
There has to be CleanupStack::PopAndDestroy(2); // ownCard, contactsDb since contactsDb is pushed on cleanup stack
Second error is here:
TContactItemId ownCardId = contactsDb->OwnCardId(); CContactItem* ownCard = contactsDb->ReadContactL(ownCardId);
Since there isn't all the time an own card id, this code should be
TContactItemId ownCardId = contactsDb->OwnCardId(); if(ownCradId != KNullContactId) {
CContactItem* ownCard = contactsDb->ReadContactL(ownCardId);
}
For field indexing a check has to be made as well:
TInt index = ownCard->CardFields().Find(KUidContactFieldGivenName); ownCard->CardFields()[index].TextStorage()->SetTextL(KOtherForename);
Should be
TInt index = ownCard->CardFields().Find(KUidContactFieldGivenName); if(index != KErrNotfound) {
ownCard->CardFields()[index].TextStorage()->SetTextL(KOtherForename);
}
Also I think article should mention how contact ids for other contacts than owncard can be obtained
--Pirosl 10:58, 15 September 2009 (UTC)