Author: Jonas Bilinkevicius
How to add a password to several Paradox tables in one step
Answer:
1
2 procedure BDEProtectTable(ATable: TTable; const APassword: string);
3 var
4 CurPrp: CURProps;
5 hDB: hDBIdb;
6 TableDesc: CRTblDesc;
7 DoEncrypt: boolean;
8 bExcl, bOpen: boolean;
9 begin
10 Check(DBIGetCursorProps(ATable.Handle, CurPrp));
11 DoEncrypt := (APassword > '');
12 with ATable do
13 begin
14 bOpen := Active;
15 bExcl := Exclusive;
16 if Active and not Exclusive then
17 Close;
18 if not Exclusive then
19 Exclusive := True;
20 if not Active then
21 Open;
22 {supply nulls (=default) for every optional parameter:}
23 FillChar(TableDesc, SizeOf(CRTblDesc), 0);
24 {supply indispensable parameters:}
25 AnsiToNative(DBLocale, TableName, TableDesc.szTblName, DBIMAXTBLNAMELEN - 1);
26 TableDesc.szTblType := CurPrp.szTableType;
27 {supply parameters for our action here:}
28 AnsiToNative(DBLocale, APassword, TableDesc.szPassword, 255);
29 TableDesc.bProtected := DoEncrypt; {supply False to decrypt}
30 hDB := DBHandle;
31 Close;
32 {do the restructure:}
33 try
34 Check(DBIDoRestructure(hDB, 1, @TableDesc, nil, nil, nil, False));
35 finally
36 Exclusive := bExcl;
37 Active := bOpen;
38 end;
39 end;
40 end;
|