delphi 取得数据库表的字段名称与字段类型

工作需要取得数据库中字段的名称

最后经过一番努力找到了如下的方法

 

procedure TForm1.Button1Click(Sender: TObject);

const

MyFielddefs: array[ftUnknown..ftTypedBinary] of string [11] =

(‘Unknown’, ‘String’, ‘Smallint’, ‘Integer’,

‘Word’, ‘Boolean’, ‘Float’, ‘Currency’, ‘BCD’,

‘Date’, ‘Time’, ‘DateTime’, ‘Bytes’, ‘VarBytes’,

‘AutoInc’, ‘Blob’, ‘Memo’, ‘Graphic’, ‘FmtMemo’,

‘ParadoxOle’, ‘DBaseOle’, ‘TypedBinary’);

 

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;

最后把库的字段名称添加到Listbox1中显示出来

 » 本站地址:http://www.gomoth.com

标签: