Data.DB.TDateField.Create

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

constructor Create(AOwner: TComponent); override;

C++

__fastcall virtual TDateField(System::Classes::TComponent* AOwner);

Properties

Type Visibility Source Unit Parent
constructor public
Data.DB.pas
Data.DB.hpp
Data.DB TDateField

Description

Creates an instance of TDateField.

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

The example below creates a TDateField object for a field named LastContact accessed through a TClientDataSet named ClientDataSet1.



var
T: TDateField;
begin
ClientDataSet1.Close;
T := TDateField.Create(ClientDataSet1);
T.FieldName := 'LastContact';
T.Name := ClientDataSet1.Name + T.FieldName;
T.Index := ClientDataSet1.FieldCount;
T.DataSet := ClientDataSet1;
T.DisplayFormat := 'mm/dd/yyyy';
ClientDataSet1.FieldDefs.UpDate;
ClientDataSet1.Open;
end;



ClientDataSet1->Close();
TDateField *T = new TDateField(ClientDataSet1);
T->FieldName = "LastContact";
T->Name = ClientDataSet1->Name + T->FieldName;
T->Index = ClientDataSet1->FieldCount;
T->DataSet = ClientDataSet1;
T->DisplayFormat = "mm//dd//yyyy";
ClientDataSet1->FieldDefs->UpDate();
ClientDataSet1->Open();



See Also