FireDAC: Mac OS X Client connecting to InterBase Server on Windows

Posted by on in Blogs

Mac client vs PC client, which is better?   With RAD Studio, Delphi or C++ Builder it really does not matter!  

Building your app in RAD Studio eliminates the need to engage in multiple development efforts for the same application on multiple devices. This means you get to market faster on multiple devices for the first release – and every release after that – while keeping costs down.  

RAD Studio speeds and simplifies OS X application development for Windows developers. Delivering a true native OS X version of your FireMonkey application is as simple as choosing Mac OS X as an additional target platform and clicking to compile – no extra development team required!

MacOSX_IBWindows

This post shows building a RAD Studio (Delphi or C++ Builder) Mac OS X Client connecting to a Remote InterBase Server on Windows.

Part 1.  Creating the FireDAC connection to remote InterBase Server database

This example is using RAD Studio 10.2 Tokyo (Delphi and/or C++ Builder)

Using InterBase Connection String for the sample EMPLOYEE.GDB database:  192.168.1.20/3050:C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\data\employee.gdb

Where 192.168.1.20 is the Windows Remote IP for InterBase Server and 3050 is the gds_db instance, tcp default InterBase port number.

 

Using the FireDAC Data Explorer Tab, created a new InterBase Connection called EMPLOYEE:

DataExplorerInterBase

Right-Click on the EMPLOYEE connection | Modify, and enter these parameters:

DriverID = IB

Database= 192.168.1.20/3050:C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\data\employee.gdb

 

Click TEST CONNECTION and verify you can connect to your InterBase database:

ConnectionEstablished

 Click OK.

FDConnectionEditorInterBase

Part 2 – Creating Multi-Device clients to connect to Remote InterBase database

1.       1. File | New | Multi-Device Delphi or C++ Builder application | Blank Application

 

2.       2. From Data Explorer, Drag and Drop the FireDAC EMPLOYEE remote InterBase connection onto the form:

 EmployeeConnection

1.       3. In the Object Inspector, set the following properties of TFDConnection:

a.       Set the LoginPrompt property to False, so that the user is not prompted for a login.

b.       Set the Connected property to True.

ObjectInspectorFDConnection  

Using the LiveBindings Wizard

1.       Use the LiveBindings Wizard to add the LiveBindings components (TBindSourceDBTBindNavigator), TFDQuery, and the Grid component.

2.       Add the LiveBinding components

a.       Select View > LiveBindings Designer (or View > Tools Window > Live Bindings Designer) and the LiveBindings Designer opens.

 

b.      Select LiveBindings Wizard

LiveBindingsDesignerWizard

1. On the Binding task page of the wizard, select Create a data source and click Next.

2.  On the Data Source page, select FireDAC and click Next.

3.   Change the Command Type to Query.

4.   Set the Command Text property to select * from employee. 

 BindingTask

Click Test Command:

 

 Verify Test command succeeded.

TestCommandSucceeded

 Click OK.

 

1.      5. Click the Next button.

2.      6. Select Add data source navigator.

3.     7. Click the Finish button.

At this point, TBindSourceDBTBindNavigator, and TFDQuery components were added to your form:

TBindSource

 NavigatorBind

 

Add the Grid component

1.       Reopen the LiveBindings Wizard.

2.       Select Link a grid with a data source binding task.

 

 BindingGrid

1.      3. Click the Next button.

2.      4. Select TSringGrid.

3.      5. Click the Next button.

4.      6. Select BindSourceDB1.

5.      7. Click the Finish button to close the wizard.

 

8. Your binding diagram should look as in the following image:

BindDiagram

 And the Form should display Design-Time Data on the TStringGrid:

DesignTimeData

 

Preparing Your Application for Run Time

 

FireDAC has a loosely-coupled multilayered architecture, where layers provide services. A service API is defined as a COM interface that other layers can request using the interface factory.

 

To properly operate FireDAC, you must link the implementation of IFDGUIxWaitCursor and IFDPhysDriver interfaces to your application.

 

1.      1. Select the NavigatorBindSourceDB1 and set the Align property to Top.

 

2.      2. Select the StringGridBindSourceDB1 and set the Align property to Client.

3.    3. Drop the TFDGUIxWaitCursor and TFDPhysIBDriverLink components on the form.

 Deploy and Run application as a Windows 32-bit Client

 

1.       1. Select Target Platform 32-bit Windows or 64-bit Windows:

Win32Target

2. Run Application

You should see the Windows Client Application run like this:

Win32App

 

Deploying your Application to OS X as an OSX Client

Up to this point, you have most likely used InterBase on your desktop. This means that the actual database is located at your local hard disk drive (for example, C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\Data\EMPLOYEES.GDB).

We need our Mac OS X Client to connect to our remote InterBase Server EMPLOYEE database on Windows.

Deploy InterBase Client Library to Mac OS X

1.       1. You need your PAServer running on your Mac.

 

2.       2. In the Project Manager, Select your OSX Target platform:

OSXTarget

3. In RAD Studio 10.2 Tokyo, open the Deployment Manager by selecting Project > Deployment

4. Select All-Configurations - OS X platform from the drop-down list of target platforms at the top of the Deployment Manager.

5. Select Add Featured Files (  FeaturedFiles ):

6. Select the InterBase Client module and select the OSX32 files, then click OK to close the Featured Files dialog box:

 FeaturedFIlesInterBase

 You will see the Mac OS X libgds.dylib added to your Mac OSX deployment list of files like this:

MacLibgds

 SAVE ALL

As of now, in the Windows Client, you have the FDConnection configured for your Windows FireDAC [EMPLOYEE] definition from the Data Explorer.  Your Mac does not have this FireDAC [EMPLOYEE] definition, so if you deploy your application as is to Mac OSX, you should get this FIreDAC exception:

>Exception EFDException in module Project2 at 0068321F.

 

[FireDAC][Stan][Def]-254. Definition [EMPLOYEE] is not found in [].

To resolve this exception, the FireDAC [EMPLOYEE] Definition does not exist on your Mac Client, so remove the [EMPLOYEE] definition from the Connection Definition Name in the FireDAC Connection Editor, and manually enter your Database value.   Double-click the FDConnection component to open the FireDAC Connection Editor.  Just remove the [EMPLOYEE] definition from the Connection Definition Name.  And set the Driver ID = IB.  This will erase the parameters you had for the [EMPLOYEE] connection.

FDConnectionIB

 Click OK, to exit out of the FireDAC Connection Editor.

Next, in code, let’s connect to our FireDAC EmployeeConnection.  We can use the Form’s FormCreate event handler for this:

Delphi:

procedure TForm3.FormCreate(Sender: TObject);

begin

EmployeeConnection.Open();

FDQuery1.Open();

end;

 

C++ Builder:

void __fastcall TForm4::FormCreate(TObject *Sender)

{

 EmployeeConnection->Open();

 FDQuery1->Open();

 

}

Lastly, we need to tell the Mac OS X Client the location of our InterBase database on our Windows InterBase Server.  For this, we can use the FireDAC BeforeConnect Event handler that fires immediately before establishing a FireDAC connection.  We use the BeforeConnect event handler to take application-specific actions before the connection component opens a connection to the remote source of database information:

Delphi:

procedure TForm3.EmployeeConnectionBeforeConnect(Sender: TObject);

begin

{$IFDEF MACOS}

EmployeeConnection.Params.Values['Database']:=

'192.168.1.20/3050:C:\Users\Public\Documents\Embarcadero\Studio\19.0\Samples\data\employee.gdb';

{$ENDIF}

 

end;

 

C++ Builder:

void __fastcall TForm4::EmployeeConnectionBeforeConnect(TObject *Sender) {

 

              try {

#if defined(_PLAT_MACOS)

                           EmployeeConnection->Params->Values["Database"] =

                           L"192.168.1.20/3050:C:\\Users\\Public\\Documents\\Embarcadero\\Studio\\19.0\\Samples\\data\\employee.gdb";

#endif

              }

              catch (Exception& E) {

                           ShowMessage(E.ClassName() + ": " + E.Message);

              }

 

}

 

Deploy the Mac OS X Client to your Mac

 

1.       Select OS X as the target platform.

TargetOSX

2.       Run your Mac OS X client application and it will deploy to your Mac:

 

3.       If all goes well, you should see you Mac OS X Client running on the Mac connected to your InterBase Server on Windows, displaying EMPLOYEE data on the StringGrid like this:

C++ Builder:

CppMacOSX_InterBase

Congratulations!

That's how easy it is using RAD Studio, Delphi or C++ Builder to have a Mac OS X client connect and get data from an InterBase Server Database on Windows!

 



About
Gold User, Rank: 90, Points: 4
Al Mannarino has 25+ years of software development experience, including object-oriented analysis and design (OOAD) and developing and deploying production applications. He is currently a Principal Software Consultant and Evangelist for Embarcadero Technologies. Prior to joining Embarcadero, Al spent three years working with CodeGear, a division of Borland that was acquired by Embarcadero in 2008. He also worked for five years as a lead systems engineer for Borland supporting application lifecycle management, software delivery optimization and developer tools solutions. Prior to Borland, Al served as a systems engineer for companies including Objectivity, Versant, Red Brick Systems, Information Builders, and was an electrical engineer for Grumman Aerospace performing application implementations on complex electrical-mechanical systems. Al has a bachelor's of science degree in electrical engineering from Manhattan College.

Comments

Check out more tips and tricks in this development video: