.......
uses bde, StdCtrls, DB, DBTables;
........
function StrToOem(const AnsiStr: String) : String;
begin
SetLength(result, Length(AnsiStr));
if Length(result)>0 then
CharToOem(PChar(AnsiStr), PChar(result));
end;
procedure DbAddPassword(var table: ttable; password: String);
var
pTblDesc : pCRTblDesc;
hDb : hDBIDb;
begin
with Table do
begin
Close; Exclusive := true; Open; hDb := DBHandle; Close;
end;
GetMem(pTblDesc, sizeof(CRTblDesc));
FillChar(pTblDesc^, sizeof(CRTblDesc), 0);
with pTblDesc^ do
begin
StrPCopy(szTblName, StrToOem(table.tablename));
szTblType := szParadox;
StrPCopy(szPassword, StrToOem(password));
bPack := true;
bProtected := true;
end;
if DbiDoRestructure(hDb, 1, pTblDesc, nil, nil, nil, false)<>DBIERR_NONE then
exit;
if pTblDesc<>nil then
FreeMem(pTblDesc, sizeof(CRTblDesc));
end;
procedure TForm1.Button1Click(Sender: TObject);
var tt: TTable;
ss: Tsession;
begin
ss:=Tsession.Create(self);
tt:=TTable.Create(self);
try
ss.SessionName:='MySession'; ss.AddPassword('OldPassWord');
tt.SessionName:='MySession'; tt.TableName:='c:/test/client.db';
DbAddPassword(tt,''); //清除密码
showmessage('搞定,自己测试一下!');
finally
ss.Free;
tt.Free;
end;
end;