| View previous topic :: View next topic |
| Author |
Message |
Preston Guest
|
Posted: Fri Jul 30, 2004 8:16 pm Post subject: How do I add an existing CDS to another CDS as a nested data |
|
|
I have two seperate data modules that each contain a cds. At runtime I'd
like to make one of the cds a nested cds of the other.
I've been using the code provided by Cary Jensen in ""Nesting DataSets in
ClientDataSets". This code compiles, but throws a " Field 'labelStock' not
found" error at runtime. I am not defining the data fields at runtime as
they are already defined on the cds as persistent fields.
with TDataSetField.Create(Self) do
begin
Name := 'labelStock';
FieldName := 'labelStock';
DataSet := cdsMaster;
end;
//////////////////////////////////////////////
localLabelStockDM.cdsMaster.DataSetField :=
TDataSetField(FindComponent('labelStock'));
Can anyone else provide a code snippet that shows how this might be done?
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Fri Jul 30, 2004 9:17 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
DetailCds.DataSetField := OtherDm.MasterCdsDataSetField;
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Fri Jul 30, 2004 10:25 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
Hi Bill,
I added a persistent field to CDSMaster. Then I did
detailDMl.cdsDetail.DataSetField := cdsMasterDataSetField (DataSetField
being the field created above).
This also produces the "Field 'x' not found"
Preston
"Bill Todd (TeamB)" <no (AT) no (DOT) com> wrote
| Quote: | DetailCds.DataSetField := OtherDm.MasterCdsDataSetField;
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Fri Jul 30, 2004 11:32 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
Let's assume that the name of the detail datasetfield as shown in the
Fields Editor is DetailData. Then
detailDMl.cdsDetail.DataSetField := cdsMasterDetailData;
should work if cdsMaster is on the data module that contains this
code. Otherwise add the data module name.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Mon Aug 02, 2004 9:17 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
That's what I have and it's not working... maybe I'm getting confused here
:)
DM1 and DM2 both descend from DM which contains cdsMaster
I want to assign DM2.cdsMaster as a nested dataset of DM1.cdsMaster.
In DM1 I did the following:
1. Created a persistent field in cdsMaster called
cdsMasterNewPersistentField
2. Created a local instance of DM2 called localDM2
3. localDM2.cdsMaster.DataSetField := cdsMasterNewPersistentField
That's generating the Field "NewPersistentField" not found error.
"Bill Todd (TeamB)" <no (AT) no (DOT) com> wrote
| Quote: | Let's assume that the name of the detail datasetfield as shown in the
Fields Editor is DetailData. Then
detailDMl.cdsDetail.DataSetField := cdsMasterDetailData;
should work if cdsMaster is on the data module that contains this
code. Otherwise add the data module name.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Mon Aug 02, 2004 9:47 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
On Mon, 2 Aug 2004 15:17:49 -0600, "Preston" <nospam (AT) nospam (DOT) com>
wrote:
| Quote: | That's what I have and it's not working... maybe I'm getting confused here
:)
DM1 and DM2 both descend from DM which contains cdsMaster
I want to assign DM2.cdsMaster as a nested dataset of DM1.cdsMaster.
|
You cannot always have what you want.<g> The only way to have a
nested dataset is is to link the source datasets. However, you can
link the ClientDataSets by setting the MasterSource and MasterFields
properties of the detail CDS.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Mon Aug 02, 2004 10:13 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
Now I've got that song stuck in my head "You can't always get what you want"
Thanks for the explanation. I think I understand what I need to do now.
Preston
"Bill Todd (TeamB)" <no (AT) no (DOT) com> wrote
| Quote: | On Mon, 2 Aug 2004 15:17:49 -0600, "Preston" <nospam (AT) nospam (DOT) com
wrote:
That's what I have and it's not working... maybe I'm getting confused
here
:)
DM1 and DM2 both descend from DM which contains cdsMaster
I want to assign DM2.cdsMaster as a nested dataset of DM1.cdsMaster.
You cannot always have what you want.
nested dataset is is to link the source datasets. However, you can
link the ClientDataSets by setting the MasterSource and MasterFields
properties of the detail CDS.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
|
| Back to top |
|
 |
Bill Todd (TeamB) Guest
|
Posted: Mon Aug 02, 2004 10:32 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
On Mon, 2 Aug 2004 16:13:38 -0600, "Preston" <nospam (AT) nospam (DOT) com>
wrote:
| Quote: | Thanks for the explanation. I think I understand what I need to do now.
|
Let us know if you have any more problems.
--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Tue Aug 03, 2004 3:26 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
I've tried this every which way I can think of, and it's still not working.
I'm starting to wonder if it's possible. Maybe it's a problem with Midas?
BTW I'm using version 7.1.1692.666
DM1 and DM2 both descend from DM which contains a SQLQuery, DataSource, and
a ClientDataSet. I want to assign DM2.cds as a nested dataset of DM1.cds
In DM1 I did the following:
1.. Created a local instance of DM2 called localDM2
2. Assigned dm2.SQLQuery.DataSource to dm1.DataSource
3. Create a TDataSetField
4. dm2.cds.DataSetField := TDataSetField(cds.FindField('FieldName'))
5. set dm2.SQLQuery.SQL to reflect the master detail relationship
This generates the Field 'FieldName' not found error. As a variation I've
tried using a persistentField. I also tried copying dm2.SQLQuery over to dm1
at design time and I'm able to hook it up just fine. It just won't work at
runtime.
You suggested using the cds.MasterSource to establish a relationship. I
really need the nested detail relationship. Any other suggestions?
Preston
current code
begin
// create a label stock dm
localLabelStockDM := TlabelStockDM.Create(self);
localLabelStockDM.cdsMaster.Active := False;
// assign the local dm datasource to cdsMaster
localLabelStockDM.SQLMaster.DataSource := DataSource1;
// create a dataSetField
with TDataSetField.Create(Self) do
begin
Name := 'labelStock';
FieldName := 'labelStock';
DataSet := cdsMaster;
end;
// add labelStockDM.cdsMaster as a nested cds of cdsMaster
localLabelStockDM.cdsMaster.DataSetField :=
TDataSetField(cdsMaster.FindField('labelStock'));
// set the sql
localLabelStockDM.SQLMaster.SQL.Add('SELECT * FROM LabelStock WHERE
LabelStockCode = ''1'' ');
localLabelStockDM.cdsMaster.Active := True;
// create the nested dataset relationship
//localLabelStockDM.CdsMaster.DataSetField := cdsMasterLabelStock;
end;
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Tue Aug 03, 2004 3:45 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
"Preston" <nospam (AT) nospam (DOT) com> wrote:
| Quote: | You suggested using the cds.MasterSource to establish a relationship. I
really need the nested detail relationship. Any other suggestions?
|
You cannot define a nested dataset relationship between two CDSs that
are fed by two DSPs respectively.
You can only establish a nested M/D relationship between CDSs when
they are created by CDS.CreateDataSet, having already defined the
TDataSet field in the master.
To establish a nested CDS relationship where the CDSs are fed from
DSPs, you must set the M/D relationship between the
DSP.DataSet(master) and another dataset via a TDataSource. The data
returned by the single DSP to the cdsMaster will contain the master
dataset, and the detail dataset as a nested DS.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Tue Aug 03, 2004 4:39 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
| Quote: | You can only establish a nested M/D relationship between CDSs when
they are created by CDS.CreateDataSet, having already defined the
TDataSet field in the master.
|
Do I need to call CDS.CreateDataSet at runtime?
| Quote: | To establish a nested CDS relationship where the CDSs are fed from
DSPs, you must set the M/D relationship between the
DSP.DataSet(master) and another dataset via a TDataSource. The data
returned by the single DSP to the cdsMaster will contain the master
dataset, and the detail dataset as a nested DS.
|
How do you establish a M/D relationship using a DSP? I thought the
relationship was established using SQLQuery.DataSource. If I had 1 master
DatatSet and 5 detail DataSet's I would only need one DSP which points to
the master DataSet... correct? The ClientDataSet's themselves just need the
DataSetField property set. The providerName property is left blank...
correct?
Now I want to throw in an additional detail ClientDataSet that is already
hooked up to a DSP. Do I need to discard that DSP and reset the properties
on the DataSet and the ClientDataSet?
Preston
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Wed Aug 04, 2004 12:16 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
"Preston" <nospam (AT) nospam (DOT) com> wrote:
| Quote: | To establish a nested CDS relationship where the CDSs are fed from
DSPs, you must set the M/D relationship between the
DSP.DataSet(master) and another dataset via a TDataSource. The data
returned by the single DSP to the cdsMaster will contain the master
dataset, and the detail dataset as a nested DS.
How do you establish a M/D relationship using a DSP? I thought the
relationship was established using SQLQuery.DataSource. If I had 1 master
DatatSet and 5 detail DataSet's I would only need one DSP which points to
the master DataSet... correct?
|
Yes, (I thought that was what I said :)
| Quote: | The ClientDataSet's themselves just need the
DataSetField property set. The providerName property is left blank...
correct?
|
Yes.
| Quote: | Now I want to throw in an additional detail ClientDataSet that is already
hooked up to a DSP. Do I need to discard that DSP and reset the properties
on the DataSet and the ClientDataSet?
|
You need to link the additional detail DSP.DataSet into the main M/D
relationship definition, and discard the additional detail DSP. Set
the additional detail CDS.DataSetField to point to the appropriate
nested dataset field.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Wed Aug 04, 2004 2:26 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
At design time this works just fine.
1. On the secondDM change the SQLQuery.DataSet to point to the master
dataset.
2. On the secondDM clear the DSP of it's settings.
3. On the firstDM add the nested dataset persistently.
4. On the secondDM change the cds.DataSetField to be the persistent field
added above.
So why don't these same steps work at runtime? It really feels like a bug.
Can someone verify that this stuff works at runtime.
"Dave Rowntree" <daver@too much spam far too much [bro oks wo od] d o t c o
d o t u k> wrote
| Quote: | "Preston" <nospam (AT) nospam (DOT) com> wrote:
To establish a nested CDS relationship where the CDSs are fed from
DSPs, you must set the M/D relationship between the
DSP.DataSet(master) and another dataset via a TDataSource. The data
returned by the single DSP to the cdsMaster will contain the master
dataset, and the detail dataset as a nested DS.
How do you establish a M/D relationship using a DSP? I thought the
relationship was established using SQLQuery.DataSource. If I had 1 master
DatatSet and 5 detail DataSet's I would only need one DSP which points to
the master DataSet... correct?
Yes, (I thought that was what I said :)
The ClientDataSet's themselves just need the
DataSetField property set. The providerName property is left blank...
correct?
Yes.
Now I want to throw in an additional detail ClientDataSet that is already
hooked up to a DSP. Do I need to discard that DSP and reset the
properties
on the DataSet and the ClientDataSet?
You need to link the additional detail DSP.DataSet into the main M/D
relationship definition, and discard the additional detail DSP. Set
the additional detail CDS.DataSetField to point to the appropriate
nested dataset field.
--
Dave Rowntree
|
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Wed Aug 04, 2004 2:40 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
"Preston" <nospam (AT) nospam (DOT) com> wrote:
| Quote: | So why don't these same steps work at runtime? It really feels like a bug.
Can someone verify that this stuff works at runtime.
|
If you put a compilable, zipped-up app (excluding executables) on
b.p.attachments, that uses employee.gdb to demonstrates the problem
you are seeing, then post back here saying you have done so, I will
have a look.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Preston Guest
|
Posted: Wed Aug 04, 2004 8:06 pm Post subject: Re: How do I add an existing CDS to another CDS as a nested |
|
|
Hi Dave,
I don't have IB installed. However I used a TQuery and DBDemos DB to
duplicate the issue.
Preston
"Dave Rowntree" <daver@too much spam far too much [bro oks wo od] d o t c o
d o t u k> wrote
| Quote: | "Preston" <nospam (AT) nospam (DOT) com> wrote:
So why don't these same steps work at runtime? It really feels like a
bug.
Can someone verify that this stuff works at runtime.
If you put a compilable, zipped-up app (excluding executables) on
b.p.attachments, that uses employee.gdb to demonstrates the problem
you are seeing, then post back here saying you have done so, I will
have a look.
--
Dave Rowntree
|
|
|
| Back to top |
|
 |
|