Registriert seit: 13. Okt 2014
16 Beiträge
FreePascal / Lazarus
|
AW: Listview speichern und laden
2. Nov 2014, 11:38
Hier der Zwischenstand.
Das Speichern funktioniert.
Delphi-Quellcode:
procedure TForm1.Button13Click(Sender: TObject);
Var
SaveList: TStrings;
i, j: Integer;
TempStr: String;
Const
ItemTrenner = #134;
ListTrenner1 = #179;
ListTrenner2 = #178;
Begin
If Not SaveDialog1.Execute Then Exit;
SaveList := TStringList.create;
Try
With ListView1 Do
Begin
For i := 0 To pred(Items.Count) Do
Begin
TempStr := '';
With Items[i] Do
For j := 0 To pred(SubItems.Count) Do
TempStr := TempStr + ItemTrenner + SubItems[j];
SaveList.Add(Items[i].Caption + TempStr);
End;
end;
SaveList.add(Listtrenner1);
With ListView2 Do
For i := 0 To pred(Items.Count) Do
Begin
TempStr := '';
With Items[i] Do
For j := 0 To pred(SubItems.Count) Do
TempStr := TempStr + ItemTrenner + SubItems[j];
SaveList.Add(Items[i].Caption + TempStr);
End;
end;
SaveList.add(Listtrenner2);
SaveList.SaveToFile(SaveDialog1.FileName+'.txt');
Finally
FreeAndNil(SaveList);
End;
End;
Das Laden funktioniert nicht. Es kommt keine Fehlermeldung. Die Listviewen bleiben leer. Wird bestimmt ein Fehler beim Copy sein.
Delphi-Quellcode:
procedure TForm1.Button12Click(Sender: TObject);
Var
LoadList, ErsteLW, ZweiteLW: TStrings;
i, ActPos, PrevPos: Integer;
Const
ItemTrenner = #134;
ListTrenner1 = #179;
ListTrenner2 = #178;
Begin
If Not OpenDialog1.Execute Then Exit;
LoadList := TStringList.create;
ErsteLW:=TStringList.create;
ZweiteLW:=TStringList.create;
Try
LoadList.LoadFromFile(OpenDialog1.FileName);
ListView1.Items.Clear;
Listview2.items.clear;
For i := 0 To pred(LoadList.Count) Do
Begin
ErsteLW.add(Copy(LoadList[i], 1, Pos (ListTrenner1, Loadlist[i]) - 1));
ZweiteLW.add(Copy(LoadList[i], Pos (ListTrenner1, Loadlist[i]) + 1, Pos (ListTrenner2, Loadlist[i]) -1));
end;
For i := 0 To pred(ErsteLW.Count) Do
Begin
PrevPos := 1;
ActPos := 1;
ActPos := PosEx(ItemTrenner, ErsteLW[i], succ(ActPos));
With ListView1.Items.Add Do
Begin
Caption := Copy(ErsteLW[i], PrevPos, (ActPos - PrevPos));
PrevPos := succ(ActPos);
Repeat
ActPos := PosEx(ItemTrenner, ErsteLW[i], succ(ActPos));
If ActPos <> 0 Then
SubItems.Add(Copy(ErsteLW[i], PrevPos, (ActPos - PrevPos)))
Else
SubItems.Add(Copy(ErsteLW[i], PrevPos, Length(ErsteLW[i])));
PrevPos := succ(ActPos);
Until ActPos = 0;
End;
End;
For i := 0 To pred(ZweiteLW.Count) Do
Begin
PrevPos := 1;
ActPos := 1;
ActPos := PosEx(ItemTrenner, ZweiteLW[i], succ(ActPos));
With ListView2.Items.Add Do
Begin
Caption := Copy(ZweiteLW[i], PrevPos, (ActPos - PrevPos));
PrevPos := succ(ActPos);
Repeat
ActPos := PosEx(ItemTrenner, ZweiteLW[i], succ(ActPos));
If ActPos <> 0 Then
SubItems.Add(Copy(ZweiteLW[i], PrevPos, (ActPos - PrevPos)))
Else
SubItems.Add(Copy(ZweiteLW[i], PrevPos, Length(ZweiteLW[i])));
PrevPos := succ(ActPos);
Until ActPos = 0;
End;
End;
Finally
FreeAndNil(LoadList);
FreeAndNil(ErsteLW);
FreeAndNil(ZweiteLW);
End;
End;
|
|
Zitat
|