Einzelnen Beitrag anzeigen

Classic12

Registriert seit: 5. Jun 2020
3 Beiträge
 
#1

How do I extract the array of contact telephone numbers using Delphi FMX TAddressboo

  Alt 5. Jun 2020, 10:15
Delphi-Version: 10.3 Rio
Delphi 10.3.
Cross platform application.
Android & IOS.
I am using the TAddressbook component and the following code adapted from the Delphi code examples.
I am able to get the names and photos but cannot workout the syntax for the phone numbers.
The code fills the Listview with firstname / surname & image but the Contact.Phones seems to be an array.

I found this in the documentation

Code:
    Phones.AddPhone(TContactPhone.TLabelKind.Mobile, '+33-6-46-51-3531');
    So I need something like this
    Phones.Extract(TContactPhone.TLabelKind.Mobile); // Does not work.


Code:
```

procedure TformMain.FillContactList(Source: TAddressBookSource);
var
I: Integer;
Contacts: TAddressBookContacts;
begin
Contacts := TAddressBookContacts.Create;
try
AddressBook1.AllContacts(Source, Contacts);
ListViewContacts.BeginUpdate;
try
ListViewContacts.Items.Clear;
for I := 0 to Contacts.Count - 1 do
AddListViewItem(Contacts.Items[I]);
finally
ListViewContacts.EndUpdate;
end;
finally
Contacts.Free;
end;
end;
procedure TformMain.AddListViewItem(Contact: TAddressBookContact);
var
ListViewItem: TListViewItem;
begin
ListViewItem := ListViewContacts.Items.Add;
try
ListViewItem.Data['Text1'] := Contact.DisplayName;
ListViewItem.Data['Text2'] := Contact.Phones;
ListViewItem.Data['Image3'] := Contact.PhotoThumbnail;

//ListViewItem.Text := Contact.DisplayName;
//ListViewItem.Text2:= Contact.Phones;
ListViewItem.Tag := Contact.ID;
finally
ListViewItem.Free;
end;
end;



eMails: TContactEmails;
phones: TContactPhones;
c : TAddressBookContact;
//phoneType : TLabelKind ;
begin
// Contact.DisplayName <> '' then
// eMails.AddEmail(TContactEmail.TLabelKind.Work, edtWorkMail.Text);
// if (Contacts.Items[I].Phones.Count >= 1) and (not Contacts.Items[I].Phones[0].Number.IsEmpty) then
// LItem.Data[TMultiDetailAppearanceNames.Detail1] := Contacts.Items[I].Phones[0].Number;
phones := Contact.Phones;
if Contact.DisplayName.Length > 0 then
begin
ListViewItem := ListViewContacts.Items.Add;
try
ListViewItem.Data['Text1'] := Contact.DisplayName;
// TLabelKind = (Custom, Home, Mobile, Work, iPhone, FaxWork, FaxHome, FaxOther, Pager, Other, Callback, Car, CompanyMain,ISDN, Main, Radio, Telex, TTYTDD, WorkMobile, WorkPager, Assistant);
ListViewItem.Data['Text2'] := c.Phones.First.LabelKind.Mobile.t;// Phones.IndexOf('Mobile');
ListViewItem.Data['Text2'] := Contact.Phones.ExtractItem('Mobile');
ListViewItem.Data['Text2'] := Contact.Phones.Extract.LabelKind('Mobile');
ListViewItem.Data['Text2'] := Contact.Phones.ExtractAt.LabelKind.Mobile;//('Mobile');
phones := Contact.Phones.ExtractItem.LabelKind.Mobile; //.TLabelKind.Mobile;// .Phones.Extract(Mobile);
ListViewItem.Data['Text2'] := phones.ExtractAt.LabelKind.Mobile;// Extract.LabelKind.Mobile;// ExtractItem.LabelKind.Mobile;// Contact.Phones.Extract('Mobile').ToString;// Phones.Extract.TLabelKind.;
ListViewItem.Data['Text2'] := phones.Extract.LabelKind.Mobile;// Contact.Phones Items[0].TLabelKind. .Number;// .Items[0];
ListViewItem.Data['Image3'] := Contact.PhotoThumbnail;
//ListViewItem.Text := Contact.DisplayName;
//ListViewItem.Text2:= Contact.Phones;
ListViewItem.Tag := Contact.ID;
```
  Mit Zitat antworten Zitat