🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.multi-tier
Article #151

Nested data set RecordCount as calculated field of parent.

#151
From: Jason Cipriani
Date: Tue, 05 Feb 2008 05:03
45 lines
3122 bytes
I have a TClientDataSet with 2 fields: One field is of type DataSet and is
attached to another nested TClientDataSet, the other field is of type
Integer and is a calculated field. I want the calculatd field to display the
RecordCount of the nested TClientDataSet. Both are attached to TDBGrid
controls.

This is what I am doing now. In the following code, DSMaster is the master,
DSChild is the nested one, "Items" is the data set field, and "ItemCount" is
the calculated field. Here is my OnCalcFields handler for DSMaster:

void __fastcall TForm1::DSMasterCalcFields(TDataSet *DataSet) {

    DSMaster->FieldByName("NItems")->AsInteger =
        DSChild->RecordCount;

}

For some reason doing this cause duplicate records to appear in DSMaster's
DBGrid control. It does not add duplicate records to the database, but
rather, creates many row in the DBGrid that all reference the same record
(i.e. edit one and the change shows up in all the copies). The duplication
appears somewhat random but is somehow related to how I use the vertical
scroll bar in the DBGrid control.

Questions:

1) How do I do what I'm trying to do -- that is, display the number of
records in a nested data set in a calculated field of the master data set?

2) How do I access the TClientDataSet of a TField that is a data set? There
is AsInteger, AsString, etc., but no AsDataSet? Without being able to do
this I can not calculate fields in OnCalcFields using only the TDataSet*
passed to the function, I must use some variables from outside the function
as well (e.g. using DSChild in the above example).

3) Is this not the right newsgroup for questions about TClientDataSets? The
borland.public.cppbuilder.database.desktop newsgroup is all but dead, and
none of the other borland.public.cppbuilder.database.* groups looked
appropriate. This -is- a VCL component, and as a matter of fact it's one of
my favorites, but nobody seems to know much about it. From what I've read
TClientDataSet was only recently moved from Enterprise to Professional
edition so maybe it's a mystery to everybody, still.

Thanks,
Jason
Technical Details
Message-ID: <47a7ee42@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: fcd2b,9807d65e41e65e64,start
X-Google-Attributes: gidfcd2b,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Jason Cipriani" <jason.cipriani@nospam-gmail.com>
From: "Jason Cipriani" <jason.cipriani@nospam-gmail.com>
Newsgroups: borland.public.cppbuilder.database.multi-tier
Subject: Nested data set RecordCount as calculated field of parent.
Date: Tue, 5 Feb 2008 00:03:54 -0500
Lines: 48
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 69.112.246.56
Message-ID: <47a7ee42@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1202187842 69.112.246.56 (4 Feb 2008 21:04:02 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail