A: This project demonstrates listing the field structure from a given table, using the Fields and IndexDefs arrays.
Noel Rice
Borland Technical Support
Note: This code works with 16 bit only.
procedure TForm1.Button1Click(Sender: TObject);
const
MyFielddefs: array[ftUnknown..ftGraphic] of string = ('ftUnknown',
'ftString', 'ftSmallint', 'ftInteger', 'ftWord', 'ftBoolean', 'ftFloat',
'ftCurrency', 'ftBCD', 'ftDate', 'ftTime', 'ftDateTime', 'ftBytes', 'ftVarBytes',
'ftBlob', 'ftMemo', 'ftGraphic');
var
i, Indx: integer;
Definition: string;
begin
for i := 0 to Table1.FieldCount - 1 do begin
Definition := Table1.Fields[i].DisplayLabel;
Definition := Definition + ' ' + MyFieldDefs[Table1.Fields[i].DataType];
Table1.IndexDefs.Update;
if Table1.Fields[i].IsIndexField then begin
Indx := Table1.IndexDefs.Indexof(Table1.Fields[i].Name);
if Indx > -1 then
if ixPrimary in Table1.IndexDefs[Indx].Options
then
Definition :=
Definition + ' (Primary)';
end;
Listbox1.Items.Add(Definition);
end;
end;
Here is a version that works with the 32 bit version (by Lloyd):
procedure TForm1.Button1Click(Sender: TObject);
const
MyFielddefs: array[ftUnknown..ftTypedBinary] of string =
('ftUnknown', 'ftString', 'ftSmallint', 'ftInteger',
'ftWord',
'ftBoolean', 'ftFloat', 'ftCurrency', 'ftBCD', 'ftDate',
'ftTime',
'ftDateTime', 'ftBytes', 'ftVarBytes', 'ftAutoInc',
'ftBlob', 'ftMemo',
'ftGraphic', 'ftFmtMemo', 'ftParadoxOle', 'ftDBaseOle',
'ftTypedBinary');
var
i, Indx: integer;
Definition: string;
begin
for i := 0 to Table1.FieldCount - 1 do begin
Definition := Table1.Fields[i].DisplayLabel;
Definition := Definition + ' ' + MyFieldDefs[Table1.Fields[i].DataType];
Table1.IndexDefs.Update;
if Table1.Fields[i].IsIndexField then begin
Indx := Table1.IndexDefs.Indexof(Table1.Fields[i].Name);
if Indx > -1 then
if ixPrimary in Table1.IndexDefs[Indx].Options
then
Definition :=
Definition + ' (Primary)';
end;
Listbox1.Items.Add(Definition);
end;
end;