Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ClientDataSet with a local file.

Status
Not open for further replies.

JES1904

Programmer
Jul 7, 2008
36
US
I am trying to use a clientdataset without an associated Table. I am attempting to extract and edit data from a Cad program. The Cad program has an interface in which the user selects specific entities within the Cad file (lines, circles, text etc) and provides basic information and attributes such as color, layer, linetype, text strings, etc. The intent is to have this information displayed in a TDBGrid, edited by the user and then sent back to the Cad program to change the Cad Database. Each field column in the DBGrid represents a specific data type and each record/row is the data from a separate Cad entities.

I need the Clientdataset to coordinate the information the DBGrid, but do not need any permanent reocrd of it. ONce the user finishes editing, I will use the change log to revise the Cad Data. I am not certain how to work the specific code to set the ClientdataSet up in this case (w/o a tTable) I suspect the easiset way to do this is to Connect the ClientDataSet direct to a file, but I cannot find any examples of how this is actually done.

Can anyone steer me to some examples of working with a ClientDataset using loadfromfile and savetofile. I am not sure how to set up the links between the dataset, the file and the datasource without a Ttable or other dataset. Can I create the file programmatically so that it is the correct structure? How do I create the file for the first time so that the ClentDataSet can laod or save?

 
You don't need to create the file, CDS will do this.

1. Drop a tclientdataset on a fresh apps form.
2. Set fielddefs (eg Name and Value, type string, SIZE 250)
3. Put this for the "write" button:

with ClientDataSet1 do begin
CreateDataSet;
Open;
Append;
FieldByName('Name').AsString := 'MyName';
FieldByName('Value').AsString := 'Paul Rigby';
Append;
FieldByName('Name').AsString := 'MyAddress';
FieldByName('Value').AsString := '5 Woodman Villas'#13#10'Oxford';
Post;
end;

4. Do this to save: ClientDataSet1.SaveToFile('c:\test.xml', dfXML);
5. To load: ClientDataSet1.LoadFromFile('c:\test.xml');
6. To get a value:
ClientDataSet1.Locate('Name', 'MyAddress', [loCaseInsensitive]);
ShowMessage(ClientDataSet1.fieldbyname('Value').asstring);

That's it. you can drop a dbgrid and datasource and link up dbgrid.datasource and datasrc.dataset and edit it live if you like.


Paul Rigby
VBA, C#, Delphi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top