Migrate from Windows to Linux using Kylix3

Source: Internet
Author: User
Tags sql error
Article Title: migrate from Windows to Linux using Kylix3. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Introduction

Use Borland? Delphi 7? Tools like Studio and IBM? DB2? Universal Database? One of the advantages of such databases is that migration between platforms only requires a small amount of changes and re-compilation. In the first article of this series, I used Delphi 7 Studio to create an application to connect to IBM DB2 UDB. In my second article, I have added more features to this application, such as master-detail reports to make it more interesting and useful. Now that I have created an executable application, let's continue and make a big leap, using Borland Kylix? 3. Run it from Microsoft? Windows? On the Delphi 7 Application to Linux? Application.

Using Kylix 3 to migrate to Linux is quite easy. Borland Kylix 3 is a fast application environment for Linux development. Kylix uses Delphi 7 Object Pascal (and C ++) as the development language, and uses the RAD environment for Linux that everyone is familiar. One of the biggest advantages provided by Borland is that migrating an application is not so much a "porting" project as re-compiling a Windows/Delphi (or Linux/Kylix) project.

When you use Kylix to recompile an application to migrate it from Windows and Delphi 7 to Linux, remember a few points. First, all versions of Kylix contain the TSQLClientDataSet component, which is also available in Delphi 6, but is not encouraged in Delphi 7 and replaced by TSimpleDataSet. Although this does not seem to be a big problem, once you realize that it is a problem, it means that you can only use Delphi 7 to compile TSimpleClientDataSet, instead, TSQLClientDataSet can only be compiled using tools other than Delphi 7.

Migrating applications from Windows to Linux involves obtaining source files and transferring them from Windows to Linux. In Linux, file names (and unit names) are case sensitive. Therefore, if you add your own units, you must be careful (Delphi 7 will ensure that all units and file names are case sensitive ). However, you do not need to transfer all project files from Delphi to Kylix. Especially. cfg and. dof files that contain Windows-specific options. Kylix will regenerate these files as. conf and. kof files. In short, you only need to put the main project file (. Dpr and. res) and cell file (. Pas and. xfm) are transmitted from Windows to Linux (the code files used in this article can be obtained at the end of the article ).

DB2 on Linux

In addition to using Kylix on Linux, We must connect to a DB2 version on Linux (of course, you can always connect to DB2 databases on other platforms ). Note: I have tried to use the DB2 Universal Database Personal Edition v7.x, but encountered an Error message: SQL Error: Error mapping failed. other people who have used dbExpress and Kylix have reported this message. In this case, make sure that the latest DB2 version (v8.1 beta version, can be downloaded from the IBM website) to solve this problem.

A small amount of source code changes

After the source file is migrated from Windows to Linux, open the project in Kylix (see figure 1 ). When you open the project and view the SQLConnection feature in the Object Inspector, you will see two feature values specific to Win32 that cannot be used on Linux: LibraryName (set to DBEXPDB2.DLL) and VendorLib (set to db2cli. dll ). Linux does not have a DLL; it uses the. so file instead. To change these values, you must first select another value for the ConnectionName feature, and then re-select DB2Connection as the ConnectionName. this will set LibraryName to libsqldb2.so. 1. Set VendorLib to db2cli. dll.

The good news is that when you migrate a project from Delphi on Windows to Kylix on Linux, you only need to change these two features. Bad messages must be completed manually. Each time a new change is made on a platform, the above change must be performed manually, which is not what you want to do. Another good news is that by writing some code in the OnCreate event handler of the form, and assigning the correct value to LibraryName and VendorLib (and Caption of the main form ), we can solve this problem 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.Openend;
       

Note: we cannot simply add {$ ELSE} after the first {$ IFDEF}, because Linux is no longer the only alternative platform for MSWINDOWS. Now, Delphi 7 Studio (used in.. NET in the previewed version of the command line compiler) also supports CLR as a platform.

Another feature that you must check is the FileName feature of the TSQLMonitor component. For example, it should not use/or \ characters but point to a file name. Finally, it should be noted that the MidasLib, dbExpDB2, and CrtL units are not available in Linux. Therefore, you must use the Midas. so and dbexpdb2.so libraries to deploy executable files.

After you have a single-source project on Windows and Linux, you can work in Delphi or Kylix (this will lead to complicated project source code merging ), or, you can work in one environment and re-compile it only in another environment. Personally, I have been using Delphi IDE on Windows to design my application, and then transfer it to Linux and recompile it with Kylix. In this way, I can direct the SQLConnection component to the Windows DLL of DB2 (instead of the Linux. so library ).

Conclusion

With Delphi 7, Kylix 3, and DB2, you do not have to be stuck on a platform or sacrifice the RAD environment because of the availability of tools or databases when building Linux applications. In my next article, I will use the Delphi WebSnap component in conjunction with the dbExpress data access layer to build a Web server application with the DB2 backend.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.