Author: Tomas Rutkauskas
Assign a password to a Paradox table
Answer:
To assign a password to a Paradox table, use the following unit and call function
TablePasswort like this:
1 uses Unit2;
2 // ..
3 TablePasswort(Table1, 'secret');
4
5 unit Unit2;
6
7 interface
8
9 uses
10 BDE, SysUtils, DBTables, Windows;
11
12 function TablePasswort(var table: TTable; password: string): Boolean;
13
14 implementation
15
16 function StrToOem(const AnsiStr: string): string;
17 begin
18 SetLength(result, Length(AnsiStr));
19 if Length(result) > 0 then
20 CharToOem(PChar(AnsiStr), PChar(result))
21 end;
22
23 function TablePasswort(var table: ttable; password: string): Boolean;
24 var
25 pTblDesc: pCRTblDesc;
26 hDb: hDBIDb;
27 begin
28 result := false;
29 with table do
30 begin
31 if Active and (not Exclusive) then
32 Close;
33 if (not Exclusive) then
34 Exclusive := true;
35 if (not Active) then
36 Open;
37 hDb := DBHandle;
38 Close
39 end;
40 GetMem(pTblDesc, sizeof(CRTblDesc));
41 FillChar(pTblDesc^, sizeof(CRTblDesc), 0);
42 with pTblDesc^ do
43 begin
44 StrPCopy(szTblName, StrToOem(table.tablename));
45 szTblType := szParadox;
46 StrPCopy(szPassword, StrToOem(password));
47 bPack := true;
48 bProtected := true
49 end;
50 if DbiDoRestructure(hDb, 1, pTblDesc, nil, nil, nil, false) <> DBIERR_NONE then
51 exit;
52 if pTblDesc <> nil then
53 FreeMem(pTblDesc, sizeof(CRTblDesc));
54 result := true
55 end;
56
57 end.
|