uses ComObj;
function IsPrimary(const DBName, TableName, FieldName: WideString): Boolean;
var
dbe, dbs, tdf, idx: OleVariant;
i, j: Integer;
begin
Result := False;
try
dbe := CreateOleObject('DAO.DBEngine.36');
dbs := dbe.OpenDatabase(DBName);
tdf := dbs.TableDefs[TableName];
for i := 0 to tdf.Indexes.Count - 1 do
if tdf.Indexes.Primary then
begin
idx := tdf.Indexes;
for j := 0 to idx.Fields.Count - 1 do
if idx.Fields[j].Name = FieldName then
begin
Result := True;
Break;
end;
Break;
end;
finally
if not VarIsEmpty(dbs) then dbs.Close;
idx := Unassigned;
tdf := Unassigned;
dbs := Unassigned;
dbe := Unassigned;
end;
end;