Board index » cppbuilder » Nested data set RecordCount as calculated field of parent.

Nested data set RecordCount as calculated field of parent.


2008-01-31 04:52:34 PM
cppbuilder114
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
 
 

Re:Nested data set RecordCount as calculated field of parent.

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
 

Re:Nested data set RecordCount as calculated field of parent.

On Tue, 5 Feb 2008 00:03:54 -0500, "Jason Cipriani"
< XXXX@XXXXX.COM >wrote:
Quote
3) Is this not the right newsgroup for questions about TClientDataSets? The
ask in .datasnap and .delphi.database.multi-tier
--
Vladimir Ulchenko aka vavan
 

{smallsort}

Re:Nested data set RecordCount as calculated field of parent.

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. (Note, well maybe #3
doesn't make sense any more, this post has been travelling around quite a
bit.)
Thanks!
Jason
 

Re:Nested data set RecordCount as calculated field of parent.

All right, thanks.
"vavan" < XXXX@XXXXX.COM >wrote in message
Quote
On Tue, 5 Feb 2008 00:03:54 -0500, "Jason Cipriani"
< XXXX@XXXXX.COM >wrote:

>3) Is this not the right newsgroup for questions about TClientDataSets?
>The

ask in .datasnap and .delphi.database.multi-tier

--
Vladimir Ulchenko aka vavan
 

Re:Nested data set RecordCount as calculated field of parent.

Jason Cipriani wrote:
Quote

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?

I believe there are some issues regarding the sequence of events such
that when OnCalcFields is fired, the nested dataset isn't synchronized.
Somebody else may be able to provide a better answer.
Quote
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).

(ADataSet.FieldByName('MyDataSetField') as TDataSetField).NestedDataSet
JB
--
 

Re:Nested data set RecordCount as calculated field of parent.

"Johannes Bjerregaard" <jozzb@hotmail[dot]com>wrote in message
Quote
I believe there are some issues regarding the sequence of events such
that when OnCalcFields is fired, the nested dataset isn't synchronized.
Somebody else may be able to provide a better answer.
Hmm... well I'll do some more research and post here if I find anything.
This seems like something -somebody- would have wanted to do in the past...
I'll get to the bottom of it sooner or later.
Quote
(ADataSet.FieldByName('MyDataSetField') as TDataSetField).NestedDataSet
Great, thanks. Maybe I should learn Delphi... doing that safely in C++ is
not nearly as pretty looking.
This also returns a reference to the same data set no matter what master
record is selected; which I guess confirms what I just learned about
TClientDataSet::EmptyDataSet's affect on every master record's detail data.
It makes me happy when stuff makes sense -- it seems to happen so rarely!
Jason
 

Re:Nested data set RecordCount as calculated field of parent.

Jason Cipriani wrote:
Quote
I have been unable to make any progress getting this to work. How did
you find out about these issues; is there a QC report or article
you've come across, is it something you've observed yourself?
It is by design and has been that way since Delphi 1.0 and the BDE.
With the BDE and Paradox tables the solution was to drop another TTable
on the form, connect it to the detail table, then, in the OnCalcFields
event handler set a range on the TTable and get the record count.
--
Bill Todd (TeamB)
 

Re:Nested data set RecordCount as calculated field of parent.

"Johannes Bjerregaard" <jozzb@hotmail[dot]com>wrote in message
Quote
>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?

I believe there are some issues regarding the sequence of events such
that when OnCalcFields is fired, the nested dataset isn't synchronized.
I have been unable to make any progress getting this to work. How did you
find out about these issues; is there a QC report or article you've come
across, is it something you've observed yourself?
Thanks,
Jason
 

Re:Nested data set RecordCount as calculated field of parent.

I see. Thanks. Entirely out of curiosity, do you happen to know why
attempting to get the RecordCount in OnCalcFields causes duplicate rows to
appear in an attached TDBGrid? If you do know, but it's a really complex
explanation, then don't worry about it it's not important -- I'm mostly just
wondering.
Jason
"Bill Todd [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Jason Cipriani wrote:

>I have been unable to make any progress getting this to work. How did
>you find out about these issues; is there a QC report or article
>you've come across, is it something you've observed yourself?

It is by design and has been that way since Delphi 1.0 and the BDE.
With the BDE and Paradox tables the solution was to drop another TTable
on the form, connect it to the detail table, then, in the OnCalcFields
event handler set a range on the TTable and get the record count.

--
Bill Todd (TeamB)
 

Re:Nested data set RecordCount as calculated field of parent.

Jason Cipriani wrote:
Quote
I see. Thanks. Entirely out of curiosity, do you happen to know why
attempting to get the RecordCount in OnCalcFields causes duplicate
rows to appear in an attached TDBGrid? If you do know, but it's a
really complex explanation, then don't worry about it it's not
important -- I'm mostly just wondering.
I do not know. Sorry.
--
Bill Todd (TeamB)
 

Re:Nested data set RecordCount as calculated field of parent.

Jason Cipriani wrote:
Quote
"Johannes Bjerregaard" <jozzb@hotmail[dot]com>wrote in message
news:47a8ef66$ XXXX@XXXXX.COM ...
>>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?
>
>I believe there are some issues regarding the sequence of events
>such that when OnCalcFields is fired, the nested dataset isn't
>synchronized.

I have been unable to make any progress getting this to work. How did
you find out about these issues; is there a QC report or article
you've come across, is it something you've observed yourself?

Thanks,
Jason
Try to analyze DataSet.state = dsCalcFields in OnCalcFields event.
--
 

Re:Nested data set RecordCount as calculated field of parent.

"Elohim Meth" < XXXX@XXXXX.COM >wrote in message
Quote
Jason Cipriani wrote:

>"Johannes Bjerregaard" <jozzb@hotmail[dot]com>wrote in message
>news:47a8ef66$ XXXX@XXXXX.COM ...
>>>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?
>>
>>I believe there are some issues regarding the sequence of events
>>such that when OnCalcFields is fired, the nested dataset isn't
>>synchronized.
>
>I have been unable to make any progress getting this to work. How did
>you find out about these issues; is there a QC report or article
>you've come across, is it something you've observed yourself?
>
>Thanks,
>Jason

Try to analyze DataSet.state = dsCalcFields in OnCalcFields event.
Thanks for your reply.
The State property is dsCalcFields every time OnCalcFields happens; I
verified it with assert().
- Jason