AnyDAC
ContentsIndexHome
PreviousUpNext
TADDataSet.SaveToFile Method

Saves a dataset's data to a file.

Group
Links
Parameters 
Description 
const AFileName: String = '' 
An external file name. 
AFormat: TADStorageFormat = sfAuto 
A file format. 

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 - file is well formed standalone XML file;
  • sfBinary - file is binary file with custom AnyDAC format;
  • sfAuto - format is determined by AFileName extension: ".XML" - XML file, ".ADB" / ".BIN" / ".DAT" - binary file. If AFileName does not have an extension, then format is determined by ResourceOptions.DefaultStoreExt if it is specified, otherwise by ResourceOptions.DefaultStoreFormat.

As option, you can specify ResourceOptions.PersistentFileName before calling Open. Then data will be saved to file at Close, if data was modified or file does not exists. 

If file exists and ResourceOptions.Backup = True, then original file extension will be changed to ResourceOptions.BackupExt and it will be saved to ResourceOptions.BackupFolder. And then will be written a new file. 

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

procedure SaveToFile(const AFileName: String = ''; AFormat: TADStorageFormat = sfAuto);
ADQuery1.Open('select * from customers');
ADQuery1.FetchAll;
ADQuery1.SaveToFile('c:\customers.xml', sfAuto);
....
ADMemTable1.LoadFromFile('c:\customers.xml', sfAuto);
ADMemTable1.Locate('CUSTOMER_ID', [100], []);
What do you think about this topic? Send feedback!