User:Loredanac/ODBCPostgreSQL Sample

From RAD Studio
Jump to: navigation, search

This sample uses dbExpress and LiveBindings components to get data from an ODBC connection.

Note: To run this sample you need to have installed the ODBC PostgreSQL driver. The applications compiled as 32-bit, require the 32-bit ODBC driver and the 64-bit applications require the 64-bit ODBC driver.

Location

You can find the ODBCPostgreSQL sample project at:

Description

This sample gets the data from an ODBC database.

You can post new records using the Insert button of the TBindNavigator component. Enter the Country and the Currency values into the TEdit fields and click the Post button. The data is accessed using components as: TSQLConnection, TSimpleDataSet, or TStringGrid.

How to Use the Sample

  1. Navigate to Start > Programs > Embarcadero RAD Studio XE5 > Samples > Delphi > Database > dbExpress > ODBCPostgreSQL and open Fmi_dbExpress_ODBC.dproj.
  2. Go to the Data Explorer.
  3. Right click the OdbcConnection.
  4. Click the Modify option.
  5. In the Modify Connection window, set the Database, User name, and Password properties as you have provide them during the driver installation.
    OdbcConnectionModifyWindow.png
  6. Click the OK button.
  7. Right click the OdbcConnection.
  8. Select the SQL Window.
  9. Copy and paste the script.sql content from the sample directory.
    SQLWindow.png
  10. Click the Execute SQL button.
  11. Click the TSQLConnection component from the project form.
  12. Set the Connected property as true.
  13. Click the TSimpleDataSet component.
  14. Set the Active property as true.
  15. Press F9 or choose Run > Run.

Files

File Contains

MainForm

Contains the base form.

Fmi_dbExpress_ODBC

The project itself.

Classes

TForm1 is the form of the application. This class contains objects as: TSQLConnection, TBindingsList, TStyleBook, TRectangle, or TShadowEffect.

Implementation

  • Form1 has the StyleBook property set as StyleBook1. This makes that the backgroundstyle or colorbuttonstyle of TStringGrid or TRectangle components to change.
  • Rectangle2 is the parent object of all the other visual components from the form.
  • BindScopeDB1 makes the necessary connections between country and currency fields and BindNavigator1, Edit1, Edit2, or StringGrid1 objects.

Uses

See Also