FMX.AddressBook.TCustomAddressBook.CreateContact
Delphi
function CreateContact(const ASource: TAddressBookSource = nil): TAddressBookContact;
C++
TAddressBookContact* __fastcall CreateContact(TAddressBookSource* const ASource = (TAddressBookSource*)(0x0));
Properties
| Type | Visibility | Source | Unit | Parent |
|---|---|---|---|---|
| function | public | FMX.AddressBook.pas FMX.AddressBook.hpp |
FMX.AddressBook | TCustomAddressBook |
Description
Creates a new contact in the specified source in a device Address Book.
Use this method to create and add a new contact to the specified source in a device Address Book (Android or iOS).
Note If you call this method without the input argument
ASource, the source is considered to benil. In this scenario, for some types of mobile devices, we cannot ensure that the newly created contact is in sync with cloud-based storages.
Examples
To clarify, consider the following example. These code snippets illustrate how to create a new contact and specify the person First name, Last name, and Work email address. The sample application adds the newly created contact to the specified source in a device Address Book.
Note Before editing the contact email addresses, you should explicitly initialize an instance of the TContactEmails object using the TContactEmails.Create method (for Delphi) or new (for C++Builder).
Delphi:
var
Contact: TAddressBookContact;
EMails: TContactEmails;
Source: TAddressBookSource;
begin
// Create a new contact in the specified source.
Contact := AddressBook1.CreateContact(Source);
try
Contact.FirstName := 'James';
Contact.LastName := 'Stowner';
// Add the work mail
EMails := TContactEmails.Create;
try
eMails.AddEmail(TContactEmail.TLabelKind.Work, '[email protected]');
Contact.eMails := EMails;
finally
eMails.Free;
end;
AddressBook1.SaveContact(Contact);
finally
Contact.Free;
end;
end.
C++Builder:
{
TAddressBookContact *Contact;
TContactEmails *eMails;
TAddressBookSource *Source;
// Create a new contact in the specified source.
Contact = AddressBook1->CreateContact(Source);
__try {
// Add the contact first name and last name.
Contact->FirstName = "James";
Contact->LastName = "Stowner";
// Add the work mail
eMails = new TContactEmails();
__try {
eMails->AddEmail(TContactEmail::TLabelKind::Work,
"[email protected]");
Contact->EMails = eMails;
}
__finally {
eMails->Free();
}
// Save the newly created contact to Address Book.
AddressBook1->SaveContact(Contact);
}
__finally {
Contact->Free();
}
}
For more information and samples, see Mobile Tutorial: Using an Address Book Component (iOS and Android).