Changeset 8 for trunk/UContact.pas
- Timestamp:
- Feb 1, 2018, 12:51:32 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r3 r8 9 9 10 10 type 11 TContactsFile = class; 12 11 13 TStringEvent = procedure (Text: string) of object; 12 14 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 13 34 TContact = class 35 private 36 function GetField(Index: TContactFieldIndex): string; 37 procedure SetField(Index: TContactFieldIndex; AValue: string); 38 public 39 Parent: TContactsFile; 14 40 Version: string; 15 41 FirstName: string; … … 44 70 Photo: string; 45 71 XJabber: string; 72 property Fields[Index: TContactFieldIndex]: string read GetField write SetField; 46 73 end; 47 74 48 75 TContacts = class(TObjectList) 49 76 ContactsFile: TContactsFile; 50 77 end; 51 78 … … 56 83 FOnError: TStringEvent; 57 84 function GetNext(var Text: string; Separator: string): string; 85 procedure InitFields; 58 86 public 87 Fields: TContactFields; 59 88 Contacts: TContacts; 60 89 function GetFileName: string; override; … … 75 104 SUnknownCommand = 'Unknown command: %s'; 76 105 106 { TContactFields } 107 108 function TContactFields.AddNew(Name: string; Index: TContactFieldIndex; 109 DataType: TDataType): TContactField; 110 begin 111 Result := TContactField.Create; 112 Result.Name := Name; 113 Result.Index := Index; 114 Result.DataType := DataType; 115 Add(Result); 116 end; 117 118 { TContact } 119 120 function TContact.GetField(Index: TContactFieldIndex): string; 121 begin 122 case Index of 123 cfFirstName: Result := FirstName; 124 cfMiddleName: Result := MiddleName; 125 cfLastName: Result := LastName; 126 end; 127 end; 128 129 procedure TContact.SetField(Index: TContactFieldIndex; AValue: string); 130 begin 131 case Index of 132 cfFirstName: FirstName := AValue; 133 cfMiddleName: MiddleName := AValue; 134 cfLastName: LastName := AValue; 135 end; 136 end; 137 77 138 { TContactsFile } 78 139 … … 85 146 Result := Text; 86 147 Text := ''; 148 end; 149 end; 150 151 procedure TContactsFile.InitFields; 152 begin 153 with Fields do begin 154 AddNew('First Name', cfFirstName, dtString); 155 AddNew('Middle Name', cfMiddleName, dtString); 156 AddNew('Last Name', cfLastName, dtString); 87 157 end; 88 158 end; … … 118 188 Add('N:' + LastName + ';' + FirstName + ';' + MiddleName + ';' + TitleBefore + ';' + TitleAfter); 119 189 if FullName <> '' then Add('FN:' + FullName); 120 if Tel Cell <> '' then Add('TEL;PREF;CELL:' + TelPrefCell);190 if TelPrefCell <> '' then Add('TEL;PREF;CELL:' + TelPrefCell); 121 191 if TelCell <> '' then Add('TEL;CELL:' + TelCell); 122 192 if TelHome <> '' then Add('TEL;HOME:' + TelHome); … … 157 227 NewRecord: TContact; 158 228 Command: string; 159 CommandParam: string;160 229 CommandPart: string; 161 230 Charset: string; … … 175 244 if Line = 'BEGIN:VCARD' then begin 176 245 NewRecord := TContact.Create; 246 NewRecord.Parent := Self; 177 247 end else 178 248 if Line = 'END:VCARD' then begin … … 244 314 inherited; 245 315 Contacts := TContacts.Create; 316 Contacts.ContactsFile := Self; 317 Fields := TContactFields.Create; 318 InitFields; 246 319 end; 247 320 248 321 destructor TContactsFile.Destroy; 249 322 begin 250 Contacts.Free; 323 FreeAndNil(Fields); 324 FreeAndNil(Contacts); 251 325 inherited; 252 326 end;
Note:
See TracChangeset
for help on using the changeset viewer.