views:

779

answers:

5

I work on a program in Delphi that holds a lot of data, and I wonder which method is the best to save it to file. Now we use records and "file of" to save it but I think it should be better methods. I would prefer a system that makes it easy to migrate from the system we use now.

EDIT: The application is a sort of a database application. The user use it to manage data.

+6  A: 

It depends on the data! Common means are databases (rows of lots of records), XML (structured data storage), ini files (simple data) or custom formats (graphic images etc). Delphi is very good with databases, with a range of third party options to allow fully compiled-in code, so for general data they will work well.

mj2008
+2  A: 

If it is a kind of a database application, storing the data in a database might be the logical choice.

One alternative approach would be to use a streamer:

procedure TmyThing.PutData(AFile: String);
var
  writer: TWriter;
  stream: TFileStream;
begin
  stream := TFileStream.Create(AFile, fmCreate);
  try
    writer := TWriter.Create(stream, $ff);
    try
      with writer do
      begin
        WriteSignature;         {marker to indicate a Delphi filer object file.}
        WriteListBegin;         {outer list marker}
        WriteFloat(cVersion);   {write the version for future use}
        WriteString(someProperty);
        {... etc. ...}
        WriteListEnd;           {outer list marker}
      end;
    finally
      writer.Free;
    end;
  finally
    stream.Free;
  end;
end;
Miel
A: 

Also depends on what you want to do with it once you have saved it... is it just storage of 'archived' data at this point ? Or do you want to search it, retrieving some of the data at some point in the future then saving it back again (potentially changed), or do you load it all in, manipulate it in some way, then save it back out again ?

Drew Gibson
+3  A: 

There are many options. If you're sure you will never need more then one user, I would go for ClientDatasets saved in XML. Dan Miser has written a few articles about them that are really good. If you are not sure you will need one or more users in the future I would go for an embedded database. Firebird is a good option for that. See http://www.firebirdsql.org/manual/fbmetasecur-embedded.html for more information. With the same code you will be able to make a Multi user version in the future.

bartvdpoel
+2  A: 

For a simple application, why not use a local TclientDataset? It would allow searching, sorting, and the use of the database controls. If you include midaslib in your uses clause, you can also deploy the application without any external dll's.

skamradt