Skip to main content

The Big Switch: Moving from Windows to Linux with Kylix 3

Bob Swart (drbob@chello.nl), Author, Trainer, Consultant and Webmaster, Bob Swart Training and Consultancy
Bob Swart (aka Dr.Bob - www.drbob42.com) is an author, trainer, consultant and Webmaster working for his own company called Bob Swart Training & Consultancy (eBob42) in Helmond, The Netherlands. Bob, who writes his own Delphi training material, has spoken at Delphi and Borland Developer Conferences since 1993. Bob has written hundreds of articles, and is co-author of the Revolutionary Guide to Delphi 2, Delphi 4 Unleashed, C++Builder 4 Unleashed, C++Builder 5 Developer's Guide, Kylix Developer's Guide, Delphi 6 Developer's Guide, and the upcoming C++Builder 6 Developer's Guide.

Summary:  One of the great things about using tools and databases such as Borland Delphi 7 Studio and IBM DB2 Universal Database is that moving between platforms is only a matter of a few changes and a recompile. Author Bob Swart takes you through the process.

Date:  31 Oct 2002
Level:  Introductory
Activity:  812 views

© 2002 International Business Machines Corporation. All rights reserved.

Introduction

One of the great things about using tools and databases such as Borland® Delphi 7TM Studio and IBM® DB2® Universal DatabaseTM is that moving between platforms is only a matter of a few changes and a recompile. In the first installment of this series, I created an application in Delphi 7 Studio that connects to an IBM DB2 UDB, and in my second article, I added some more functionality such as master-detail reporting to make the application more interesting and useful. Now that I've created an application that is functional, let's go ahead and take a big jump and move it from a Delphi 7 application running on Microsoft® Windows® to a Linux® (on Intel architecture) application using Borland KylixTM 3.


Moving to Linux is easy with Kylix 3

Borland Kylix 3 is a rapid application environment for Linux development. Kylix uses Delphi 7 Object Pascal (as well as C++) as the development language, as well as a familiar RAD environment for Linux. One of the greatest benefits the Borland tools offer, is that moving an application is less of a "porting" project than a recompilation of your Windows/Delphi (or Linux/Kylix) project.

When moving the application from Windows and Delphi 7 to Linux by recompiling it with Kylix, there are a few things we must keep in mind. First of all, all versions of Kylix contain the TSQLClientDataSet component, which is also present in Delphi 6 but is deprecated and is replaced by TSimpleDataSet in Delphi 7. While this may not seem like a big issue, it is an issue once you realize that this means that the TSimpleClientDataSet will only compile with Delphi 7, and the TSQLClientDataSet only without Delphi 7.

Moving an application from Windows to Linux involves taking the source files and transporting them from Windows to a Linux file system. On Linux, filenames (and unit names) are case sensitive, so you must take care of that if you added some units of your own (Delphi 7 will make sure all units and filenames are named with case sensitivity in mind). However, you do not need to move all project files over from Delphi to Kylix. Specifically, the .cfg and .dof files contain Windows specific options. These files will be regenerated by Kylix as .conf and .kof files. In short, you only need to transport the main project file (.dpr and .res) and the unit files (.pas and .xfm) from Windows to Linux. (The code files used in this article are available at the end of this article.)


DB2 on Linux

Apart from using Kylix on Linux, we must also connect to one of the various versions of DB2 on Linux (of course, you can always connect with DB2 databases on other platforms as well). One note: I've tried DB2 Universal Database Personal Edition v7.x and encountered an error message: SQL Error: Error mapping failed. This message has been reported by some other people using dbExpress and Kylix, and can be solved in this case by making sure to use the latest version of DB2 on Linux, namely the v8.1 beta, which can be downloaded from the IBM web site.


Minor source code changes

After the source files are moved from Windows to Linux, open the project in Kylix (see Figure 1). When you open the project and look at the SQLConnection properties in the Object Inspector, you see two property values that are Win32 specific, and will not work on Linux: the LibraryName (set to DBEXPDB2.DLL) and the VendorLib (set to db2cli.dll). Linux doesn't have DLLs; it uses .so files instead. To change these values, you must first select another value for the ConnectionName property, and then reselect DB2Connection as ConnectionName again. This will set LibraryName to libsqldb2.so.1 and VendorLib to db2cli.dll.

The good news is that these two properties are the only things you have to change when you move the project over from Delphi on Windows to Kylix on Linux. The bad news is that it has to be done manually. Making these changes manually every time a new change is made on one platform is not something you want to do. The good news again is that we can solve this problem by writing some code in the OnCreate event handler of the form, by assigning the correct values to the LibraryName and VendorLib (as well as the Caption of the main form), as follows:

 
  procedure TForm1.FormCreate(Sender: TObject); 
  begin 
    {$IFDEF MSWINDOWS} 
      Caption := 'Delphi 7 talking to DB2 using dbExpress'; 
      SQLCOnnection1.LibraryName := 'DBEXPDB2.DLL'; 
      SQLCOnnection1.VendorLib := 'db2cli.dll'; 
    {$ENDIF} 
    {$IFDEF LINUX} 
      Caption := 'Kylix 3 talking to DB2 using dbExpress'; 
      SQLCOnnection1.LibraryName := 'libsqldb2.so.1'; 
      SQLCOnnection1.VendorLib := 'libdb2.so'; 
    {$ENDIF} 
    cdsEMPLOYEE.Open; 
    cdsEMP_ACT.Open; 
    cdsEMP_PHOTO.Open; 
    cdsEMP_RESUME.Open 
  end; 

Note that we cannot simply add {$ELSE} after the first {$IFDEF}, since Linux isn't the only alternative for MSWINDOWS anymore, now that Delphi 7 Studio ( in the preview command-line compiler for .NET) also supports CLR as a platform.

Another property that you have to check is the FileName property of the TSQLMonitor component, which should not use / or \ characters, but point to a single filename for example. Finally, I should note that the MidasLib, dbExpDB2 and CrtL units are not available on Linux, so you have to deploy your executable with the Midas.so and dbexpdb2.so libraries.


Figure 1. Kylix application at design-time
Kylix application at design-time

After you have a single source project on Windows and Linux, you can either work in both Delphi and Kylix (which can cause complex merges of the project source code), or work in one environment and only recompile in the other. Personally, I always design my applications using the Delphi IDE on Windows, and then transport and recompile the application on Linux using Kylix. That way, I can let the SQLConnection component point to the Windows DLLs for DB2 (instead of the Linux .so libraries).


Summary

With Delphi 7 or Kylix 3 and DB2, you don't have to be locked into one platform because of tool or database availability, or sacrifice a RAD environment when building Linux applications. In my next article, I will use the Delphi WebSnap components in combination with the dbExpress data access layer to build Web server applications with a DB2 backend.



Download

NameSizeDownload method
source.zip6 KB

Information about download methods


About the author

Bob Swart (aka Dr.Bob - www.drbob42.com) is an author, trainer, consultant and Webmaster working for his own company called Bob Swart Training & Consultancy (eBob42) in Helmond, The Netherlands. Bob, who writes his own Delphi training material, has spoken at Delphi and Borland Developer Conferences since 1993. Bob has written hundreds of articles, and is co-author of the Revolutionary Guide to Delphi 2, Delphi 4 Unleashed, C++Builder 4 Unleashed, C++Builder 5 Developer's Guide, Kylix Developer's Guide, Delphi 6 Developer's Guide, and the upcoming C++Builder 6 Developer's Guide.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=13262
ArticleTitle=The Big Switch: Moving from Windows to Linux with Kylix 3
publish-date=10312002
author1-email=drbob@chello.nl
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers