Registriert seit: 31. Okt 2003
1.120 Beiträge
Delphi 7 Personal
|
Re: LoadFromFile bei TListView
31. Okt 2003, 18:05
und hier die Textdatei-Variante:
Delphi-Quellcode:
procedure SaveListItemsToFile(Filename : String; ListItems : TListItems);
var
ItemCount,
SubItemCount : Integer;
ItemStr : String;
ListFile : TextFile;
IOr : Integer;
begin
{$I-}
AssignFile(ListFile, Filename);
ReWrite(ListFile);
for ItemCount := 0 to (ListItems.Count - 1) do
begin
ItemStr := ListItems[ItemCount].Caption + Chr(9);
for SubItemCount := 0 to (ListItems[ItemCount].SubItems.Count - 1) do
ItemStr := ItemStr + ListItems[ItemCount].SubItems[SubItemCount] + Chr(9);
WriteLn(ListFile, ItemStr);
end;
CloseFile(ListFile);
{$I+}
IOr := IOResult;
If (IOr <> 0) then
ShowMessage(IntToStr(IOr) + ': ' + Filename);
end;
procedure LoadListItemsFromFile(Filename : String; ListItems : TListItems);
var
ItemStr : String;
ListFile : TextFile;
IOr : Integer;
begin
{$I-}
AssignFile(ListFile, Filename);
Reset(ListFile);
ListItems.Clear;
while not eof(ListFile) do
begin
ReadLn(ListFile, ItemStr);
with ListItems.Add do
begin
Caption := Copy(ItemStr, 1, Pos(Chr(9), ItemStr) - 1);
ItemStr := Copy(ItemStr, Pos(Chr(9), ItemStr) + 1, length(ItemStr));
while (Pos(Chr(9), ItemStr) > 0) do
begin
SubItems.Add(Copy(ItemStr, 1, Pos(Chr(9), ItemStr) - 1));
ItemStr := Copy(ItemStr, Pos(Chr(9), ItemStr) + 1, length(ItemStr));
end;
end;
end;
CloseFile(ListFile);
{$I+}
IOr := IOResult;
If (IOr <> 0) then
ShowMessage(IntToStr(IOr) + ': ' + Filename);
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
SaveListItemsToFile('C:\test.txt', ListView1.Items);
end;
|
|
Zitat
|