Zum Beispiel so. Und Freigeben nicht vergessen.
Delphi-Quellcode:
type
TData = class
A, B: string;
end;
procedure TSomeForm.Button1Click(Sender: TObject);
var
Item: TListItem;
Data : TData;
begin
Item := ListView1.Items.Add;
Data := TData.Create;
Data.A := 'A';
Data.B := 'B';
Item.Data := Data;
end;
procedure TSomeForm.Button2Click(Sender: TObject);
var
Data : TData;
begin
Data := TData(ListView1.Items[0].Data);
ShowMessage(Data.A);
ShowMessage(Data.B);
end;
procedure TSomeForm.FormDestroy(Sender: TObject);
var
Data : TData;
begin
while ListView1.Items.Count > 0 do
begin
Data := TData(ListView1.Items[0].Data);
Data.Free;
ListView1.Items.Delete(0);
end;
end;