procedure AddPasswordToTable(Tbl: TTable; Password: String);
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);
Tbl.DisableControls;
Tbl.Close;
Check(DbiOpenDatabase(nil, nil, dbiReadWrite, dbiOpenExcl, nil, 0, nil, nil, hDb));
Check(DbiSetDirectory(hDb, PChar(Dir)));
TblDesc.iValChkCount := NumVChks;
TblDesc.pVChkDesc := VChk;
OpType := crMODIFY;
TblDesc.pecrValChkOp := @OpType;
StrPCopy(TblDesc.szTblName, Tbl.TableName);
StrCopy(TblDesc.szTblType, szParadox);
StrPCopy(TblDesc.szPassword, Password);
TblDesc.bProtected := Password <> '';
Check(DbiDoRestructure(hDb, 1, @TblDesc, nil, nil, nil, False));
finally
Check(DbiCloseDatabase(hDb));
FreeMem(VChk, sizeof(VChkDesc));
Session.AddPassword(Password);
Tbl.EnableControls;
Tbl.Open;
end;
end;