Saving listview to text file.

Posted on 1998-08-28
Last Modified: 2008-03-04
What is the best way to save the contents of a listview to a text file? Any examples would help a lot.

Question by:Kmiller

Expert Comment

ID: 1338058
Hi Kmiller,

In fact I made a component, descendant from TListView that has a SaveToFile method.

If you can wait till Monday I can send you the source code (It's in my office...)


Accepted Solution

mirek071497 earned 100 total points
ID: 1338059
The easiest way is to use something like this:

procedure TForm1.SaveBtnClick(Sender: TObject);
var st : TFileStream;
  st := TFileStream.Create( 'c:\test.res', fmCreate );
  st.WriteComponent( ListView1 );;

procedure TForm1.LoadBtnClick(Sender: TObject);
var st : TFileStream;
  st := TFileStream.Create( 'c:\test.res', fmOpenRead );
  st.ReadComponent( ListView1 );;

however this proc reads the settings for the ListView1.too. If you don't like this you can create invisible mListView and assign items from visible to invisible.

You can of course travell over the items with for i:=0 to ListView1.Items.Count and save nodes and subnodes.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 206
Downloading email attachments 2 67
How to debug For loops? 3 46
Find and Replace Stream with 0s 8 57
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now