Hi Brad,

I asked "Do you also need to add these fields to a query?"

If the ClientDataset is tied to a Query and not used as an in-memory dataset
then you must first add it to the query before adding it to the
ClientDataset.

I know this works because we build our queries and clientdatasets on the fly
as needed in out program.

Here is three actual procedures that we use to create 3 different query
fields (Integer, Date and String):

{---------------------------------------------------------------------------
--
  Procedure: AddQueryStringField
  Author:    Michael Tuttle
  Date:      2001
  Purpose:
----------------------------------------------------------------------------
-}
procedure TdtmAccountRem.AddQueryStringField(Query: TIBQuery; FldName:
String;
  FldKind: TFieldKind; FieldSize: Integer);
var
  fldString: TStringField;
begin
  fldString := TStringField.Create(Query);

  with fldString do
    begin
      FieldName := FldName;
      FieldKind := FldKind;
      DisplayLabel := FieldName;
      Size := FieldSize;
      DataSet := Query;
      Name := Query.Name + FieldName;
      ProviderFlags := [];
    end;

  with Query.FieldDefs do
    begin
      Add(fldString.Name, ftString, FieldSize, False);
      Update;
    end;
end;

{---------------------------------------------------------------------------
--
  Procedure: AddQueryDateField
  Author:    Michael Tuttle
  Date:      2001
  Purpose:
----------------------------------------------------------------------------
-}
procedure TdtmAccountRem.AddQueryDateField(Query: TIBQuery; FldName: String;
  FldKind: TFieldKind);
var
  fldDate: TDateField;
begin
  fldDate := TDateField.Create(Query);

  with fldDate do
    begin
      FieldName := FldName;
      FieldKind := FldKind;
      DisplayLabel := FieldName;
      DataSet := Query;
      Name := Query.Name + FieldName;
      ProviderFlags := [];
    end;

  with Query.FieldDefs do
    begin
      Add(fldDate.Name, ftDate, 0, False);
      Update;
    end;
end;

{---------------------------------------------------------------------------
--
  Procedure: AddQueryIntegerField
  Author:    Michael Tuttle
  Date:      2001
  Purpose:
----------------------------------------------------------------------------
-}
procedure TdtmAccountRem.AddQueryIntegerField(Query: TIBQuery; FldName:
String;
  FldKind: TFieldKind);
var
  fldIntegerField: TIntegerField;
begin
  fldIntegerField := TIntegerField.Create(Query);

  with fldIntegerField do
    begin
      FieldName := FldName;
      FieldKind := FldKind;
      DisplayLabel := FieldName;
      DataSet := Query;
      Name := Query.Name + FieldName;
      ProviderFlags := [];
    end;

  with Query.FieldDefs do
    begin
      Add(fldIntegerField.Name, ftInteger, 0, False);
      Update;
    end;
end;

Here is an example call:
AddQueryIntegerField(qryAddress, PERSON_ID, fkData);

Again create the query field first then the clientdataset field.  We do it
all the time.

Good luck and let me know how this works out for you.

Mike

----- Original Message ----- 
From: "Gies,Brad" <[EMAIL PROTECTED]>
To: "Delphi-Talk Discussion List" <[email protected]>
Sent: Monday, October 10, 2005 7:43 PM
Subject: RE: Adding a field to a ClientDataSet at runtime


> Mike,
>
> Are you sure about that? Reading the help for update sounds like it
> looks at the fields and updates the definitions according to the fields,
> not the fields according to the definitions. I'll try it anyway though.
>
> I have tried just creating a new TField Object and adding it to the
> ClientDataSet using the Fields.Add method, but when trying to add a
> value to the field it couldn't find it. I'm not sure why.
>
>
> Sincerely,
>
> Brad Gies
> -------------------------------------
> NLM Software
> Southfield, MI, USA
> ------------------------------------- 
>
>
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:delphi-talk-
> > [EMAIL PROTECTED] On Behalf Of M Tuttle (KS)
> > Sent: Monday, October 10, 2005 7:58 PM
> > To: Delphi-Talk Discussion List
> > Subject: Re: Adding a field to a ClientDataSet at runtime
> >
> > Something like this.  Do you also need to add these field to a query?
> >
> > Procedure SomeProcedure
> > var
> >   fldStringField: TStringField;
> >   fldIntegerField: TIntegerField;
> > begin
> >
> > with cdsAddress do
> > begin
> >       //* Add the persistent field
> >       with FieldDefs do
> >         begin
> >             fldIntegerField := TIntegerField.Create(cdsAddress);
> >            with fldIntegerField do
> >                 begin
> >                   FieldName := 'FIELD_NAME';
> >                   DisplayLabel := FieldName;
> >                   DataSet := cdsAddress;
> >                   Name := cdsAddress.Name + FieldName;
> >                   cdsAddress.FieldDefs.Add(fldIntegerField.Name,
> > ftInteger,
> > 0, False);
> >                 end;
> >
> >             fldStringField := TStringField.Create(cdsAddress);
> >             with fldStringField do
> >                 begin
> >                   FieldName := 'ANOTHER_FIELD_NAME';
> >                   DisplayLabel := FieldName;
> >                   DataSet := cdsAddress;
> >                   Name := cdsAddress.Name + FieldName;
> >                   cdsAddress.FieldDefs.Add(fldStringField.Name,
> ftString,
> > 1,
> > False);
> >                 end;
> >
> >           //* Update the field defs
> >           Update;
> >         end;
> >     end;
> > end:
> >
> > ----- Original Message -----
> > From: "Gies,Brad" <[EMAIL PROTECTED]>
> > To: "Delphi-Talk Discussion List" <[email protected]>
> > Sent: Monday, October 10, 2005 6:44 PM
> > Subject: Adding a field to a ClientDataSet at runtime
> >
> >
> > >
> > > Does anyone know how to add a new field to a ClientDataSet after the
> > > DataSet is already created? Is it possible?
> > >
> > > Sincerely,
> > >
> > > Brad Gies
> > > -------------------------------------
> > > NLM Software
> > > Southfield, MI, USA
> > > -------------------------------------
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > This e-mail is intended only for the person or entity to which it is
> > addressed and may
> > > contain confidential and/or privileged material.  Any review,
> > retransmission,
> > > dissemination or other use of, or taking of any action in reliance
> upon,
> > this information
> > > by persons or entities other than the intended recipient is
> prohibited.
> > If you
> > > received this message in error, please contact the sender
> immediately
> > and
> > delete
> > > the material from your computer.
> > > __________________________________________________
> > > Delphi-Talk mailing list -> [email protected]
> > > http://www.elists.org/mailman/listinfo/delphi-talk
> > >
> > >
> >
> >
> > __________________________________________________
> > Delphi-Talk mailing list -> [email protected]
> > http://www.elists.org/mailman/listinfo/delphi-talk
>
>
> This e-mail is intended only for the person or entity to which it is
addressed and may
> contain confidential and/or privileged material.  Any review,
retransmission,
> dissemination or other use of, or taking of any action in reliance upon,
this information
> by persons or entities other than the intended recipient is prohibited.
If you
> received this message in error, please contact the sender immediately and
delete
> the material from your computer.
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
>
>


__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to