FireDAC.Comp.DataSet.TFDDataSet.SaveToFile

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure SaveToFile(const AFileName: String = ''; AFormat: TFDStorageFormat = sfAuto);

C++

void __fastcall SaveToFile(const System::UnicodeString AFileName = System::UnicodeString(), Firedac::Stan::Intf::TFDStorageFormat AFormat = (Firedac::Stan::Intf::TFDStorageFormat)(0x0));

Properties

Type Visibility Source Unit Parent
procedure
function
public
FireDAC.Comp.DataSet.pas
FireDAC.Comp.DataSet.hpp
FireDAC.Comp.DataSet TFDDataSet

Description

Saves a dataset's data to a file.

Use SaveToFile to write a dataset's data to an external file for later use by this or other datasets. 

AFileName is the name of the external file to save the data. 

AFormat is the file format:

  • sfXML – a well formed stand-alone XML file.
  • sfBinary – a binary file with custom FireDAC format.
  • sfAuto – a format is determined by the AFileName extension: ".XML" - XML file, ".ADB" / ".BIN" / ".DAT" - binary file.
  • sfJSON – a stand-alone JSON file.

If AFileName does not have an extension, then the format is determined by the ResourceOptions.DefaultStoreExt if it is specified, otherwise by ResourceOptions.DefaultStoreFormat.

Optional, you can specify ResourceOptions.PersistentFileName before calling Open. In this case data is saved to file at Close, if data was modified or the file does not exist. 

If the file exists and ResourceOptions.Backup is set to True, then the original file extension is changed to ResourceOptions.BackupExt, it is saved to ResourceOptions.BackupFolder, and then a new file is written. 

SaveToFile stores into the file the items specified by ResourceOptions.StoreItems.

Example

FDQuery1.Open('select * from customers');
FDQuery1.FetchAll;
FDQuery1.SaveToFile('c:\customers.xml', sfAuto);
....
FDMemTable1.LoadFromFile('c:\customers.xml', sfAuto);
FDMemTable1.Locate('CUSTOMER_ID', [100], []);

See Also