Changeset 56 for trunk/UContact.pas


Ignore:
Timestamp:
Dec 8, 2021, 4:44:21 PM (3 years ago)
Author:
chronos
Message:
  • Added: Show textual name of contact field in contact field form and prefill field name and attributes. Update that name back according used field name and attributes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r55 r56  
    3030    cfVersion, cfAnniversary);
    3131
     32  { TContactField }
     33
    3234  TContactField = class
    3335    SysName: string;
     
    3840    ValueIndex: Integer;
    3941    DataType: TDataType;
     42    function GroupsContain(Name: string): Boolean;
     43    function Match(ASysName: string; AGroups: TStringArray): Boolean;
    4044  end;
    4145
     
    4650      Title: string; Index: TContactFieldIndex; DataType:
    4751      TDataType; ValueIndex: Integer = -1): TContactField;
     52    function GetBySysName(SysName: string): TContactField;
     53    function GetBySysNameGroups(SysName: string; Groups: TStringArray): TContactField;
    4854    function GetByIndex(Index: TContactFieldIndex): TContactField;
    4955    procedure LoadToStrings(AItems: TStrings);
     
    238244end;
    239245
     246{ TContactField }
     247
     248function TContactField.GroupsContain(Name: string): Boolean;
     249var
     250  I: Integer;
     251begin
     252  Result := False;
     253  for I := 0 to Length(Groups) - 1 do
     254    if Groups[I] = Name then begin
     255      Result := True;
     256      Break;
     257    end;
     258end;
     259
     260function TContactField.Match(ASysName: string; AGroups: TStringArray): Boolean;
     261var
     262  I: Integer;
     263begin
     264  Result := ASysName = SysName;
     265  if Result then begin
     266    for I := 0 to Length(AGroups) - 1 do begin
     267      if not GroupsContain(AGroups[I]) then begin
     268        Result := False;
     269        Break;
     270      end;
     271    end;
     272  end;
     273end;
     274
    240275{ TContactProperties }
    241276
     
    491526  Result.DataType := DataType;
    492527  Add(Result);
     528end;
     529
     530function TContactFields.GetBySysName(SysName: string): TContactField;
     531var
     532  I: Integer;
     533  C: Integer;
     534begin
     535  C := Count;
     536  I := 0;
     537  while (I < Count) and (Items[I].SysName <> SysName) do Inc(I);
     538  if I < Count then Result := Items[I]
     539    else Result := nil;
     540end;
     541
     542function TContactFields.GetBySysNameGroups(SysName: string; Groups: TStringArray
     543  ): TContactField;
     544var
     545  I: Integer;
     546  C: Integer;
     547begin
     548  C := Count;
     549  I := 0;
     550  while (I < Count) and not Items[I].Match(SysName, Groups) do Inc(I);
     551  if I < Count then Result := Items[I]
     552    else Result := nil;
    493553end;
    494554
Note: See TracChangeset for help on using the changeset viewer.