RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TStringField.Create Constructor

Creates an instance of a TStringField object.

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

Most applications do not explicitly create instances of TStringField. 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 ftString, Size to 20, and Transliterate to true. 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 TStringField. After instantiating a TStringField, associate it with a specific field by setting its FieldName property to the name of the field. Give the TStringField 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 TStringField with a dataset component by setting its DataSet property. 

The example below creates a TStringField object for a field named LastName accessed through a TSQLDataSet named SQLDataSet1.

var
  T: TStringField;
begin
  SQLDataSet1.Close;
  T := TStringField.Create(SQLDataSet1);
  T.FieldName := 'LastName';
  T.Name := SQLDataSet1.Name + T.FieldName;
  T.Index := SQLDataSet1.FieldCount;
  T.DataSet := SQLDataSet1;
  SQLDataSet1.FieldDefs.UpDate;
  SQLDataSet1.Open;
end;

 

SQLDataSet1->Close();
TStringField *T = new TStringField(SQLDataSet1);
T->FieldName = "LastName";
T->Name = SQLDataSet1->Name + T->FieldName;
T->Index = SQLDataSet1->FieldCount;
T->DataSet = SQLDataSet1;
SQLDataSet1->FieldDefs->UpDate();
SQLDataSet1->Open();

 

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