OK, hier dein Code für einen neuen Kontakt:
Delphi-Quellcode:
procedure TfrmAdressen.NewContact;
var
Details : TDetails;
Contact : TContact;
begin
Details := TDetails.Create(nil); // Edit, New
try
Details.IsNewContact := True; // New
Details.Caption := 'Neuer Kontakt'; // New
Contact := TContact.Create; // New
Details.Contact := Contact; // New
Details.ShowModal; // Edit, New
if Contact.HasBeenModified then // Edit, New
begin
ContactCollection.Add(Contact); // New
ContactCollection.HasBeenModified := True; // Edit, New
FillListbox; // Edit, New
UpdateStatusbar; // Edit, New
end;
finally
Details.Release; // Edit, New
end;
end;
und hier für das Bearbeiten:
Delphi-Quellcode:
procedure TfrmAdressen.ShowContactDetails;
var
Details : TDetails;
begin
if (lbContacts.ItemIndex > -1) then // Edit
begin
Details := TDetails.Create(nil); // Edit, New
try
Details.Contact := TContact(lbContacts.Items.Objects[lbContacts.ItemIndex]); // Edit
Details.ShowModal; // Edit, New
if Details.Contact.HasBeenModified then // Edit, New
begin
ContactCollection.HasBeenModified := True; // Edit, New
FillListbox; // Edit, New
UpdateStatusbar; // Edit, New
end;
finally
Details.Release; // Edit, New
end;
end;
end;
jetzt fassen wir das mal zusammen:
Delphi-Quellcode:
procedure TfrmAdressen.EditContactDetails(const IsNew : Boolean );
var
Details : TDetails;
Contact : TContact;
begin
if
IsNew or
(lbContacts.ItemIndex > -1)
then
begin
Details := TDetails.Create(nil);
try
if
IsNew
then
begin
Contact := TContact.Create;
Details.Caption := 'Neuer Kontakt';
end
else
Contact := TContact(lbContacts.Items.Objects[lbContacts.ItemIndex]);
Details.IsNewContact := IsNew;
Details.Contact := Contact;
Details.ShowModal;
if
Details.Contact.HasBeenModified
then
begin
if
IsNew
then
ContactCollection.Add(Contact);
ContactCollection.HasBeenModified := True;
FillListbox;
UpdateStatusbar;
end;
finally
Details.Release;
end;
end;
end;
Nun ist es eine Funktion
cu
Oliver
Kaum macht man's richtig - schon funktioniert's

Zertifikat: Sir Rufo (Fingerprint: ea 0a 4c 14 0d b6 3a a4 c1 c5 b9
dc 90 9d f0 e9 de 13 da 60)