dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Pascal
Expertise: Beginner
Nov 4, 1998

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Saving List Box Data at Run Time 16 Bit Delphi 1

Question:
How do I save data entered in a list box at run time without resorting to a text file or having to deal with the overhead of a table? I am using 16bit Delphi 1.

Answer:
The easiest way to approach this is to use a TFileStream and TStream's ReadComponent and WriteComponent methods to open and save your saved list box. For instance, this is something that I use in my own code:

procedure TConfigForm.StreamList(Read : Boolean);
var
  strm : TFileStream;
begin
  //if Read then read the file off disk and load
  //the list box. Otherwise, write it to disk.
  //Notice that the Write methodology opens the
  //stream with fmCreate. This will cause the 
  //current file to be overwritten
  if Read then 
    begin
      strm := TFileStream.Create(
              ExtractFilePath(ParamStr(0) +
              'ConfigList.DAT', 
              fmOpenRead);
      try
        strm.ReadComponent(lstConfigMain)
      finally
        strm.Free;
      end;
    end
  else
    begin
      strm := TFileStream.Create(
              ExtractFilePath(ParamStr(0) + 
              'ConfigLst.DAT', 
              fmCreate);
      try
        strm.WriteComponent(lstConfigMain)
      finally
        strm.Free;
      end;
    end;
end;
It's quick and dirty and demonstrates how to implement persistence in your components from run to run of your program.
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date