Changeset 3 for trunk/Forms/UFormContacts.pas
- Timestamp:
- Jan 29, 2018, 10:54:40 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 5 5 *.lps 6 6 *.res 7 vCardStudio.exe
-
- Property svn:ignore
-
trunk/Forms/UFormContacts.pas
r2 r3 31 31 procedure ARemoveExecute(Sender: TObject); 32 32 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 33 procedure FormCreate(Sender: TObject); 33 34 procedure FormShow(Sender: TObject); 34 35 procedure ListView1Data(Sender: TObject; Item: TListItem); … … 37 38 Selected: Boolean); 38 39 private 40 FContacts: TContacts; 41 procedure SetContacts(AValue: TContacts); 39 42 40 43 public 41 Contacts: TContacts;44 property Contacts: TContacts read FContacts write SetContacts; 42 45 procedure ReloadList; 43 46 procedure UpdateInterface; … … 55 58 UFormContact, UCore; 56 59 60 resourcestring 61 SRemoveContacts = 'Remove contacts'; 62 SRemoveContactsQuery = 'Do you want to remove selected contacts?'; 63 57 64 { TFormContacts } 58 65 … … 61 68 if Assigned(Contacts) and (Item.Index < Contacts.Count) then 62 69 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); 64 73 Item.Data := Contacts[Item.Index]; 65 74 end; … … 77 86 end; 78 87 88 procedure TFormContacts.SetContacts(AValue: TContacts); 89 begin 90 if FContacts = AValue then Exit; 91 FContacts := AValue; 92 ReloadList; 93 UpdateInterface; 94 end; 95 79 96 procedure TFormContacts.FormShow(Sender: TObject); 80 97 begin … … 87 104 var 88 105 FormContact: TFormContact; 106 Contact: TContact; 89 107 begin 90 108 FormContact := TFormContact.Create(nil); 109 try 91 110 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; 93 115 ReloadList; 94 116 UpdateInterface; 95 117 end; 96 FormContact.Free; 118 finally 119 FormContact.Free; 120 end; 97 121 end; 98 122 … … 102 126 begin 103 127 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; 109 138 end; 110 FormContact.Free;111 139 end; 112 140 … … 115 143 I: Integer; 116 144 begin 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; 122 156 end; 123 157 … … 126 160 begin 127 161 Core.PersistentForm1.Save(Self); 162 end; 163 164 procedure TFormContacts.FormCreate(Sender: TObject); 165 begin 166 FContacts := nil; 128 167 end; 129 168 … … 138 177 procedure TFormContacts.UpdateInterface; 139 178 begin 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); 142 182 end; 143 183
Note:
See TracChangeset
for help on using the changeset viewer.