procedure fDbiDoRestructure(Tbl: TTable;
Field: TField;
MinVal, MaxVal, DefVal: pLongint;
Required: Bool);
var
hDb: hDbiDb;
TblDesc: CRTblDesc;
VChk: pVChkDesc;
Dir: String;
NumVChks: Word;
OpType: CROpType;
begin
NumVChks := 0;
SetLength(Dir, dbiMaxNameLen + 1);
Check(DbiGetDirectory(Tbl.DBHandle, False, PChar(Dir)));
SetLength(Dir, StrLen(PChar(Dir)));
VChk := AllocMem(sizeof(VChkDesc));
try
FillChar(TblDesc, sizeof(CRTblDesc), #0);
VChk.iFldNum := Field.Index + 1;
Tbl.DisableControls;
Tbl.Close;
Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl, nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Dir)));
with VChk^do
begin
bRequired := Required;
if MinVal <> nil then
begin
Inc(NumVChks);
bHasMinVal := True;
move(MinVal^, aMinVal, sizeof(MinVal^));
end
else
bHasMinVal := False;
if MaxVal <> nil then
begin
Inc(NumVChks);
bHasMaxVal := True;
move(MaxVal^, aMaxVal, sizeof(MaxVal^));
end
else
bHasMaxVal := False;
if DefVal <> nil then
begin
Inc(NumVChks);
bHasDefVal := True;
move(DefVal^, aDefVal, sizeof(DefVal^));
end
else
bHasDefVal := False;
end;
TblDesc.iValChkCount := NumVChks;
TblDesc.pVChkDesc := VChk;
OpType := crADD;
TblDesc.pecrValChkOp := @OpType;
StrPCopy(TblDesc.szTblName, Tbl.TableName);
StrCopy(TblDesc.szTblType, szParadox);
Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
finally
Check(DbiCloseDatabase(hDb));
FreeMem(VChk, sizeof(VChkDesc));
Tbl.EnableControls;
Tbl.Open;
end;
end;