TurboDB VCL Component Library



Previous  Top  Next

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

Delphi syntax:

function Add(const Name: String; DataTypeTdb: TTdbDataType; Size: Integer = 0; Required: Boolean = False; const Specification: string = ''): TTdbFieldDef;

C++ syntax:

TTdbFieldDef* __fastcall Add(const AnsiString Name, TTdbDataType DataTypeTdb, int Size = 0, Boolean Required = false, const AnsiString Specification);


Use Add to add a new TdbFieldDef to the list of field definitions. Add returns a reference to the new TTdbFieldDef object within the list.

Add uses the values passed in the Name, DataType, Size, Required and Specification parameters and assigns them to the respective properties of the new field definition object.

If a field definition with same name already exists, an EDatabaseError exception is raised.


The following code clears the FieldDefsTdb list and adds three fields for altering the table:

// Clear the field definition list
// Add a string field called name 40 characters long
TdbTable1.FieldDefsTdb.Add('Name', dtString, 40);
{ Add an enumeration field that has the enumeration values "Sales", "Marketing", "Development" }
with TdbTable1.FieldDefsTdb.Add('Department', dtEnum) do Specification := 'Sales,Marketing,Development';
{ Add an auto-incrementing field used as a record id. References to records of this table via this auto-incrementing field are displayed as the Name of the person. }
with TdbTable1.FieldDefsTdb.Add('RecordId', dtAutoInc) do Specification := 'Name';
// The table is restructured to reflect the new field definitions

See also