BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TClientDataSet and LookupFields

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier)
View previous topic :: View next topic  
Author Message
Jaroslav Demin
Guest





PostPosted: Wed Jul 02, 2003 9:33 am    Post subject: TClientDataSet and LookupFields Reply with 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.

Thank You


Back to top
Ignacio Vazquez
Guest





PostPosted: Wed Jul 02, 2003 9:40 am    Post subject: Re: TClientDataSet and LookupFields Reply with quote



"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





PostPosted: Wed Jul 02, 2003 10:53 am    Post subject: Re: TClientDataSet and LookupFields Reply with quote



"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





PostPosted: Wed Jul 02, 2003 10:53 am    Post subject: Re: TClientDataSet and LookupFields Reply with quote

"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





PostPosted: Wed Jul 02, 2003 1:55 pm    Post subject: Re: TClientDataSet and LookupFields Reply with quote

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





PostPosted: Wed Jul 02, 2003 2:27 pm    Post subject: Re: TClientDataSet and LookupFields Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Multi-Tier) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.