Ignore:
Timestamp:
Feb 8, 2022, 6:07:35 PM (3 years ago)
Author:
chronos
Message:
  • Added: Buttons to show contact home and work addresses on online map. Predefined map uses openstreetmap.org.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContact.pas

    r100 r101  
    1919    APhotoLoad: TAction;
    2020    ActionList1: TActionList;
     21    ButtonHomeAddressShow: TButton;
    2122    ButtonCancel: TButton;
     23    ButtonWorkAddressShow: TButton;
    2224    ButtonNext: TButton;
    2325    ButtonOk: TButton;
     
    5254    EditHomeAddressStreet: TEdit;
    5355    EditHomeAddressStreetExtended: TEdit;
    54     EditAddressWorkCity: TEdit;
    55     EditAddressWorkCountry: TEdit;
    56     EditAddressWorkPostalCode: TEdit;
    57     EditAddressWorkPostOfficeBox: TEdit;
    58     EditAddressWorkRegion: TEdit;
    59     EditAddressWorkStreet: TEdit;
    60     EditAddressWorkStreetExtended: TEdit;
     56    EditWorkAddressCity: TEdit;
     57    EditWorkAddressCountry: TEdit;
     58    EditWorkAddressPostalCode: TEdit;
     59    EditWorkAddressPostOfficeBox: TEdit;
     60    EditWorkAddressRegion: TEdit;
     61    EditWorkAddressStreet: TEdit;
     62    EditWorkAddressStreetExtended: TEdit;
    6163    EditAniversary: TEdit;
    6264    EditJabber: TEdit;
     
    192194    procedure APhotoLoadExecute(Sender: TObject);
    193195    procedure APhotoSaveExecute(Sender: TObject);
     196    procedure ButtonHomeAddressShowClick(Sender: TObject);
    194197    procedure ButtonNextClick(Sender: TObject);
    195198    procedure ButtonPreviousClick(Sender: TObject);
     199    procedure ButtonWorkAddressShowClick(Sender: TObject);
    196200    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    197201    procedure FormCreate(Sender: TObject);
     
    254258begin
    255259  Result := FormatDateTime('yyyy-mm-dd', Date);
     260end;
     261
     262function URLEncode(Text: string): string;
     263var
     264  I: Integer;
     265begin
     266  Result := '';
     267  for I := 1 to Length(Text) do begin
     268    if not (Text[I] in ['A'..'Z', 'a'..'z', '0'..'9', '-', '_', '~', '.', ':', '/']) then
     269      Result := Result + '%' + IntToHex(Ord(Text[I]), 2)
     270    else
     271      Result := Result + Text[I];
     272  end;
    256273end;
    257274
     
    677694  Contact.Fields[cfOrganization] := EditOrganization.Text;
    678695  Contact.Fields[cfDepartment] := EditDepartment.Text;
    679   Contact.Fields[cfWorkAddressPostOfficeBox] := EditAddressWorkPostOfficeBox.Text;
    680   Contact.Fields[cfWorkAddressStreet] := EditAddressWorkStreet.Text;
    681   Contact.Fields[cfWorkAddressStreetExtended] := EditAddressWorkStreetExtended.Text;
    682   Contact.Fields[cfWorkAddressCity] := EditAddressWorkCity.Text;
    683   Contact.Fields[cfWorkAddressRegion] := EditAddressWorkRegion.Text;
    684   Contact.Fields[cfWorkAddressCountry] := EditAddressWorkCountry.Text;
    685   Contact.Fields[cfWorkAddressPostalCode] := EditAddressWorkPostalCode.Text;
     696  Contact.Fields[cfWorkAddressPostOfficeBox] := EditWorkAddressPostOfficeBox.Text;
     697  Contact.Fields[cfWorkAddressStreet] := EditWorkAddressStreet.Text;
     698  Contact.Fields[cfWorkAddressStreetExtended] := EditWorkAddressStreetExtended.Text;
     699  Contact.Fields[cfWorkAddressCity] := EditWorkAddressCity.Text;
     700  Contact.Fields[cfWorkAddressRegion] := EditWorkAddressRegion.Text;
     701  Contact.Fields[cfWorkAddressCountry] := EditWorkAddressCountry.Text;
     702  Contact.Fields[cfWorkAddressPostalCode] := EditWorkAddressPostalCode.Text;
    686703  Contact.Fields[cfUrlWork] := EditWorkWeb.Text;
    687704
     
    699716  EditOrganization.Text := Contact.Fields[cfOrganization];
    700717  EditDepartment.Text := Contact.Fields[cfDepartment];
    701   EditAddressWorkPostOfficeBox.Text := Contact.Fields[cfWorkAddressPostOfficeBox];
    702   EditAddressWorkStreet.Text := Contact.Fields[cfWorkAddressStreet];
    703   EditAddressWorkStreetExtended.Text := Contact.Fields[cfWorkAddressStreetExtended];
    704   EditAddressWorkCity.Text := Contact.Fields[cfWorkAddressCity];
    705   EditAddressWorkRegion.Text := Contact.Fields[cfWorkAddressRegion];
    706   EditAddressWorkCountry.Text := Contact.Fields[cfWorkAddressCountry];
    707   EditAddressWorkPostalCode.Text := Contact.Fields[cfWorkAddressPostalCode];
     718  EditWorkAddressPostOfficeBox.Text := Contact.Fields[cfWorkAddressPostOfficeBox];
     719  EditWorkAddressStreet.Text := Contact.Fields[cfWorkAddressStreet];
     720  EditWorkAddressStreetExtended.Text := Contact.Fields[cfWorkAddressStreetExtended];
     721  EditWorkAddressCity.Text := Contact.Fields[cfWorkAddressCity];
     722  EditWorkAddressRegion.Text := Contact.Fields[cfWorkAddressRegion];
     723  EditWorkAddressCountry.Text := Contact.Fields[cfWorkAddressCountry];
     724  EditWorkAddressPostalCode.Text := Contact.Fields[cfWorkAddressPostalCode];
    708725  EditWorkWeb.Text := Contact.Fields[cfUrlWork];
    709726end;
     
    771788end;
    772789
     790procedure TFormContact.ButtonHomeAddressShowClick(Sender: TObject);
     791var
     792  Address: string;
     793begin
     794  Address := '';
     795  if EditHomeAddressStreet.Text <> '' then Address := Address + ' ' + EditHomeAddressStreet.Text;
     796  if EditHomeAddressStreetExtended.Text <> '' then Address := Address + ' ' + EditHomeAddressStreetExtended.Text;
     797  if EditHomeAddressPostOfficeBox.Text <> '' then Address := Address + ' ' + EditHomeAddressPostOfficeBox.Text;
     798  if EditHomeAddressCity.Text <> '' then Address := Address + ' ' + EditHomeAddressCity.Text;
     799  if EditHomeAddressCountry.Text <> '' then Address := Address + ' ' + EditHomeAddressCountry.Text;
     800  OpenURL(Core.MapUrl + URLEncode(Trim(Address)));
     801end;
     802
    773803procedure TFormContact.ButtonPreviousClick(Sender: TObject);
    774804begin
    775805  if Assigned(FOnGetPrevious) then
    776806    Contact := FOnGetPrevious(Contact);
     807end;
     808
     809procedure TFormContact.ButtonWorkAddressShowClick(Sender: TObject);
     810var
     811  Address: string;
     812begin
     813  Address := '';
     814  if EditWorkAddressStreet.Text <> '' then Address := Address + ' ' + EditWorkAddressStreet.Text;
     815  if EditWorkAddressStreetExtended.Text <> '' then Address := Address + ' ' + EditWorkAddressStreetExtended.Text;
     816  if EditWorkAddressPostOfficeBox.Text <> '' then Address := Address + ' ' + EditWorkAddressPostOfficeBox.Text;
     817  if EditWorkAddressCity.Text <> '' then Address := Address + ' ' + EditWorkAddressCity.Text;
     818  if EditWorkAddressCountry.Text <> '' then Address := Address + ' ' + EditWorkAddressCountry.Text;
     819  OpenURL(Core.MapUrl + URLEncode(Trim(Address)));
    777820end;
    778821
Note: See TracChangeset for help on using the changeset viewer.