2004. november 9., kedd

Save and load TListView items to / from a file (2)


Problem/Question/Abstract:

Does anyone one have any idea how to save the content of a TListView to a text file

Answer:

You could save the contents to a TStrings object, and then save the TStrings using .SaveToFile.

procedure ListViewToStrings(AListView: TListView; AStrings: TStrings; const Delim:
  string = ';');
var
  Ix, Sx: Integer;
  S: string;
begin
  AStrings.BeginUpdate;
  Ix := 0;
  while Ix < AListView.Items.Count do
  begin
    with AListView.Items[Ix] do
    begin
      S := Caption + Delim;
      if Assigned(SubItems) then
      begin
        Sx := 0;
        while Sx < SubItems.Count do
        begin
          S := S + SubItems[Sx] + Delim;
          Inc(Sx);
        end;
      end;
    end;
    AStrings.Append(S);
    Inc(Ix);
  end;
  AStrings.EndUpdate;
end;

Nincsenek megjegyzések:

Megjegyzés küldése