RAD Studio VCL Reference
TCustomClientDataSet.LoadFromFile Method

Loads a client dataset's data from a file.

procedure LoadFromFile(const FileName: string = '');
__fastcall LoadFromFile(const AnsiString FileName = '');

Call LoadFromFile to populate the Data property of the client dataset with data stored in an external file. FileName is the name of the file containing the data to load. If the FileName parameter is an empty string, or if this parameter is omitted (Delphi), LoadFromFile reads from the file specified by the FileName property. 

To load data from a file at design time, right-click on the client dataset and choose Load from File.

Note: FileName must contain data saved to a file by a previous call to this or another client dataset's SaveToFile method, or by a TXMLTransform component

Delphi Examples: 


This example requires two ClientDataSets, two DBGrids, two
DataSources and two DBNavigators.  Name the two
ClientDataSets CDS and CDS2. Set the DataSet property in the
first DataSource to CDS and name that DataSource DS.  Set the
DataSet property in the second DataSource to CDS2 and name
that DataSource DS2.  Set the DataSource in the first
DBNavigator to DS and the DataSource in the second DBNavigator
to DS2.  Set the DataSource in the first DBGrid to DS and the
DataSource in the second DBGrid to DS2.  Right click on CDS
and select the Fields Editor, then right click on the Field
Editor form and create two fields by selecting "new field".
In the field configuration window, set the name to HOST, the
Component value will automatically be set to CDSHOST.  Set
the filed type to String.  In the field configuration window
for the second field, set the name to PORTA, the Component
value will automatically be set to CDSPORTA.  Set the field
type to Integer.  The file used to load CDS must have an
attribute name of HOST with an attribute type of string and
an attribute name of PORTA with an attribute type of integer.
Add DB, DBCtrls, Grids, DBGrids, DBClient and SwSystem to the
uses clause.  "LoadFormFile" to start with the file, or 
"CreateDataSet" to start from scratch.  You must "CloseDataSet"
after a "LoadFromFile" before you can do another "CreateDataSet".
uses SwSystem;

procedure TForm1.Button1Click(Sender: TObject);
  CDS.LoadFromFile(GetCurrentDir + '\CDS.XML');
  CDS.LoadFromFile(gsAppPath + 'CDS.XML');

procedure TForm1.Button2Click(Sender: TObject);
  CDS.SaveToFile(GetCurrentDir + '\CDS.XML', dfXML);
  CDS.SaveToFile(gsAppPath + 'CDS.XML', dfXML);

procedure TForm1.Button3Click(Sender: TObject);

procedure TForm1.Button4Click(Sender: TObject);
  CDS2.Data := CDS.Data;

procedure TForm1.Button5Click(Sender: TObject);


Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!