RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TFieldDefs.AddFieldDef Method

Creates a new field definition object and adds it to the Items property of this TFieldDefs object.

Pascal
function AddFieldDef: TFieldDef;
C++
__fastcall TFieldDef AddFieldDef();

Call AddFieldDef to add field definitions when creating a client dataset's data or a database table. AddFieldDef returns the new TFieldDef object that is added to the collection of field definitions. After calling AddFieldDef, set the properties of the newly added TFieldDef object to specify the name, type, and size of field that should be created.

Note: AddFieldDef is only valid in the context of creating field definitions for a table to be created with a subsequent call to the CreateTable
or CreateDataSet method. It cannot be used to add fields to an already-existing table.  

C++ Examples: 

 

/*
The following code creates and activates a client dataset in
the form’s OnCreate event handler.
*/ 
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  TFieldDefs *pDefs = CDS2->FieldDefs;
  TFieldDef *pDef = pDefs->AddFieldDef();
  pDef->DataType = ftInteger;
  pDef->Name = "Field1";

  pDef = pDefs->AddFieldDef();
  pDef->DataType = ftString;
  pDef->Size = 10;
  pDef->Name = "Field2";

  TIndexDef *pIDef = CDS2->IndexDefs->AddIndexDef();
  pIDef->Fields = "Field1";
  pIDef->Name = "IntIndex";

  CDS2->CreateDataSet();
}

 

Delphi Examples: 

{
The following code creates and activates a client dataset in
the form’s OnCreate event handler.
} 
procedure TForm1.FormCreate(Sender: TObject);
begin
  with CDS2 do
  begin
    with FieldDefs.AddFieldDef do
    begin
      DataType := ftInteger;
      Name := 'Field1';
    end;
    with FieldDefs.AddFieldDef do
    begin
      DataType := ftString;
      Size := 10;
      Name := 'Field2';
    end;
    with IndexDefs.AddIndexDef do
    begin
      Fields := 'Field1';
      Name := 'IntIndex';
    end;
    CreateDataSet;
  end;
end; 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!