Changeset 8 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 1, 2018, 12:51:32 PM (6 years ago)
Author:
chronos
Message:
  • Added: Show all fields tab in contact form.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r3 r8  
    99
    1010type
     11  TContactsFile = class;
     12
    1113  TStringEvent = procedure (Text: string) of object;
    1214
     15  TDataType = (dtString, dtInteger, dtDate, dtDateTime, dtImage);
     16
     17  TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName);
     18
     19  TContactField = class
     20    Name: string;
     21    Index: TContactFieldIndex;
     22    DataType: TDataType;
     23  end;
     24
     25  { TContactFields }
     26
     27  TContactFields = class(TObjectList)
     28    function AddNew(Name: string; Index: TContactFieldIndex; DataType:
     29      TDataType): TContactField;
     30  end;
     31
     32  { TContact }
     33
    1334  TContact = class
     35  private
     36    function GetField(Index: TContactFieldIndex): string;
     37    procedure SetField(Index: TContactFieldIndex; AValue: string);
     38  public
     39    Parent: TContactsFile;
    1440    Version: string;
    1541    FirstName: string;
     
    4470    Photo: string;
    4571    XJabber: string;
     72    property Fields[Index: TContactFieldIndex]: string read GetField write SetField;
    4673  end;
    4774
    4875  TContacts = class(TObjectList)
    49 
     76    ContactsFile: TContactsFile;
    5077  end;
    5178
     
    5683    FOnError: TStringEvent;
    5784    function GetNext(var Text: string; Separator: string): string;
     85    procedure InitFields;
    5886  public
     87    Fields: TContactFields;
    5988    Contacts: TContacts;
    6089    function GetFileName: string; override;
     
    75104  SUnknownCommand = 'Unknown command: %s';
    76105
     106{ TContactFields }
     107
     108function TContactFields.AddNew(Name: string; Index: TContactFieldIndex;
     109  DataType: TDataType): TContactField;
     110begin
     111  Result := TContactField.Create;
     112  Result.Name := Name;
     113  Result.Index := Index;
     114  Result.DataType := DataType;
     115  Add(Result);
     116end;
     117
     118{ TContact }
     119
     120function TContact.GetField(Index: TContactFieldIndex): string;
     121begin
     122  case Index of
     123    cfFirstName: Result := FirstName;
     124    cfMiddleName: Result := MiddleName;
     125    cfLastName: Result := LastName;
     126  end;
     127end;
     128
     129procedure TContact.SetField(Index: TContactFieldIndex; AValue: string);
     130begin
     131  case Index of
     132    cfFirstName: FirstName := AValue;
     133    cfMiddleName: MiddleName := AValue;
     134    cfLastName: LastName := AValue;
     135  end;
     136end;
     137
    77138{ TContactsFile }
    78139
     
    85146    Result := Text;
    86147    Text := '';
     148  end;
     149end;
     150
     151procedure TContactsFile.InitFields;
     152begin
     153  with Fields do begin
     154    AddNew('First Name', cfFirstName, dtString);
     155    AddNew('Middle Name', cfMiddleName, dtString);
     156    AddNew('Last Name', cfLastName, dtString);
    87157  end;
    88158end;
     
    118188        Add('N:' + LastName + ';' + FirstName + ';' + MiddleName + ';' + TitleBefore + ';' + TitleAfter);
    119189      if FullName <> '' then Add('FN:' + FullName);
    120       if TelCell <> '' then Add('TEL;PREF;CELL:' + TelPrefCell);
     190      if TelPrefCell <> '' then Add('TEL;PREF;CELL:' + TelPrefCell);
    121191      if TelCell <> '' then Add('TEL;CELL:' + TelCell);
    122192      if TelHome <> '' then Add('TEL;HOME:' + TelHome);
     
    157227  NewRecord: TContact;
    158228  Command: string;
    159   CommandParam: string;
    160229  CommandPart: string;
    161230  Charset: string;
     
    175244      if Line = 'BEGIN:VCARD' then begin
    176245        NewRecord := TContact.Create;
     246        NewRecord.Parent := Self;
    177247      end else
    178248      if Line = 'END:VCARD' then begin
     
    244314  inherited;
    245315  Contacts := TContacts.Create;
     316  Contacts.ContactsFile := Self;
     317  Fields := TContactFields.Create;
     318  InitFields;
    246319end;
    247320
    248321destructor TContactsFile.Destroy;
    249322begin
    250   Contacts.Free;
     323  FreeAndNil(Fields);
     324  FreeAndNil(Contacts);
    251325  inherited;
    252326end;
Note: See TracChangeset for help on using the changeset viewer.