Ignore:
Timestamp:
Nov 25, 2021, 1:18:44 AM (3 years ago)
Author:
chronos
Message:
  • Modified: Store contact properties in general way to support also user defined properties and unknown attributes.
  • Added: Show contact image in contact edit window.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContact.pas

    r29 r31  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ActnList, Menus, UContact;
     9  ComCtrls, ActnList, Menus, ExtCtrls, UContact, base64;
    1010
    1111type
     
    4040    EditName: TEdit;
    4141    EditCellPhone: TEdit;
     42    ImagePhoto: TImage;
    4243    Label1: TLabel;
    4344    Label10: TLabel;
     
    5556    Label21: TLabel;
    5657    Label22: TLabel;
     58    Label23: TLabel;
    5759    LabelOrganization: TLabel;
    5860    Label3: TLabel;
     
    110112procedure TFormContact.ListView1Data(Sender: TObject; Item: TListItem);
    111113begin
    112   if Item.Index < Contact.Parent.Fields.Count then
    113   with TContactField(Contact.Parent.Fields[Item.Index]) do begin
    114     Item.Caption := Name;
    115     Item.SubItems.Add(Contact.Fields[Index]);
     114  if Item.Index < Contact.Properties.Count then
     115  with Contact.Properties[Item.Index] do begin
     116    Item.Caption := Contact.Properties[Item.Index].Name;
     117    Item.SubItems.Add(Attributes.DelimitedText);
     118    Item.SubItems.Add(Contact.Properties[Item.Index].Values.DelimitedText);
     119    Item.Data := Contact.Properties[Item.Index];
    116120  end;
    117121end;
     
    125129begin
    126130  if Assigned(Contact) then begin
    127     ListView1.Items.Count := Contact.Parent.Fields.Count;
     131    ListView1.Items.Count := Contact.Properties.Count;
    128132  end else ListView1.Items.Count := 0;
    129133  ListView1.Refresh;
     
    139143begin
    140144  if Assigned(ListView1.Selected) then begin
    141     Contact.Fields[TContactFieldIndex(ListView1.Selected.Index)] :=
    142       InputBox(SFieldEdit, SEditFieldValue, Contact.Fields[TContactFieldIndex(ListView1.Selected.Index)]);
     145    TContactProperty(ListView1.Selected.Data).Values.DelimitedText :=
     146      InputBox(SFieldEdit, SEditFieldValue, TContactProperty(ListView1.Selected.Data).Values.DelimitedText);
    143147  end;
    144148end;
     
    152156
    153157procedure TFormContact.LoadData(Contact: TContact);
     158var
     159  Photo: string;
     160  JpegImage: TJpegImage;
     161  Stream: TMemoryStream;
     162  PhotoProperty: TContactProperty;
    154163begin
    155164  Self.Contact := Contact;
    156   EditName.Text := Contact.FirstName;
    157   EditSurname.Text := Contact.LastName;
    158   EditCellPhone.Text := Contact.TelCell;
    159   EditPhoneHome.Text := Contact.TelHome;
    160   EditPhoneWork.Text := Contact.TelWork;
    161   EditEmail.Text := Contact.EmailHome;
    162   MemoNotes.Lines.Text := Contact.Note;
    163   EditTitle.Text := Contact.Title;
    164   EditOrganization.Text := Contact.Organization;
    165   EditAddress.Text := Contact.AdrHome;
    166   EditEmailHome.Text := Contact.EmailHome;
     165  EditName.Text := Contact.Fields[cfFirstName];
     166  EditSurname.Text := Contact.Fields[cfLastName];
     167  EditCellPhone.Text := Contact.Fields[cfTelCell];
     168  EditPhoneHome.Text := Contact.Fields[cfTelHome];
     169  EditPhoneWork.Text := Contact.Fields[cfTelWork];
     170  EditEmail.Text := Contact.Fields[cfEmail];
     171  MemoNotes.Lines.Text := Contact.Fields[cfNote];
     172  EditTitle.Text := Contact.Fields[cfTitle];
     173  EditOrganization.Text := Contact.Fields[cfOrganization];
     174  EditAddress.Text := Contact.Fields[cfAdrHome];
     175  EditEmailHome.Text := Contact.Fields[cfEmailHome];
     176
     177  ImagePhoto.Picture.Bitmap.Clear;
     178  PhotoProperty := Contact.GetProperty(cfPhoto);
     179  if Assigned(PhotoProperty) then begin
     180    Photo := Contact.Fields[cfPhoto];
     181    if (Photo <> '') and (PhotoProperty.Encoding <> '') then begin
     182      Photo := PhotoProperty.GetDecodedValue;
     183      Stream := TMemoryStream.Create;
     184      Stream.Write(Photo[1], Length(Photo));
     185      Stream.Position := 0;
     186      JpegImage := TJPEGImage.Create;
     187      JpegImage.LoadFromStream(Stream);
     188      ImagePhoto.Picture.Bitmap.SetSize(JpegImage.Width, JpegImage.Height);
     189      ImagePhoto.Picture.Bitmap.Canvas.Draw(0, 0, JpegImage);
     190      JpegImage.Free;
     191      Stream.Free;
     192    end;
     193  end;
    167194end;
    168195
    169196procedure TFormContact.SaveData(Contact: TContact);
    170197begin
    171   Contact.FirstName := EditName.Text;
    172   Contact.LastName := EditSurname.Text;
    173   Contact.TelCell := EditCellPhone.Text;
    174   Contact.TelHome := EditPhoneHome.Text;
    175   Contact.TelWork := EditPhoneWork.Text;
    176   Contact.EmailHome := EditEmail.Text;
    177   Contact.Note := MemoNotes.Lines.Text;
    178   Contact.Title := EditTitle.Text;
    179   Contact.Organization := EditOrganization.Text;
    180   Contact.AdrHome := EditAddress.Text;
    181   Contact.EmailHome := EditEmailHome.Text;
     198  Contact.Fields[cfFirstName] := EditName.Text;
     199  Contact.Fields[cfLastName] := EditSurname.Text;
     200  Contact.Fields[cfTelCell] := EditCellPhone.Text;
     201  Contact.Fields[cfTelHome] := EditPhoneHome.Text;
     202  Contact.Fields[cfTelWork] := EditPhoneWork.Text;
     203  Contact.Fields[cfEmail] := EditEmail.Text;
     204  Contact.Fields[cfNote] := MemoNotes.Lines.Text;
     205  Contact.Fields[cfTitle] := EditTitle.Text;
     206  Contact.Fields[cfOrganization] := EditOrganization.Text;
     207  Contact.Fields[cfAdrHome] := EditAddress.Text;
     208  Contact.Fields[cfEmailHome] := EditEmailHome.Text;
    182209end;
    183210
Note: See TracChangeset for help on using the changeset viewer.