RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDataSet.Fields Property

Lists all non-aggregate field components of the dataset.

Pascal
property Fields: TFields;
C++
__property TFields Fields;

Use Fields to access field components. If fields are generated dynamically at runtime, the order of field components in Fields corresponds directly to the order of columns in the table or tables underlying a dataset. If a dataset uses persistent fields, then the order of field components corresponds to the ordering of fields specified in the Fields editor at design time. 

When ObjectView is true, the fields are stored hierarchically, meaning any child fields of an object field are referenced by the object field and don't appear sequentially after the object field in the TFields . :: Fields array. When ObjectView is false, the fields are stored sequentially, or flattened out, meaning any child fields of an object field are stored sequentially in the TFields . :: Fields array. 

Accessing fields with the Fields property is useful for applications that: 

Iterate over some or all fields in a dataset. 

Work with underlying tables whose internal data structure is unknown at runtime. 

If an application knows the data types of individual fields, then it can read or write individual field values through the Fields property. For example, the following statement assigns a field value to the Text property of an edit box:

Edit1.Text := CustTable.Fields.Fields[6].AsString;

 

Edit1->Text = CustTable->Fields->Fields[0]->AsString;

Note: The preferred method for retrieving and assigning field values is to use persistent fields or the FieldByName method.
Note: The AggFields property is a collection of all the dataset's aggregated fields. AggFields and Fields are mutually exclusive collections of the dataset's fields. These two properties contain all of the dataset's fields between them.
 

Delphi Examples: 

 

{
This example displays a message box with the names of all
fields in a table.
}
procedure TForm1.Button1Click(Sender: TObject);
var
   i: Integer;
   Info: String;
begin
   Info := 'The fields of table ' + Table1.TableName +
           ' are:'#13#10#13#10;
   for i := 0 to Table1.FieldCount - 1 do
      Info := Info + Table1.Fields[i].FieldName + #13#10;
  ShowMessage(Info);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Table1:= TTable.Create(Form1);
  with Table1 do
  begin
    DatabaseName := 'DBDEMOS';
    TableType := ttParadox;
    TableName := 'CustInfo';
    Table1.Active := False;
    { Don't overwrite an existing table }
    if not Table1.Exists then
    begin
      { The Table component must not be active }
      { First, describe the type of table and give }
      { it a name }
      { Next, describe the fields in the table }
      with FieldDefs do
      begin
        Clear;
        with AddFieldDef do
        begin
          Name := 'Field1';
          DataType := ftInteger;
          Required := True;
        end;
        with AddFieldDef do
        begin
          Name := 'Field2';
          DataType := ftString;
          Size := 30;
        end;
      end;
      { Next, describe any indexes }
      with IndexDefs do
      begin
        Clear;
        { The 1st index has no name because it is
        { a Paradox primary key }
        with AddIndexDef do
        begin
          Name := '';
          Fields := 'Field1';
          Options := [ixPrimary];
        end;
        with AddIndexDef do
        begin
          Name := 'Fld2Indx';
          Fields := 'Field2';
          Options := [ixCaseInsensitive];
        end;
      end;
      { Call the CreateTable method to create the table }
      CreateTable;
    end;
  end;
  DS2.DataSet:= Table1;
  DBGrid2.DataSource.DataSet:= Table1;
  Table1.Active:= True;
end;

 

FieldByName 

Edit 

Post 

TEdit 

FieldList 

AggFields 

FieldDefs 

FieldCount 

Executing a Search with Goto Methods 

Modifying a Range 

Specifying Ranges 

Accessing Field Values with a Dataset's Fields Property 

Working with Reference Fields

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