function LV_Speichern(TLV: TListView; Pfad: string): boolean;
var
x, y, i: integer;
sl: TStringlist;
begin
sl := TStringlist.create;
try
for x := 0 to TLV.items.count - 1 do begin
sl.add(TLV.items[x].caption);
i := TLV.items[x].subitems.count - 1;
sl.add(inttostr(i));
for y := 0 to i do sl.add(TLV.items[x].subitems[y]);
end;
sl.savetofile(pfad);
result := true;
except
result := false;
end;
sl.free;
end;
function LV_Laden(TLV: TListView; Pfad: string): boolean;
var
x, y: integer;
sl: TStringlist;
tli: TListitem;
begin
sl := TStringlist.create;
try
TLV.items.clear;
sl.loadfromfile(pfad);
x := 0;
while x < sl.count do begin
tli := TLV.items.add;
tli.caption := sl[x];
inc(x);
for y := 0 to strtoint(sl[x]) do begin
inc(x);
tli.subitems.add(sl[x]);
end;
inc(x);
end;
result := true;
except
result := false;
end;
sl.free;
end;
// Speichern
procedure TForm1.Button2Click(Sender: TObject);
begin
if not LV_Speichern(Listview1, 'C:\LVTST.txt')
then showmessage('Fehler beim Speichern');
end;
// Laden
procedure TForm1.Button3Click(Sender: TObject);
begin
if not LV_Laden(Listview1, 'C:\LVTST.txt')
then showmessage('Fehler beim Laden');
end;