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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Delphi's TClientDataSet - The basics, please.

Status
Not open for further replies.

VuurSnikkel

Programmer
Sep 8, 2003
16
NL
Hello there...


I'm currently programming quite a large application using Delphi 7 Enterprise and my application is also in need of a database. Since the database only needs to run on a single machine (just a local database, nothing fancy), doesn't need to be that large and/or complex and since I don't want to use a server technology, I chose Delphi's TClientDataSet and file-based data storage (XML) as the way to go.

For some reason, though, I find working with the TClientDataSet extremely cumbersome (it's probably just me ;-)). It might have something to do with the fact that I've been using MySQL in conjunction with PHP for the last couple of years and it kind of grew on me. But since I didn't want to use any server technology, I discarded SQL as an option. So now I'm wondering how to do basic things like inserting, deleting, sorting records etc. with my TClientDataSet, things that went like a breeze when using MySQL (I must say that the way in which the "Using TClientDataSet"-help is organized within Delphi isn't quite that helpful).

So is there a tutorial out there somewhere that gets SQL-users up to speed as far as the usage of the TClientDataSet is concerned or is there some possibility of using SQL to access the TClientDataSet without having to rewrite large parts of my code (I've already created a lot of classes and auxiliary code for managing the TClientDataSets, so I don't want to abandon them)? Thanks in advance.


GRTZ,

(Sn)Ik.
 
Using a CDS with its file based storage. When you LoadFromFile, the whole file is loaded into the CDS. When you SaveToFile, the whole contents of the CDS are save to the file.

There is no SQL interpreter.

For various tasks use methods and properties as follows. See Delphi help on how to use each one.
Inserting a record: Append or AppendRecord
Deleting: Delete
Sorting, simple: IndexFieldNames
Sorting, advanced: IndexDefs and IndexName
Working on a subset records: Filter and Filtered
Finding: Locate or Lookup
Begin/End Transaction: SavePoint

Above are the easy ones. If you want to do something like
SELECT SUM(Value) WHERE CustomerID=29
you either write code like:

with ClientDataSet1 do begin
Filter:='CustomerID=29;
Filtered:=true;
try
LVal:=0;
First;
while not EOF do begin
LVal:=LVal+FieldName('Value').asCurrency;
Next;
end;
finally
Filtered:=false;
end;
end;

or use Aggregates. Aggregates do work, but are a bit fiddely. The one that particularly got me first time is that there is a property:
TClientDataset.AggregatesActive
and another
TAggregate.Active
You need them both true for anything to happen.

Have fun
Simon
 
Thanks for your info, I'll try to work my way through the TClientDataSet methods.


GRTZ,

(Sn)Ik.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top