Changeset 3 for trunk/UContact.pas


Ignore:
Timestamp:
Jan 29, 2018, 10:54:40 AM (7 years ago)
Author:
chronos
Message:
  • Added: Allow to edit more contacts fields.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        55*.lps
        66*.res
         7vCardStudio.exe
  • trunk/UContact.pas

    r1 r3  
    5757    function GetNext(var Text: string; Separator: string): string;
    5858  public
    59     Records: TContacts;
     59    Contacts: TContacts;
    6060    function GetFileName: string; override;
    6161    function GetFileExt: string; override;
     
    7373resourcestring
    7474  SVCardFile = 'vCard file';
     75  SUnknownCommand = 'Unknown command: %s';
    7576
    7677{ TContactsFile }
     
    110111  try
    111112    Output := TStringList.Create;
    112     for I := 0 to Records.Count - 1 do
    113     with TContact(Records[I]), Output do begin
     113    for I := 0 to Contacts.Count - 1 do
     114    with TContact(Contacts[I]), Output do begin
    114115      Add('BEGIN:VCARD');
    115116      if Version <> '' then Add('VERSION:' + Version);
     
    160161  Charset: string;
    161162  Encoding: string;
    162 begin
    163   inherited;
    164   Records.Clear;
     163  CommandItems: TStringList;
     164begin
     165  inherited;
     166  Contacts.Clear;
    165167  Lines := TStringList.Create;
    166168  Lines.LoadFromFile(FileName);
    167169  try
     170    CommandItems := TStringList.Create;
     171    CommandItems.Delimiter := ';';
    168172    I := 0;
    169173    while I < Lines.Count do begin
     
    173177      end else
    174178      if Line = 'END:VCARD' then begin
    175         Records.Add(NewRecord);
     179        Contacts.Add(NewRecord);
    176180        NewRecord := nil;
    177181      end else
    178182      if Pos(':', Line) > 0 then begin
    179183        CommandPart := GetNext(Line, ':');
    180         Command := GetNext(CommandPart, ';');
    181         while CommandPart <> '' do begin
    182           CommandParam := GetNext(CommandPart, ';');
    183           if CommandParam = 'CHARSET' then begin
    184             GetNext(CommandParam, '=');
    185             Charset := CommandParam;
    186           end else
    187           if CommandParam = 'ENCODING' then begin
    188             GetNext(CommandParam, '=');
    189             Encoding := CommandParam;
    190           end else if Assigned(FOnError) then FOnError('Unknown command param: ' + CommandParam);
     184        CommandItems.DelimitedText := CommandPart;
     185        if CommandItems.IndexOfName('CHARSET') >= 0 then begin
     186          Charset := CommandItems.Values['CHARSET'];
     187          CommandItems.Delete(CommandItems.IndexOfName('CHARSET'));
     188        end
     189        else if CommandItems.IndexOfName('ENCODING') >= 0 then begin
     190          Encoding := CommandItems.Values['ENCODING'];
     191          CommandItems.Delete(CommandItems.IndexOfName('ENCODING'));
    191192        end;
     193        Command := CommandItems.DelimitedText;
     194
    192195        if Command = 'FN' then NewRecord.FullName := Line
    193196        else if Command = 'N' then begin
     
    212215        else if Command = 'X-NICKNAME' then NewRecord.NickName := Line
    213216        else if Command = 'EMAIL;HOME' then NewRecord.EmailHome := Line
    214         else if Command = 'EMAIL;INTERNET' then NewRecord.EmailInternet := Line
     217        else if Command = 'EMAIL:INTERNET' then NewRecord.EmailInternet := Line
    215218        else if Command = 'NOTE' then NewRecord.Note := Line
    216219        else if Command = 'ORG' then NewRecord.Organization := Line
     
    231234      Inc(I);
    232235    end;
     236    CommandItems.Free;
    233237  finally
    234238    Lines.Free;
     
    239243begin
    240244  inherited;
    241   Records := TContacts.Create;
     245  Contacts := TContacts.Create;
    242246end;
    243247
    244248destructor TContactsFile.Destroy;
    245249begin
    246   Records.Free;
     250  Contacts.Free;
    247251  inherited;
    248252end;
Note: See TracChangeset for help on using the changeset viewer.