RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDateTimeField.Create Constructor

Creates and initializes a TDateTimeField object.

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

Most applications do not explicitly create instances of TDateTimeField. 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 ftDateTime. 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 TDateTimeField. After instantiating a TDateTimeField, associate it with a specific field by setting its FieldName property to the name of the field. Give the TDateTimeField 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 TDateTimeField with a dataset component by setting its DataSet property to the name of the dataset component. Optionally set the DisplayFormat property to the desired date and time format. 

The example below creates a TDateTimeField object for a field named CheckOut accessed through a TClientDataSet named ClientDataSet1.

var
  T: TDateTimeField;
begin
  ClientDataSet1.Close;
  T := TDateTimeField.Create(ClientDataSet1);
  T.FieldName := 'CheckOut';
  T.Name := ClientDataSet1.Name + T.FieldName;
  T.Index := ClientDataSet1.FieldCount;
  T.DataSet := ClientDataSet1;
  T.DisplayFormat := 'mm/dd/yyyy hh:nn:ss ampm';
  ClientDataSet1.FieldDefs.UpDate;
  ClientDataSet1.Open;
end;

 

ClientDataSet1->Close();
TDateTimeField *T = new TDateTimeField(ClientDataSet1);
T->FieldName = "CheckOut";
T->Name = ClientDataSet1->Name + T->FieldName;
T->Index = ClientDataSet1->FieldCount;
T->DataSet = ClientDataSet1;
T->DisplayFormat = "mm//dd//yyyy hh:nn:ss ampm";
ClientDataSet1->FieldDefs->UpDate();
ClientDataSet1->Open();

 

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