各製品の資料を入手。
詳細はこちら →Build a Simple VCL Application for WordPress データ
How to build a simple VCL Application to view WordPress データ in RAD Studio using the CData ODBC Driver for WordPress.
最終更新日:2023-06-12Embarcadero RAD Studio provides a development environment for Delphi and C++Builder applications. With the CData ODBC Driver for WordPress, you gain access to live WordPress データ within RAD Studio, abstracting the data into tables, views, and stored procedures that can be used to retrieve and update WordPress データ. This article will walk through connecting to WordPress and creating a simple VCL application with the Form Designer.
Create a Connection to WordPress データ
If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.
WordPress 接続プロパティの取得・設定方法
現時点では、CData JDBC Driver for WordPress はセルフホスト型のWordPress インスタンスへの接続のみをサポートしています。データに接続するには、Url を自身のwordpress サイトに指定し、次に以下に説明するように認証を行います。URL を完全な形式で記入します。例えば、あなたのサイトが'http://localhost/wp/wordpress' でホストされている場合、URL は'http://localhost' ではなく、'http://localhost/wp/wordpress' となるべきです。 URL を完全な形式で入力しないと、'site not found' というエラーが発生します。
WordPress は2種類の認証をサポートします。
- Basic 認証は、テスト環境での使用が推奨されます。
- OAuth 2.0 認証は、デスクトップアプリケーション、Web アプリケーション、またはヘッドレスマシンからのブラウザベースのアクセスをサポートします。
Basic 認証
Basic 認証を使用するようにWordPress を設定する前に:
- WordPress ログインに管理者権限があることを確認してください。
- ローカルホストで実行されているWordPress のバージョンを確認します。(WordPress 4.7 以降はネイティブでWordPress REST API サポートしていますが、それより前のバージョンでは、REST API へのアクセスを安全に行うには、Basic 認証プラグインの使用が必要です。)
- WordPress ホストにログインします。
- 4.7より前のバージョンのWordPress を実行している場合は、REST API プラグインをインストールしてください。
- Basic Authentication プラグインをインストールします。
- カスタムタクソノミーを作成するには、Simple Taxonomy Refreshed をインストールします。プラグインを手動でインストールしたい場合は、圧縮されたフォルダをwp-content\plugins フォルダに展開してからWordPress 管理者インターフェース経由でプラグインを有効にします。
- 次の接続プロパティを設定します。
- AuthScheme:Basic。
- Url:WordPress URL。
- User:ユーザーネーム。
- Password:パスワード。
You can then follow the steps below to use the Data Explorer to create a FireDAC connection to WordPress データ.
- In a new VCL Forms application, expand the FireDAC node in the Data Explorer.
- Right-click the ODBC Data Source node in the Data Explorer.
- Click Add New Connection.
- Enter a name for the connection.
- In the FireDAC Connection Editor that appears, set the DataSource property to the name of the ODBC DSN for WordPress.

Create VCL Applications with Connectivity to WordPress データ
Follow the procedure below to start executing queries to WordPress データ from a simple VCL application that displays the results of a query in a grid.
-
Drop a TFDConnection component onto the form and set the following properties:
- ConnectionDefName: Select the FireDAC connection to WordPress データ.
- Connected: Select True from the menu and, in the dialog that appears, enter your credentials.
-
Drop a TFDQuery component onto the form and set the properties below:
- Connection: Set this property to the TFDConnection component, if this component is not already specified.
SQL: Click the button in the SQL property and enter a query. For example:
SELECT Id, Name FROM Categories
- Active: Set this property to true.
Drop a TDataSource component onto the form and set the following property:
- DataSet: In the menu for this property, select the name of the TFDQuery component.
-
Drop a TDBGrid control onto the form and set the following property:
- DataSource: Select the name of the TDataSource.
- 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.

Related Articles
Below you can find other articles for using the CData ODBC Driver with RAD Studio, Delphi, and C++ Builder.