The code below displays how I'm currently making new database (.dbf) tabes to use and display in my TDBGrid.
It creates tables for me, however I don't understand the lower section concerning IndexDefs, where I'm supposed to describe indexes. I found this code in Delphi's Help and have modified it as best I could, so it would work.
Could someone please give me the gist on what indexes are for (are they used to uniquely identify specific rows in the table I create?), what problems may arise from not having them, and how (if needed) I may create the indexes to ensure corrupt tables are not created from not having them? Any help would be appreciated.
Thanks,
cold25
with Table1 do begin
Active := False;
DatabaseName := 'DBDEMOS';
TableType := ttDBase;
Table1.TableName := newName;
{ 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 := 'FeatNum';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'CODE';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'ABC';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'DEF';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'GHI';
DataType := ftInteger;
end;
end; //end of with FieldDefs do begin
{ Next, describe any indexes }
with IndexDefs do begin
Clear;
{ The 1st index has no name because it is
{ a Paradox primary key }//I'm not working with paradox, this was a comment left from Delphi's example.
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 of if not Table1.Exists then begin
end; //end of with Table1 do begin
It creates tables for me, however I don't understand the lower section concerning IndexDefs, where I'm supposed to describe indexes. I found this code in Delphi's Help and have modified it as best I could, so it would work.
Could someone please give me the gist on what indexes are for (are they used to uniquely identify specific rows in the table I create?), what problems may arise from not having them, and how (if needed) I may create the indexes to ensure corrupt tables are not created from not having them? Any help would be appreciated.
Thanks,
cold25
with Table1 do begin
Active := False;
DatabaseName := 'DBDEMOS';
TableType := ttDBase;
Table1.TableName := newName;
{ 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 := 'FeatNum';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'CODE';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'ABC';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'DEF';
DataType := ftString;
Size := 10;
end;
with AddFieldDef do begin
Name := 'GHI';
DataType := ftInteger;
end;
end; //end of with FieldDefs do begin
{ Next, describe any indexes }
with IndexDefs do begin
Clear;
{ The 1st index has no name because it is
{ a Paradox primary key }//I'm not working with paradox, this was a comment left from Delphi's example.
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 of if not Table1.Exists then begin
end; //end of with Table1 do begin