What is the best way to save data in Delphi

I am working on a program in Delphi that contains a lot of data, and I wonder what method is best stored in a file. Now we use the records and the “file” to save it, but I think these should be the best methods. I would prefer a system that will simplify the migration from the system we use.

EDIT: The application is a kind of database application. The user uses it to manage data.

+4
source share
6 answers

It depends on the data! Common tools are databases (strings of a large number of records), XML (storage of structured data), ini files (simple data), or user-defined formats (graphic images, etc.). Delphi is very good with databases with a number of third-party options that allow fully compiled code, so they will work well for general data.

+6
source

There are many options. If you are sure that you will not need more than one user, I would go to save ClientDatasets in XML. Dan Mizer has written several articles about them that are really good. If you are not sure that in the future you will need one or more users, I would go to the built-in database. Firebird is a good option for this. See http://www.firebirdsql.org/manual/fbmetasecur-embedded.html for more details. With the same code, you can make a multi-user version in the future.

+3
source

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

One alternative approach is 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; 
+2
source

For a simple application, why not use a local TClientDataset ? This will allow you to search, sort, and use database controls. If you include midaslib in your uses section, you can also deploy the application without any external dlls.

+2
source
 var FileStream: TFileStream; procedure TForm1.Load(Sender: TObject); Begin if FileExists ('Thing2.dat') then Begin FileStream := TFileStream.Create('Thing2.dat', fmOpenRead); FileStream.ReadComponent( {Thing like Edit1} ); FileStream.Free; End; end; 

and upload

 procedure TForm1.Save(Sender: TObject); Begin FileStream := TFileStream.Create('Thing2.dat', fmcreate); FileStream.WriteComponent( {Thing like Edit1} ); FileStream.Free; end; 

This should work because it works for me

+1
source

It also depends on what you want to do with it as soon as you save it ... is it just storing “archived” data at the moment? Or do you want to search for it, extract some data at some point in the future, and then save it back (potentially modified) or load it all, somehow manipulate it, and then save it back again?

0
source

All Articles