Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Learn How To Create A Database Login Dialog In Delphi With The FireDAC.TFDGUIxLoginDialog Sample

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:

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 namePassword 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:

ChangeExpiredPasswordTrue.

HistoryEnabledTrue

HistoryWithPasswordTrue

LoginRetries3

VisibleItemsDatabase, User_Name and Password

If you want to ti visit the original Embarcadero post, refer to the link below:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDGUIxLoginDialog_Sample

Exit mobile version