Changeset 108 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 11, 2022, 11:31:42 AM (3 years ago)
Author:
chronos
Message:
  • Fixed: Do not update interface in contact properties if the listview doesn't have handle yet.
  • Added: Synced update of full name and name parts in contact form.
  • Modified: Improved image loading code by image format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r104 r108  
    141141    function GetProperty(Field: TContactField): TContactProperty; overload;
    142142    function GetProperty(FieldIndex: TContactFieldIndex): TContactProperty; overload;
     143    procedure FullNameToNameParts(FullName: string; out Before, First, Middle,
     144      Last, After: string);
     145    function NamePartsToFullName(Before, First, Middle, Last, After: string): string;
    143146    procedure Assign(Source: TContact);
    144147    function UpdateFrom(Source: TContact): Boolean;
     
    11161119end;
    11171120
     1121function IsNumber(Text: string): Boolean;
     1122var
     1123  Value: Integer;
     1124begin
     1125  Result := TryStrToInt(Text, Value);
     1126end;
     1127
     1128function IsRomanNumber(Text: string): Boolean;
     1129var
     1130  I: Integer;
     1131begin
     1132  Result := True;
     1133  for I := 1 to Length(Text) do
     1134    if not (Text[I] in ['I', 'V', 'X', 'L', 'C', 'D', 'M']) then begin
     1135      Result := False;
     1136      Break;
     1137    end;
     1138end;
     1139
     1140procedure TContact.FullNameToNameParts(FullName: string; out Before, First,
     1141  Middle, Last, After: string);
     1142var
     1143  Parts: TStringArray;
     1144  I, J: Integer;
     1145begin
     1146  Before := '';
     1147  First := '';
     1148  Middle := '';
     1149  Last := '';
     1150  After := '';
     1151  while Pos('  ', FullName) > 0 do
     1152    FullName := StringReplace(FullName, '  ', ' ', [rfReplaceAll]);
     1153  Parts := Explode(' ', Trim(FullName));
     1154
     1155  // Title before
     1156  while (Length(Parts) > 0) and EndsWith(Parts[0], '.') do begin
     1157    Before := Trim(Before + ' ' + Parts[0]);
     1158    Delete(Parts, 0, 1);
     1159  end;
     1160
     1161  // Title after
     1162  for I := 0 to High(Parts) do
     1163    if (Pos('.', Parts[I]) > 0) or IsNumber(Parts[I]) or IsRomanNumber(Parts[I]) then begin
     1164      for J := I to High(Parts) do
     1165        After := Trim(After + ' ' + Parts[J]);
     1166      SetLength(Parts, I);
     1167      Break;
     1168    end;
     1169
     1170  if Length(Parts) = 0 then begin
     1171  end else
     1172  if Length(Parts) = 1 then begin
     1173    First := Parts[0];
     1174  end else
     1175  if Length(Parts) = 2 then begin
     1176    First := Parts[0];
     1177    Last := Parts[1];
     1178  end else begin
     1179    First := Parts[0];
     1180    for I := 0 to Length(Parts) - 3 do
     1181      Middle := Trim(Middle + ' ' + Parts[I + 1]);
     1182    Last := Parts[High(Parts)];
     1183  end;
     1184end;
     1185
     1186function TContact.NamePartsToFullName(Before, First, Middle, Last, After: string
     1187  ): string;
     1188begin
     1189  Result := '';
     1190  if Before <> '' then Result := Result + ' ' + Before;
     1191  if First <> '' then Result := Result + ' ' + First;
     1192  if Middle <> '' then Result := Result + ' ' + Middle;
     1193  if Last <> '' then Result := Result + ' ' + Last;
     1194  if After <> '' then Result := Result + ' ' + After;
     1195  Result := Trim(Result);
     1196end;
     1197
    11181198procedure TContact.Assign(Source: TContact);
    11191199begin
Note: See TracChangeset for help on using the changeset viewer.