FireDAC.TFDGUIxLoginDialog Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample describes how to use TFDGUIxLoginDialog in FireDAC GUI applications to allow users to enter their database credentials to connect to a DBMS. The same component also allows users to manage their passwords.

The sample connects to a database using a TFDConnection.

Location

You can find the TFDGUIxLoginDialog sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
    • Object Pascal\DataBase\FireDAC\Samples\Comp Layer\TFDGUIxLoginDialog\Main.
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

This sample uses the Use Connection Definition drop-down menu to select a connection definition. If the database requires login credentials and the Login prompt check-box is selected, the FireDAC Login window appears where the user can input the User name, Password and other optional parameters. The set of parameters depends on the database type. The Profile combo-box allows choosing one of the previously successfully used credentials.

How to Use the Sample

  1. Navigate to the location given above and open:
    • Delphi: LoginDialog.dproj
  2. Press F9 or choose Run > Run.
  3. Select a connection definition from the Use Connection Definition drop-down menu.
  4. Click Connect to connect to the database.
  5. The FireDAC Login appears, allowing to input the login credentials.
  6. Click Disconnect to disconnect from the database.

Implementation

This project uses the dmMainComp unit where the TFDGUIxLoginDialog component is placed.

Use Connection Definition

The menu shows all the connections defined on the file at C:\Users\Public\Documents\Embarcadero\Studio\FireDAC\FDConnectionsDefs.ini.

The connection to the database is established using a TFDConnection component placed at the dmMainComp unit. It uses the LoginDialog property from the TFDConnection to select the TFDGUIxLoginDialog component.

If the Login prompt of the main form is checked then it checks the LoginPrompt option from the TFDConnection to show the FireDAC Login window when trying to connect to the database.

When selecting the connection, it updates the TFDGUIxLoginDialog properties with the values selected for the options on the FireDAC Login Dialog properties TPanel.

Connect

It updates the TFDGUIxLoginDialog properties with the values selected for the options on the FireDAC Login Dialog properties TPanel.

Opens the connection to the database by setting to True the Connected property for the TFDConnection.

Disconnect

Closes the connection to the database by setting to False the Connected property for the TFDConnection.

FireDAC Login Dialog properties

Values by default for the TFDGUIxLoginDialog properties:

ChangeExpiredPassword: True.

  • It allows the user to change an expired password.

HistoryEnabled: True

  • It allows the login history storage.

HistoryWithPassword: True

  • It allows the password storage in the login history.

LoginRetries: 3

  • Specifies the number of allowed login tries for the user. An exception is raised when the defined number is reached.

VisibleItems: Database, User_Name and Password

  • Specifies the fields shown on the FireDAC Login window. You can also set the name to be shown. For example Database = My Database Connection .

Uses

See Also