Mirror

Add a password to several Paradox tables in one step (Views: 100)


Problem/Question/Abstract:

How to add a password to several Paradox tables in one step

Answer:

procedure BDEProtectTable(ATable: TTable; const APassword: string);
var
  CurPrp: CURProps;
  hDB: hDBIdb;
  TableDesc: CRTblDesc;
  DoEncrypt: boolean;
  bExcl, bOpen: boolean;
begin
  Check(DBIGetCursorProps(ATable.Handle, CurPrp));
  DoEncrypt := (APassword > '');
  with ATable do
  begin
    bOpen := Active;
    bExcl := Exclusive;
    if Active and not Exclusive then
      Close;
    if not Exclusive then
      Exclusive := True;
    if not Active then
      Open;
    {supply nulls (=default) for every optional parameter:}
    FillChar(TableDesc, SizeOf(CRTblDesc), 0);
    {supply indispensable parameters:}
    AnsiToNative(DBLocale, TableName, TableDesc.szTblName, DBIMAXTBLNAMELEN - 1);
    TableDesc.szTblType := CurPrp.szTableType;
    {supply parameters for our action here:}
    AnsiToNative(DBLocale, APassword, TableDesc.szPassword, 255);
    TableDesc.bProtected := DoEncrypt; {supply False to decrypt}
    hDB := DBHandle;
    Close;
    {do the restructure:}
    try
      Check(DBIDoRestructure(hDB, 1, @TableDesc, nil, nil, nil, False));
    finally
      Exclusive := bExcl;
      Active := bOpen;
    end;
  end;
end;

<< Back to main page