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

Reply via email to