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/Forms/UFormContacts.pas

    r2 r3  
    3131    procedure ARemoveExecute(Sender: TObject);
    3232    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     33    procedure FormCreate(Sender: TObject);
    3334    procedure FormShow(Sender: TObject);
    3435    procedure ListView1Data(Sender: TObject; Item: TListItem);
     
    3738      Selected: Boolean);
    3839  private
     40    FContacts: TContacts;
     41    procedure SetContacts(AValue: TContacts);
    3942
    4043  public
    41     Contacts: TContacts;
     44    property Contacts: TContacts read FContacts write SetContacts;
    4245    procedure ReloadList;
    4346    procedure UpdateInterface;
     
    5558  UFormContact, UCore;
    5659
     60resourcestring
     61  SRemoveContacts = 'Remove contacts';
     62  SRemoveContactsQuery = 'Do you want to remove selected contacts?';
     63
    5764{ TFormContacts }
    5865
     
    6168  if Assigned(Contacts) and (Item.Index < Contacts.Count) then
    6269  with TContact(Contacts[Item.Index]) do begin
    63     Item.Caption := FullName;
     70    Item.Caption := FirstName;
     71    Item.SubItems.Add(MiddleName);
     72    Item.SubItems.Add(LastName);
    6473    Item.Data := Contacts[Item.Index];
    6574  end;
     
    7786end;
    7887
     88procedure TFormContacts.SetContacts(AValue: TContacts);
     89begin
     90  if FContacts = AValue then Exit;
     91  FContacts := AValue;
     92  ReloadList;
     93  UpdateInterface;
     94end;
     95
    7996procedure TFormContacts.FormShow(Sender: TObject);
    8097begin
     
    87104var
    88105  FormContact: TFormContact;
     106  Contact: TContact;
    89107begin
    90108  FormContact := TFormContact.Create(nil);
     109  try
    91110  if FormContact.ShowModal = mrOK then begin
    92     FormContact.SaveData(TContact(ListView1.Selected.Data));
     111    Contact := TContact.Create;
     112    FormContact.SaveData(Contact);
     113    Contacts.Add(Contact);
     114    Core.DataFile.Modified := True;
    93115    ReloadList;
    94116    UpdateInterface;
    95117  end;
    96   FormContact.Free;
     118  finally
     119    FormContact.Free;
     120  end;
    97121end;
    98122
     
    102126begin
    103127  FormContact := TFormContact.Create(nil);
    104   FormContact.LoadData(TContact(ListView1.Selected.Data));
    105   if FormContact.ShowModal = mrOK then begin
    106     FormContact.SaveData(TContact(ListView1.Selected.Data));
    107     ReloadList;
    108     UpdateInterface;
     128  try
     129    FormContact.LoadData(TContact(ListView1.Selected.Data));
     130    if FormContact.ShowModal = mrOK then begin
     131      FormContact.SaveData(TContact(ListView1.Selected.Data));
     132      Core.DataFile.Modified := True;
     133      ReloadList;
     134      UpdateInterface;
     135    end;
     136  finally
     137    FormContact.Free;
    109138  end;
    110   FormContact.Free;
    111139end;
    112140
     
    115143  I: Integer;
    116144begin
    117   for I := ListView1.Items.Count - 1 downto 0 do
    118     if ListView1.Items[I].Selected then begin
    119       Contacts.Delete(I);
    120     end;
    121   UpdateInterface;
     145  if Assigned(ListView1.Selected) then
     146  if MessageDlg(SRemoveContacts, SRemoveContactsQuery,
     147    TMsgDlgType.mtConfirmation, [mbCancel, mbOk], 0) = mrOk then begin
     148    for I := ListView1.Items.Count - 1 downto 0 do
     149      if ListView1.Items[I].Selected then begin
     150        Contacts.Delete(I);
     151      end;
     152    Core.DataFile.Modified := True;
     153    ReloadList;
     154    UpdateInterface;
     155  end;
    122156end;
    123157
     
    126160begin
    127161  Core.PersistentForm1.Save(Self);
     162end;
     163
     164procedure TFormContacts.FormCreate(Sender: TObject);
     165begin
     166  FContacts := nil;
    128167end;
    129168
     
    138177procedure TFormContacts.UpdateInterface;
    139178begin
    140   AModify.Enabled := Assigned(ListView1.Selected);
    141   ARemove.Enabled := Assigned(ListView1.Selected);
     179  AAdd.Enabled := Assigned(Contacts);
     180  AModify.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
     181  ARemove.Enabled := Assigned(Contacts) and Assigned(ListView1.Selected);
    142182end;
    143183
Note: See TracChangeset for help on using the changeset viewer.