RAD Studio VCL Reference
|
Specifies the name of the database entity defined by the TNamedItem object.
property Name: string;
__property AnsiString Name;
Use Name to specify the name that the underlying database table uses to refer to the defined object. For example, if the TNamedItem object is a field definition, the value of Name is the name of the corresponding field in the underlying database table.
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(); }
/* This example uses the IndexName property to sort the records in a client dataset on the Field2 field. */ void __fastcall TForm1::Button3Click(TObject *Sender) { // If Active is True, Update will remove Fields added in FormCreate // and add the DEFAULT_ORDER and CHANGEINDEX Fields CDS2->Active = False; // Get the current available indices CDS2->IndexDefs->Update(); // Find a field named "Field2" for (int I = 0; I < CDS2->IndexDefs->Count; I++) if (CDS2->IndexDefs->Items[I]->Fields == "Field2") { // set that index as the current index for the dataset} CDS2->IndexName = CDS2->IndexDefs->Items[I]->Name; } CDS2->Active = True; }
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;
{ This example uses the IndexName property to sort the records in a client dataset on the Field2 field. } procedure TForm1.Button3Click(Sender: TObject); var I : Integer; begin // If Active is True, Update will remove Fields added in FormCreate // and add the DEFAULT_ORDER and CHANGEINDEX Fields CDS2.Active := False; { Get the current available indices } CDS2.IndexDefs.Update; { Find a field named 'Field2' } for I := 0 to CDS2.IndexDefs.Count - 1 do if CDS2.IndexDefs.Items[I].Fields = 'Field2' then begin { set that index as the current index for the dataset} CDS2.IndexName := CDS2.IndexDefs.Items[I].Name; end; CDS2.Active := True; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|