Ignore:
Timestamp:
Dec 15, 2021, 9:03:17 PM (3 years ago)
Author:
chronos
Message:
  • Modified: More preparation for future Previous and Next buttons in Contact window.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormContacts.pas

    r76 r77  
    8080    procedure FilterList(List: TFPGObjectList<TObject>);
    8181    procedure SetContacts(AValue: TContacts);
    82     procedure FormContactPrevious(Sender: TObject);
    83     procedure FormContactNext(Sender: TObject);
     82    function GetPreviousContact(Contact: TContact): TContact;
     83    function GetNextContact(Contact: TContact): TContact;
    8484    procedure DoUpdateInterface;
    8585    procedure UpdateColumns;
     
    234234end;
    235235
    236 procedure TFormContacts.FormContactPrevious(Sender: TObject);
    237 var
    238   I: Integer;
    239 begin
    240   I := ListViewSort1.List.IndexOf(TFormContact(Sender).Contact);
     236function TFormContacts.GetPreviousContact(Contact: TContact): TContact;
     237var
     238  I: Integer;
     239begin
     240  I := ListViewSort1.List.IndexOf(Contact);
    241241  if (I <> -1) and (I > 0) then
    242     TFormContact(Sender).Contact := TContact(ListViewSort1.List[I - 1]);
    243 end;
    244 
    245 procedure TFormContacts.FormContactNext(Sender: TObject);
    246 var
    247   I: Integer;
    248 begin
    249   I := ListViewSort1.List.IndexOf(TFormContact(Sender).Contact);
     242    Result := TContact(ListViewSort1.List[I - 1])
     243    else Result := nil;
     244end;
     245
     246function TFormContacts.GetNextContact(Contact: TContact): TContact;
     247var
     248  I: Integer;
     249begin
     250  I := ListViewSort1.List.IndexOf(Contact);
    250251  if (I <> -1) and (I < ListViewSort1.List.Count - 1) then
    251     TFormContact(Sender).Contact := TContact(ListViewSort1.List[I + 1]);
     252    Result := TContact(ListViewSort1.List[I + 1])
     253    else Result := nil;
    252254end;
    253255
     
    312314      Contact.Parent := Contacts.ContactsFile;
    313315      FormContact.Contact := Contact;
    314       FormContact.OnPrevious := FormContactPrevious;
    315       FormContact.OnNext := FormContactNext;
     316      FormContact.OnGetPrevious := GetPreviousContact;
     317      FormContact.OnGetNext := GetNextContact;
    316318      if FormContact.ShowModal = mrOK then begin
    317319        Contacts.Add(Contact);
     
    342344      Contact.Assign(TContact(ListView1.Selected.Data));
    343345      FormContact.Contact := Contact;
    344       FormContact.OnPrevious := FormContactPrevious;
    345       FormContact.OnNext := FormContactNext;
     346      FormContact.OnGetPrevious := GetPreviousContact;
     347      FormContact.OnGetNext := GetNextContact;
    346348      if FormContact.ShowModal = mrOK then begin
    347349        Contacts.Add(Contact);
     
    443445      Contact.Assign(TContact(ListView1.Selected.Data));
    444446      FormContact.Contact := Contact;
    445       FormContact.OnPrevious := FormContactPrevious;
    446       FormContact.OnNext := FormContactNext;
     447      FormContact.OnGetPrevious := GetPreviousContact;
     448      FormContact.OnGetNext := GetNextContact;
    447449      if FormContact.ShowModal = mrOK then begin
    448450        TContact(ListView1.Selected.Data).Assign(Contact);
Note: See TracChangeset for help on using the changeset viewer.