RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

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:

  • Start | Programs | Embarcadero RAD Studio Sydney | 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 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.

  • It allows the user to change an expired password.

HistoryEnabledTrue

  • It allows the login history storage.

HistoryWithPasswordTrue

  • It allows the password storage in the login history.

LoginRetries3

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

VisibleItemsDatabase, 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 .

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


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Deep Dive Webinar: Boost C++Builder Compile Speed with TwineCompile
Related posts
CodeDelphi

Quickly Build Enterprise-Grade Multi-Tier Solutions Using DataSnap In Delphi And C++

C++CodeDelphi

Easily Create A Python Container Type In Delphi And Execute It In This Windows Sample App

C++DelphiRAD Studio

Manual uninstall of RAD Studio/Delphi/C++Builder 10.4 Sydney

CodeDelphiRAD Studio

Learn How To Send Arrays To A PostgreSQL Database Server Using FireDAC In Delphi On Windows

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES