RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TIndexDef.Options Property

Describes the characteristics of the index.

Pascal
property Options: TIndexOptions;
C++
__property TIndexOptions Options;

When creating a new index, use Options to specify the attributes of the index. Options can contain zero or more of the TIndexOption constants ixPrimary, ixUnique, ixDescending, ixCaseInsensitive, and ixExpression. 

When inspecting the definitions of existing indexes, read Options to determine the option(s) used to create the index.

Note: Different database drivers may support only a subset of these options. For example, with dBASE tables, ixCaseInsensitive is not supported. Including an option that is not valid for a table will raise an exception.
Note: Primary indexes are, by definition unique. If setting the Options value ixPrimary, you need not also use ixUnique.
 

C++ Examples: 

 

/*
The following example shows how to create a table.
*/

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Table1 = new TTable(Form1);
  Table1->Active = false; // The Table component must not be active
  Table1->DatabaseName = "DBDEMOS";
  Table1->TableType = ttParadox;
  Table1->TableName = "CustInfo";
  if (Table1->Exists)
    MessageDlg("CustInfo table already exists.", mtWarning, TMsgDlgButtons() << mbOK, 0);
  else // Don't overwrite an existing table
  {
    // describe the fields in the table
    Table1->FieldDefs->Clear();
    TFieldDef *newDef = Table1->FieldDefs->AddFieldDef();
    newDef->Name = "Field1";
    newDef->DataType = ftInteger;
    newDef->Required = true;
    newDef = Table1->FieldDefs->AddFieldDef();
    newDef->Name = "Field2";
    newDef->DataType = ftString;
    newDef->Size = 30;
    // Next, describe any indexes
    Table1->IndexDefs->Clear();
    /* the 1st index has no name because it is a Paradox primary key */
    Table1->IndexDefs->Add("","Field1", TIndexOptions() <<ixPrimary << ixUnique);
    Table1->IndexDefs->Add("Fld2Index", "Field2", TIndexOptions() << ixCaseInsensitive);
    // Now that we have specified what we want, create the table
    Table1->CreateTable();
    Table1->Active = True;
    for (int i = 1; i <= 20; i++)
      Table1->AppendRecord(ARRAYOFCONST((i*111, i*222)));
  }
  DS2->DataSet = Table1;
  DBGrid2->DataSource->DataSet = Table1;
  Table1->Active = True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Table1->Close();
  Table1->DeleteTable();
}

 

Delphi Examples: 

{ The following example shows how to create a table. }
procedure TForm1.Button1Click(Sender: TObject);
begin
  Table1.Close;
  Table1.DeleteTable;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
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 Table1.Exists then
      MessageDlg('CustInfo table already exists.', mtWarning, [mbOK], 0)
    else
    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;
      Table1.Active:= True;
      for i := 1 to 20 do
        Table1.AppendRecord([i*111, i*222]);
    end;
  end;
  DS2.DataSet:= Table1;
  DBGrid2.DataSource.DataSet:= Table1;
  Table1.Active:= True;
end;

 

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