//先引用ADOX
procedure TForm1.Button1Click(Sender: TObject);
var
ACatalog:_Catalog;//定义为_Catalog的接口类型
ATable : _Table;
AKey : _Key;
sCon : String;
sKey : String;
i : Integer;
begin
//adKeyPrimary = $00000001;
//adKeyForeign = $00000002;
//adKeyUnique = $00000003;
try
sCon := ADOCn1.ConnectionString;
ACatalog := CreateComObject(Class_Catalog) as _Catalog;
ACatalog._Set_ActiveConnection(sCon);
ATable := ACatalog.Tables.Get_Item('t1'); //t1是表名称
for i := 0 to ATable.Keys.Count - 1 do
begin
AKey := ATable.Keys.Item;
if AKey.Type_ = adKeyPrimary then
ShowMessage(AKey.Name + ' -- 是主键!')
else
ShowMessage(AKey.Name + ' -- 不是!');
end;
except
//忽略
end;
end;
看一看office中的Ado210.chm,里面有详细的说明。