Saving List Box Data at Run Time 16 Bit Delphi 1

Saving List Box Data at Run Time 16 Bit Delphi 1

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.

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.

See also  Comparing different methods of testing your Infrastructure-as-Code

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist