Build a Simple VCL Application for USPS Data

How to build a simple VCL Application to view USPS data in RAD Studio using the CData FireDAC Components for USPS.

Embarcadero RAD Studio provides a development environment for Delphi and C++Builder applications. With the CData FireDAC Components for USPS, you gain access to live USPS data within RAD Studio, abstracting the data into tables, views, and stored procedures that can be used to retrieve and update USPS data. This article will walk through connecting to USPS and creating a simple VCL application with the Form Designer.

Creating a VCL Application for USPS Data

The following instructions show how to use the Form Designer to create a simple VCL Forms application that shows the basic FireDAC objects needed to connect to USPS from any application.

The following example populates a TDBGrid control.

  1. Create a new VCL Forms Application.
  2. Drop a TFDPhysUSPSDriverLink and TFDConnection object onto the form.
  3. Double-click the TFDConnection object. The FireDAC Connection Editor is displayed. Select "CData.USPS" in the DriverId menu and configure the connection properties.

    To authenticate with USPS, set the following connection properties.

    • PostageProvider: The postage provider to use to process requests. Available options are ENDICIA and STAMPS. If unspecified, this property will default to ENDICIA.
    • UseSandbox: This controls whether live or test requests are sent to the production or sandbox servers. If set to true, the Password, AccountNumber, and StampsUserId properties are ignored.
    • StampsUserId: This value is used for logging into authentication to the Stamps servers. This value is not applicable for Endicia and is optional if UseSandbox is true.
    • Password: This value is used for logging into Endicia and Stamps servers. If the postage provider is Endicia, this will be the pass phrase associated with your postage account. It is optional if UseSandbox is true.
    • AccountNumber: The shipper's account number. It is optional if UseSandbox is true.
    • PrintLabelLocation: This property is required to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

    The Cache Database

    Many of the useful task available from USPS require a lot of data. To ensure this data is easy to input and recall later, utilize a cache database to make requests. Set the cache connection properties in order to use the cache:

    • CacheLocation: The path to the cache location, for which a connection will be configured with the default cache provider. For example, C:\users\username\documents\uspscache

    As an alternative to CacheLocation, set the combination of CacheConnection and CacheProvider to configure a cache connection using a provider separate from the default.

  4. Drop a TFDQuery object onto the form and set the properties below:

    • Connection - Set this property to the TFDConnection object, if this object is not already specified.
    • SQL - Click the button in the SQL property and enter a query.
    • Active - Set this property to true.
  5. Drop a TDataSource object onto the form and set the following property:

    • DataSet - In the menu for this property, select the name of the TFDQuery object.
  6. Drop a TDBGrid control onto the form and set the following property:

    • DataSource - Select the name of the TDataSource.
  7. Drop a TFDGUIxWaitCursor onto the form. This is required to avoid a run-time error.

You now have an executable application that displays the results of the SQL Query set in the TFDQuery object.