unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
PAdresse = ^TAdresse;
TAdresse =
record
Name,
Vorname,
Telefon,
Anschrift:
String;
end;
TForm1 =
class(TForm)
Button1: TButton;
ListBox1: TListBox;
lblName: TLabel;
edtName: TEdit;
lblTelefon: TLabel;
edtTelefon: TEdit;
lblVorname: TLabel;
edtVorname: TEdit;
lblAdresse: TLabel;
edtAnschrift: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
AdressListe: TList;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function MySort(Item1,Item2: Pointer): integer;
begin
Result := AnsiStrIComp(PChar(PAdresse(Item1)^.
Name),PChar(PAdresse(Item2)^.
Name));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AdressListe := TList.Create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
AdressListe.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var Adresse: PAdresse;
i: integer;
begin
ListBox1.Items.BeginUpdate;
try
Adresse := new(PAdresse);
with Adresse^
do
begin
Name := edtName.Text;
Vorname := edtVorname.Text;
Telefon := edtTelefon.Text;
Anschrift := edtAnschrift.Text;
end;
AdressListe.Add(Adresse);
AdressListe.Sort(@MySort);
ListBox1.Items.Clear;
for i := 0
to AdressListe.Count - 1
do
begin
ListBox1.Items.Add(Format('
Name: %s',[PAdresse(AdressListe[i])^.
Name]));
ListBox1.Items.Add(Format('
Vorname: %s',[PAdresse(AdressListe[i])^.Vorname]));
ListBox1.Items.Add(Format('
Telefon: %s',[PAdresse(AdressListe[i])^.Telefon]));
ListBox1.Items.Add(Format('
Anschrift: %s',[PAdresse(AdressListe[i])^.Anschrift]));
ListBox1.Items.Add('
');
ListBox1.Items.Add('
--------------------');
end;
finally
ListBox1.Items.EndUpdate;
end;
end;
end.