unit uMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Contnrs, ComCtrls, TestData;
type
TForm1 =
class(TForm)
ListView1: TListView;
ListView2: TListView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
private
{ Private-Deklarationen }
FKW: TObjectList;
procedure GenerateTestData;
procedure DisplayKWList;
procedure DisplayNames(ATest: TTest);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
(* Anzeige der KWs aus der FKW-Liste in ListView1 *)
procedure TForm1.DisplayKWList;
var
i: integer;
Item: TListItem;
Test: TTest;
begin
ListView1.Items.BeginUpdate;
try
ListView1.Items.Clear;
for i := 0
to FKW.Count - 1
do
begin
Item := ListView1.Items.Add;
Test := FKW[i]
as TTest;
Item.Caption := IntToStr(Test.KW);
(* Anhängen der Instanz an den Listeneintrag *)
Item.Data := Test;
end;
finally
ListView1.Items.EndUpdate;
end;
end;
(* Anzeige der Namen zur übergebenen KW in ListView2 *)
procedure TForm1.DisplayNames(ATest: TTest);
var
i: integer;
Item: TListItem;
begin
ListView2.Items.BeginUpdate;
try
ListView2.Items.Clear;
for i := 0
to ATest.Names.Count - 1
do
begin
Item := ListView2.Items.Add;
Item.Caption := ATest.Names[i];
end;
finally
ListView2.Items.EndUpdate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FKW := TObjectList.Create;
GenerateTestData;
DisplayKWList;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FKW.Free;
end;
procedure TForm1.GenerateTestData;
var
Data: TTest;
begin
Data := TTest.Create(1);
Data.Names.Add('
Heinz');
Data.Names.Add('
Hans');
Data.Names.Add('
August');
FKW.Add(Data);
Data := TTest.Create(2);
Data.Names.Add('
Fritz');
Data.Names.Add('
Sabine');
Data.Names.Add('
Eleonore');
FKW.Add(Data);
Data := TTest.Create(3);
Data.Names.Add('
Victor');
Data.Names.Add('
Kunigunde');
Data.Names.Add('
Klaus-Bärbel');
FKW.Add(Data);
end;
(* Bei Auswahl einer KW deren Daten anzeigen *)
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
var
Test: TTest;
begin
if Selected
then
begin
Test := TTest(Item.Data);
if Assigned(Test)
then
DisplayNames(Test);
end;
end;
end.