RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TVariantField.Create Constructor

Creates and initializes a variant field component.

Pascal
constructor Create(AOwner: TComponent); override;
C++
virtual __fastcall TVariantField(TComponent * AOwner);

Most applications do not explicitly create instances of TVariantField. Instead, the field components are created automatically, as persistent field components defined in the Fields editor at design time or as dynamic field components created automatically by the dataset. 

Create sets the DataType property to ftVariant. The AOwner parameter specifies the component, typically a dataset, that becomes the new field's Owner. The Owner is responsible for freeing the component. 

In the rare cases when you must create a persistent field component at runtime, call Create to create and initialize an instance of TVariantField. After instantiating a TVariantField, associate it with a specific field by setting its FieldName property to the name of the field. Give the TVariantField a unique identifier in the Name property. Establish where the field appears in the collection of fields by providing an ordinal number in the Index property. Associate the TVariantField with a dataset component by setting its DataSet property to the name of the dataset component. 

The example below creates a TInterfaceField object for a field named UnknownData accessed through a TQuery named Query1.  

var
  T: TInterfaceField;
begin
  Query1.Close;
  T := TInterfaceField.Create(Query1);
  T.FieldName := 'UnknownData';
  T.Name := Query1.Name + T.FieldName;
  T.Index := Query1.FieldCount;
  T.DataSet := Query1;
  Query1.FieldDefs.UpDate;
  Query1.Open;
end;

 

Query1->Close();
TInterfaceField *T = new TInterfaceField(Query1);
T->FieldName = "UnknownData";
T->Name = Query1->Name + T->FieldName;
T->Index = Query1->FieldCount;
T->DataSet = Query1;
Query1->FieldDefs->UpDate();
Query1->Open();

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!