FireDAC.Comp.DataSet.TFDDataSet.LoadFromFile

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

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

C++

void __fastcall LoadFromFile(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

Loads a dataset's data from a file.

Use LoadFromFile to populate the dataset with data stored in an external file. The data is not moved to a database, it is just loaded into a dataset in-memory storage. 

AFileName is the name of the file containing the data to load. If the file does not exist, an exception is raised. 

AFormat is the file format:

  • sfXML-- the file is a-well formed standalone XML file.
  • sfBinary--file is a binary file with custom FireDAC format.
  • sfAuto-- the format is determined by the AFileName extention: ".XML" - XML file, ".ADB" / ".BIN" / ".DAT"--binary file. If AFileName does not have an extension, the format is determined by ResourceOptions.DefaultStoreExt if it is specified. Otherwise, it is determined by ResourceOptions.DefaultStoreFormat.

Optionally, you can specify ResourceOptions.PersistentFileName and call Open, and dataset data is loaded from the specified file. When calling Close, it is saved back if data was modified. 

AFileName must contain data saved to a file by a previous call to this or another client dataset's SaveToFile method. After the call, the dataset is active. 

LoadFromFile tries to load from the file the items specified by ResourceOptions.StoreItems. If the file was written with a different StoreItems value, the following exception is raised: 

  [FireDAC][Stan]-712 Cannot read [Relationlist] object

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