EPUB | CHM | PDF

TMySQLDatabase.Events.OnLogin

Top Previous Next

Occurs when an application connects to a database.

Syntax:

type
   TMySQLDataBaseLoginEvent = procedure(Database: TMySQLDataBase;
                                     LoginParams: TStrings)of object;
property OnLogin: TMySQLDataBaseLoginEvent;

Description:

Write an OnLogin event handler to take specific actions when an application attempts to connect to a database. By default, a database login is required. The current USERNAME is read from the Params property, and a standard Login dialog box opens. The dialog prompts for a user name and password combination, and then uses the values entered by the user to set the UID and PWD values in the Params property. These values are then passed to the remote server.

Applications that provide alternative OnLogin event handlers must set the UID and PWD values in LoginParams. LoginParams is a temporary string list and is freed automatically when no longer needed.

This event handler is called only if LoginPrompt property value is True.

Example:

procedure TForm1.mySQLDatabase1Login(Database: TMySQLDatabase; LoginParams: TStrings);
var
  vUserName, vPassword : string;
begin
  vUserName := 'root';           //most probably you want to ask user for user name and password
  vPassword := 'strongpassword'; //with some GUI instead of just assigning it here
  LoginParams.Add('UID=' + vUserName);
  LoginParams.Add('PWD=' + vPassword);
end;

note Another way to ask user for username and password is to call ConnectWithConnectionOptionsDialog method

See also: LoginPrompt property, ConnectWithConnectionOptionsDialog method