I wanted to learn tclientdataset in May 2009, but I couldn't learn it at the time. Now I have a good idea. I have the source code (dbclient. Pas ).
I hope that I can learn more about the memory coordination mode and learn about the database by the way.
Tclientdataset is a memory dataset ("data table" Can't help it). Its memory data can be stored locally (*. CDs or *. XML format ).
You can use TDBGrid to conveniently view its memory data, but you need to use a data source component (such as tdatasource) to bridge it:
TDBGrid. datasource restart tdatasource. dataset restart tclientdataset
Official test data is available under Program Files \ common files \ codegear shared \ data. belowProgramYou can view the data:
// Assume that clientdataset1, performance1, and dbgrid1 have been attached during design, and add a listbox1uses ioutils, types; var datapath: string; Procedure tform1.formcreate (Sender: tobject); var Sarr: tstringdynarray; s: string; begin {path for obtaining test data} datapath: = getenvironmentvariable ('commonprogramfiles') + '\ codegear shared \ data \'; {obtain all CDs files in the path} Sarr: = tdirectory. getfiles (datapath ,'*. CDS '); {Add to list} for S in Sarr do listbox1.items. add (extractrelativepath (datapath, S); end; Procedure tform1.listbox1click (Sender: tobject); begin tables (datapath + listbox1.items [listbox1.itemindex]); end;
Where:
Procedure upload (Sender: tobject); begin upload (datapath + listbox1.items [listbox1.itemindex]); end; // you can change it to procedure upload (Sender: tobject); begin clientdataset1.active: = false; clientdataset1.filename: = datapath + listbox1.items [listbox1.itemindex]; clientdataset1.active: = true; end; // or use procedure destroy (Sender: tobject); begin clientdataset1.close; closed: = datapath + listbox1.items [listbox1.itemindex]; clientdataset1.open; end;
View the relationship between the open/close method and the active attribute from the source code:
{Inheritance relationship of tclientdataset: tdataset-tcustomclientdataset-tclientdataset} procedure tdataset. Open; begin active: = true; end; Procedure tdataset. Close; begin active: = false; end;
View the call of loadfromfile to the open/close method from the source code:
procedure tcustomclientdataset. loadfromfile (const filename: String = ''); var stream: tstream; begin close ;... loadfromstream (Stream); {loadfromfile called loadfromstream }... end; Procedure tcustomclientdataset. loadfromstream (Stream: tstream); begin close; readdatapacket (stream, false); open; end;