| View previous topic :: View next topic |
| Author |
Message |
Jaroslav Demin Guest
|
Posted: Wed Jul 02, 2003 9:33 am Post subject: TClientDataSet and LookupFields |
|
|
Good morning!
I need to have Lookup field in my TclientDataSet component.
For some reasons I can not use fields editor.
How can I append lookupfield for TclientDataSet at Run-time.
Thank You
|
|
| Back to top |
|
 |
Ignacio Vazquez Guest
|
Posted: Wed Jul 02, 2003 9:40 am Post subject: Re: TClientDataSet and LookupFields |
|
|
"Jaroslav Demin" <dejar (AT) mail (DOT) ru> wrote
| Quote: | I need to have Lookup field in my TclientDataSet component.
|
It's easier if you create the lookup field in the source TDataSet and let
the TClientDataSet pull it from there.
Cheers,
Ignacio
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Wed Jul 02, 2003 10:53 am Post subject: Re: TClientDataSet and LookupFields |
|
|
"Jaroslav Demin" <dejar (AT) mail (DOT) ru> wrote:
| Quote: | Good morning!
I need to have Lookup field in my TclientDataSet component.
For some reasons I can not use fields editor.
How can I append lookupfield for TclientDataSet at Run-time.
|
Here is one way:
Assuming 'ClientDataSet1' is your main CDS, and 'cdsLookup' is your
lookup CDS ...
var
i: integer;
f: TField;
begin
// fetch the FieldDefs to the CDS ...
ClientDataSet1.Open;
ClientDataSet1.Close;
//create persistent fields for any that do not already exist ...
for i := 0 to ClientDataSet1.FieldDefs.Count - 1 do
if ClientDataSet1.FindField(ClientDataSet1.FieldDefs[i].Name) =
nil then
ClientDataSet1.FieldDefs.Items[i].CreateField(ClientDataSet1);
//create a new lookup currency field ...
f := TCurrencyField.Create(ClientDataSet1);
f.Name := 'ClientDataSet1MyLookupField';
f.FieldName := 'MyLookupField';
f.FieldKind := fkLookup;
f.KeyFields := 'A_ID';
f.LookupDataSet := cdsLookup;
f.LookupKeyFields := 'A_ID';
f.LookupResultField := 'Amount';
f.DataSet := ClientDataSet1;
ClientDataSet1.Open;
end;
If you already have persistent fields on ClientDataSet1, you do not
need the first section of code (above // create a new lookup currency
field), you just need to make sure ClientDataSet1 is closed.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Wed Jul 02, 2003 10:53 am Post subject: Re: TClientDataSet and LookupFields |
|
|
"Ignacio Vazquez" <ivazquezATorioncommunications.com> wrote:
| Quote: | "Jaroslav Demin" <dejar (AT) mail (DOT) ru> wrote in message
news:3f02a6bd (AT) newsgroups (DOT) borland.com...
I need to have Lookup field in my TclientDataSet component.
It's easier if you create the lookup field in the source TDataSet and let
the TClientDataSet pull it from there.
|
Lookup fields created on the DSP.DataSet are read only at the CDS.
--
Dave Rowntree
|
|
| Back to top |
|
 |
Jaroslav Demin Guest
|
Posted: Wed Jul 02, 2003 1:55 pm Post subject: Re: TClientDataSet and LookupFields |
|
|
Thank you Dave!
Your advise is clear and well-demonstrated with source code!
It's really helpfull!
Thank you
"Dave Rowntree" <daver (AT) spam_offbrookswood (DOT) co.uk> wrote
| Quote: | "Jaroslav Demin" <dejar (AT) mail (DOT) ru> wrote:
Good morning!
I need to have Lookup field in my TclientDataSet component.
For some reasons I can not use fields editor.
How can I append lookupfield for TclientDataSet at Run-time.
Here is one way:
Assuming 'ClientDataSet1' is your main CDS, and 'cdsLookup' is your
lookup CDS ...
var
i: integer;
f: TField;
begin
// fetch the FieldDefs to the CDS ...
ClientDataSet1.Open;
ClientDataSet1.Close;
//create persistent fields for any that do not already exist ...
for i := 0 to ClientDataSet1.FieldDefs.Count - 1 do
if ClientDataSet1.FindField(ClientDataSet1.FieldDefs[i].Name) =
nil then
ClientDataSet1.FieldDefs.Items[i].CreateField(ClientDataSet1);
//create a new lookup currency field ...
f := TCurrencyField.Create(ClientDataSet1);
f.Name := 'ClientDataSet1MyLookupField';
f.FieldName := 'MyLookupField';
f.FieldKind := fkLookup;
f.KeyFields := 'A_ID';
f.LookupDataSet := cdsLookup;
f.LookupKeyFields := 'A_ID';
f.LookupResultField := 'Amount';
f.DataSet := ClientDataSet1;
ClientDataSet1.Open;
end;
If you already have persistent fields on ClientDataSet1, you do not
need the first section of code (above // create a new lookup currency
field), you just need to make sure ClientDataSet1 is closed.
--
Dave Rowntree
|
|
|
| Back to top |
|
 |
Dave Rowntree Guest
|
Posted: Wed Jul 02, 2003 2:27 pm Post subject: Re: TClientDataSet and LookupFields |
|
|
"Jaroslav Demin" <dejar (AT) mail (DOT) ru> wrote:
| Quote: | Thank you Dave!
Your advise is clear and well-demonstrated with source code!
It's really helpfull!
Thank you
|
You're welcome, and thanks for the compliment.
--
Dave Rowntree
|
|
| Back to top |
|
 |
|