TurboDB VCL Component Library

TTdbDatabase.OnPassword

TTdbDatabase

Previous  Top  Next

Occurs when an application attempts to open a protected TurboDB table for the first time.

Delphi syntax:

TTdbPasswordEvent = procedure(Sender: TObject; const TableName: string; var Key: WideString; var Retry: Boolean) of object;

property OnPassword: TTdbPasswordEvent;

C++ syntax:

typedef void __fastcall (__closure *TTdbPasswordEvent)(System::TObject* Sender, const AnsiString TableName, WideString &Key, bool &Retry);

__property TTdbPasswordEvent OnPassword = {read=FOnPassword, write=FOnPassword};

Description

Write an OnPassword event handler to take specific action when an application attempts to open a password-protected or encrypted TurboDB table for the first time. To gain access to the TurboDB table, the event handler must set the parameters to Key . Use Retry to conditionally finalize opening the table. If Retry is set to True, opening the table is tried with the new password provided in the arguments. If set to False, the attempt to open the table is abandoned.

Note

If an OnPassword event handler does not exist, but TurboDB reports insufficient access rights, an exception is raised.

Example

The following example shows a typical event handler and the source code for opening the table.

procedure TForm1.Password(Sender: TObject; const TableName: string; var Key: WideString; var Retry: Boolean);
begin
       Key := InputBox('Enter password', 'Password:', '');
       Retry := (Key > '');
end;

procedure TForm1.OpenTableBtnClick(Sender: TObject);
begin
       Database.OnPassword := Password;
       try
               Table1.Open;
       except
               if not Table1.Active then begin
                       ShowMessage('Could not open table');
                       Application.Terminate;
   end;
end;
end;