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

Learn To Populate A String List With Some Data From A Database With The FireDAC.GetFieldNames Delphi Sample

To this end, the sample uses the following methods of the TFDConnection component:

  • GetTableNames populates a string list with the names of tables in a database.
  • GetFieldNames populates a string list with the names of fields in a table.
  • GetKeyFieldNames populates a string list with the names of the key fields in a table.

Location

You can find the GetFieldNames sample project at:

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

How to Use the Sample

  1. Navigate to the location given above and open GetFieldNames.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select a database.
    • It populates the list box component labeled as Tables with the names of tables contained in this database.
    • The first item of the Tables list is automatically selected, which fills the list box components labeled as Fields and Key Fields.
    • Click on a different item of the Tables list to see the list of fields and key fields contained in the selected table.

Files

File in DelphiContains
GetFieldNames.dproj
GetFieldNames.dpr
The project itself.
fGetFieldNames.pas
fGetFieldNames.fmx
The main form.

Implementation

The sample implements the following database related features.

Define a connection to a database

To connect to a database, click on the combo box labeled as Use Connection Definition and choose a database.

Get the table names

The sample populates the list box named lbxTables with the name of the tables of the chosen database. The first item of the lbxTables list is automatically selected. To this end, the sample uses a OnClick event and the GetTableNames method. See the following code:

Get the field names

When you select an item (a table) of the lbxTables list box, the sample populates the list box named lbxFields with the fild names contained on the selected table. To do this, the sample use an OnClick event ant the GetFieldNames method. See the following code:

Get the key field names

When you select an item (a table) of the lbxTables list box, the sample populates the list box named lbxKeyFields with the key field names contained on the selected table. To do this, the sample use an OnClick event and the GetKeyFieldNames method. See the following code:

If you want to visit the original post, please visit the next link:

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


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

Related posts
DelphiShowcase

Powerful Petroleum And Mining Software For Surface And Subsurface Data Visualization Is Built In Delphi

C++CodeDelphiIDE

Quickly Log Python Script Output To The Delphi Debug Log In Your Windows Apps

CodeDelphiRAD Studio

Learn How To Use Connection Pooling With A Multi-threaded Environment In Delphi

CodeDelphi

Learn How To Build A REST API App For iOS In 45 Minutes With Delphi

Leave a Reply

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

IN THE ARTICLES