Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ListVies.SaveToFile ??

Posted on 1998-08-25
6
Medium Priority
?
525 Views
Last Modified: 2012-06-22
ListVies.SaveToFile ??

Hi there, I need to save the contents of a ListView with multiply columns, I have thought of
saving each column by coping the contents of a column to a TStringList and then save in a new file, so the file would look something like this

[Column1]
.
.
.
.


[Column2]
.
.
.
.


The file gets rather big, so isn't there a better way to do that?
0
Comment
Question by:koger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1337652
0
 
LVL 4

Accepted Solution

by:
erajoj earned 200 total points
ID: 1337653
Hi,
Here's a very simple solution, using TStringList.CommaText:

procedure TForm1.Button1Click(Sender: TObject); // save
var
  List1, List2: TStringList;
  iRow, iCol  : Integer;
begin
  List1 := TStringList.Create;
  List2 := TStringList.Create;
  for iRow := 0 to ListView1.Items.Count - 1 do
  with ListView1.Items[ iRow ] do begin
    List1.Add( Caption );
    for iCol := 0 to SubItems.Count - 1 do List1.Add( SubItems[ iCol ] );
    List2.Add( List1.CommaText );
    List1.Clear;
  end;
  List2.SaveToFile( 'c:\listviewcontents.dat' );
  List1.Free;
  List2.Free;
  ListView1.Items.Clear; // not necessary except for this example...
end;

procedure TForm1.Button2Click(Sender: TObject); // load
var
  List1, List2: TStringList;
  iRow, iCol  : Integer;
begin
  List1 := TStringList.Create;
  List2 := TStringList.Create;
  List2.LoadFromFile( 'c:\listviewcontents.dat' );
  ListView1.Items.BeginUpdate;
  for iRow := 0 to List2.Count - 1 do
  with ListView1.Items.Add do begin
    List1.CommaText := List2[ iRow ];
    if List1.Count > 0 then begin
      Caption := List1[ 0 ];
      for iCol := 1 to List1.Count - 1 do SubItems.Add( List1[ iCol ] );
    end;
  end;
  List1.Free;
  List2.Free;
  ListView1.Items.EndUpdate;
end;

/// John
0
 

Expert Comment

by:lavar
ID: 1337654
var
  Stream: TFileStream;
begin
{++Save ListView items++}
Stream := TFileStream.Create('ListView1.dat', fmCreate);
Stream.WriteComponentRes('Items', ListView1);
Stream.Destroy;

{++Load ListView items++}
Stream := TFileStream.Create('ListView1.dat', fmOpenRead);
Stream.ReadComponentRes(ListView1);
Stream.Destroy;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:koger
ID: 1337655
Very good answer

The only problem is that the code is very very slow, it can take more than ten minuttes to load a file with about 1000 columns and 8 rows, the problem is not your code, but TListView's add procedure it's very slow I have tried using AllocBy, but it didn't help.
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337656
Hi,
I think there are some speed improved listviews on DSP or Torry's.
Look them up, I hope they might speed up things for you...
You can also use beginupdate/endupdate on the TStringLists to speed up things some.

/// John
0
 

Expert Comment

by:menorcanet
ID: 23252367
lavar's code works really well, just what I was looking for. thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question