unit Unit5;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, System.Generics.Collections,
Vcl.StdCtrls,
Vcl.ComCtrls;
type
TDingens =
class
private
FName:
string;
FZahl: integer;
procedure SetName(
const Value:
string);
procedure SetZahl(
const Value: integer);
public
property Name:
string read FName
write SetName;
property Zahl: integer
read FZahl
write SetZahl;
end;
TForm5 =
class(TForm)
ListView1: TListView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
FListe: TObjectList<TDingens>;
public
{ Public-Deklarationen }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
{ TDingens }
procedure TDingens.SetName(
const Value:
string);
begin
FName := Value;
end;
procedure TDingens.SetZahl(
const Value: integer);
begin
FZahl := Value;
end;
procedure TForm5.Button1Click(Sender: TObject);
var
Dingens: TDingens;
Item: TListItem;
begin
for Dingens
in FListe
do
begin
Item := ListView1.Items.Add;
Item.Caption := Dingens.
Name;
Item.SubItems.Add(Dingens.Zahl.ToString);
Item.Data := Dingens;
end;
end;
procedure TForm5.FormCreate(Sender: TObject);
var
Dingens: TDingens;
begin
FListe := TObjectList<TDingens>.Create;
Dingens := TDingens.Create;
Dingens.
Name := '
Hein Blöd';
Dingens.Zahl := 42;
FListe.Add(Dingens);
Dingens := TDingens.Create;
Dingens.
Name := '
Max Mustermann';
Dingens.Zahl := 100;
FListe.Add(Dingens);
Dingens := TDingens.Create;
Dingens.
Name := '
Klara Korn';
Dingens.Zahl := 3;
FListe.Add(Dingens);
Dingens := TDingens.Create;
Dingens.
Name := '
Rudi Rüssel';
Dingens.Zahl := 150;
FListe.Add(Dingens);
end;
procedure TForm5.FormDestroy(Sender: TObject);
begin
FListe.Free;
end;
end.