Skip to content

Porting DB Designer Fork to Lazarus and the Free Pascal Compiler

DB Designer is an excellent visual database design tool that was originally written and maintained by fabFORCE. The main developer was subsequently hired by MySQL and DB Designer became the MySQL workbench tool. Sometime after this the original DB Designer 4 code was forked as a new open source project to continue development on this great piece of software. I have used the software off and on since the pre-fork days of DB Designer 4 for various database projects. Recently I started using dbdesigner-fork for a new database project and wanted to try to debug some memory access violation errors that kept popping up while reverse engineering an Oracle database. I soon found out that in order to build the software, one needed a copy of Delphi 7 (for windows builds) or Kylix 3 (for linux builds). Unfortunately, these software packages are getting a bit long in the tooth and are becoming harder and harder to find for purchase on-line. Not to mention that the cost for either is in my opinion (for an older piece of software) quite high.

In the open source spirit of things I decided that I would try to attempt porting the software to build with the open source Lazarus IDE and Free Pascal Compiler. Here are some benefits I can see from doing this.

  • It would lower the barrier to entry for new contributors to the project as the tools required to develop it would be free and open source.
  • It would also (in my own opinion) make the project more supportable by using a current and actively developed compiler / library.
  • Lazarus also makes developing cross-platform projects a little bit easier, so if the porting goes well, Windows, Mac and Linux binaries could be released together.
  • Unicode support has been in Lazarus for some time compared to Delphi which only started supporting Unicode in Delphi 2007.

The purpose of this posting is to document my attempt to get a working build of dbdesigner-fork under Lazarus. I have very little experience with Delphi/Kylix and object pascal in general, so this may be a long and bumpy road. However, I hope that by documenting the process with all of my dumb mistakes along the way it may help others who are trying to port over legacy Delphi code to Lazarus.

Getting the Code

I’m a bit of an amateur when it comes to software development so I only recently started using version control for my software projects. I initially used bazaar as it was the “official” Ubuntu revision control software. However, it was slow and kind of clunky. I stumbled upon git after watching a rather humorous video of Linus Torvalds speaking on git and his rant about how much he couldn’t stand CVS and SVN. Now I’m not as opinionated as Torvalds when it comes to SVN, but I would prefer to use git as I am familiar with it (albeit at a somewhat limited level). Luckily there is a nice tool out there, at least for linux called git-svn. It allows you to interface with subversion projects using the git tools I am familiar with. Enough talk, lets do some work!

Using git-svn
http://www.viget.com/extend/effectively-using-git-with-subversion/
http://www.kernel.org/pub/software/scm/git/docs/git-svn.html

First, install the git-svn package (instructions for Ubuntu 9.10)

$ sudo apt-get install git-svn

I keep all my code projects under the src directory in my home:

$ cd src 

Now clone the existing dbdesigner-fork repository into the src directory

$ git svn clone https://dbdesigner-fork.svn.sourceforge.net/svnroot/dbdesigner-fork

The full source tree with revisions checked out is only 52Mb, not bad.

$ du -sh dbdesigner-fork/
52M	dbdesigner-fork/

I also created and switched to a new branch for the Lazarus porting work:

$ cd dbdesigner-fork
$ git branch lazarus-dev
$ git checkout lazarus-dev

Installing Lazarus

Very easy under either Linux or Windows. Following are instructions for Ubuntu 9.10.

Get the Lazarus package (includes dependencies such as FPC)

$ sudo apt-get install lazarus

Resources

There are several resources on the Lazarus wiki that give guidance on how to port software from Delphi/Kylix over to Lazarus/FPC.

In addition to these, some background information on Delphi is helpful

Some possible drawbacks to using Lazarus
No MDI:

http://wiki.lazarus.freepascal.org/index.php/MultiDoc

http://objectmix.com/pascal/78231-lazarus.html

Modifying the Code

I’m going to start the porting process by following the instructions listed on the Lazarus Code Conversion Guide.

Renaming Files

First, rename .xfm files to .lfm (kind of a clunky way to do it using bash, I welcome suggestions on how to improve this!)

for i in $(find ~/src/dbdesigner-fork/ -name "*.xfm"); do mv $i ${i%%.*}.lfm; done

Add the new files. By the way, this is super easy with git, the following command adds all new files in the current directory and below:

$ git add .

Commit the changes (I’m paranoid so I commit alot…), by the way, the ‘-a’ option here ensures that the rename from xfm to lfm is properly tracked.

$ git commit -a -m "Renamed form data files"

Lesson Learned: I screwed up my commits and adds a few times and it is nice to be able to back up a step using git. Use the following command to checkout the last commit.

git reset --hard HEAD^

Now rename the main project file and update repository

$ mv DBDesignerFork.dpr DBDesignerFork.lpr
$ git add DBDesignerFork.lpr
$ git commit -a -m "Renamed main project file"

Editing Main Project File

Following the directions in the code conversion guide again.

  1. Add {$mode delphi}{$H+} or {$mode objfpc}{H+} directives
  2. Add ‘Interfaces’ to uses clause
  3. Comment out or delete {$R *.res} or directive

Commit changes

$ git commit -m "Added new directives and changed uses clause." DBDesignerFork.lpr

Creating the Resource Files

Need to create the resource files that will be referenced by the .pas unit files.

for i in $(find ~/src/dbdesigner-fork/ -name "*.lfm"); do lazres ${i%%.*}.lrs $i; done

Editing .pas Unit Files

For this step I am going to make the following changes (if needed) to the list of files below:

  1. Add {$mode delphi}{$H+} or {$mode objfpc}{H+} directives
  2. Add ‘LResources’
  3. Comment out or delete {$R *.dfm} or {$R *.xfm} directive
  4. Add ‘Initialization’ section at the end of each unit file, and add {$I unitname.lrs} directive in it

DBConnEditor.pas DONE
DBConnLogin.pas DONE
DBConnSelect.pas DONE
DBDM.pas DONE
DBEERDM.pas DONE
EditorDatatype.pas DONE
EditorImage.pas DONE
EditorNote.pas DONE
EditorQueryDragTarget.pas DONE
EditorQuery.pas DONE
EditorRegion.pas DONE
EditorRelation.pas DONE
EditorString.pas DONE
EditorTableData.pas DONE
EditorTableFieldDatatypeInplace.pas DONE
EditorTableFieldParam.pas DONE
EditorTableField.pas DONE
EditorTable.pas DONE
EERDM.pas DONE
EERExportImportDM.pas DONE
EERExportSQLScript.pas DONE
EERModel.pas DONE
EERModel_XML_ERwin41_Import.pas DONE
EERModel_XML.pas DONE
EERPageSetup.pas DONE
EER.pas DONE
EERPlaceModel.pas DONE
EERReverseEngineering.pas DONE
EERStoreInDatabase.pas DONE
EERSynchronisation.pas DONE
GlobalSysFunctions.pas DONE
GUIDM.pas DONE
LibXmlParser.pas
MainDM.pas DONE
Main.pas DONE
OptionsModel.pas DONE
Options.pas DONE
PaletteDatatypes.pas DONE
PaletteDataTypesReplace.pas DONE
PaletteModel.pas DONE
PaletteNav.pas DONE
PaletteTools.pas DONE
PrinterSettings.pas DONE
RegExpr.pas
Splash.pas DONE
Tips.pas DONE
ZoomSel.pas DONE

Now a little cleanup
Change all instances of CLX ‘Q’ modules in the uses clause to their respective FPC module names

find . -type f -name '*.pas' -not -path './.git' -exec sed -i -e 's/QButtons/Buttons/g' \
-e 's/ Q[tT],//g' \
-e 's/,Q[tT],/,/g' \
-e 's/, Q[tT];/;/g' \
-e 's/QCheckLst/CheckLst/g' \
-e 's/QMask/Mask/g' \
-e 's/QStyle/Style/g' \
-e 's/QMenus/Menus/g' \
-e 's/QForms/Forms/g' \
-e 's/QTypes/Types/g' \
-e 's/QClipbrd/Clipbrd/g' \
-e 's/QStdCtrls/StdCtrls/g' \
-e 's/QExtCtrls/ExtCtrls/g' \
-e 's/QGrids/Grids/g' \
-e 's/QComCtrls/ComCtrls/g' \
-e 's/QPrinters/Printers/g' \
-e 's/QImgList/ImgList/g' \
-e 's/QControls/Controls/g' \
-e 's/QGraphics/Graphics/g' \
-e 's/QDialogs/Dialogs/g' \
-e 's/QDBCtrls/DBCtrls/g' \
-e 's/QConsts/Consts/g' \
-e 's/QFileCtrls/FileCtrls/g' \
-e 's/QDBGrids/DBGrids/g' {} \;

Installing and Configuring Oracle Instant Client 10.2.0.4 on Ubuntu 9.10

Lets be blunt about it. The Oracle client can be a real pain to get working sometimes. Following are some basic steps that I used to get a properly working Oracle client installation on Ubuntu 9.10.

Helpful Links


http://download.oracle.com/docs/cd/B12037_01/java.101/b10979/instclient.htm#sthref1813

Getting the files


The Oracle Instant Client main page is here. You will need to register (free account) with Oracle to access their free downloads. After you’ve registered, you can grab the following files from Oracle (10.2.0.4 is the current version as of the writing of this article). You may not need all of these, but I wanted to make sure that I had a complete installation of the client software.
oracle-instantclient-basic-10.2.0.4-1.i386.rpm
oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
oracle-instantclient-devel-10.2.0.4-1.i386.rpm
oracle-instantclient-jdbc-10.2.0.4-1.i386.rpm
oracle-instantclient-odbc-10.2.0.4-1.i386.rpm

Lets debianize the rpm’s

$ apt-get install alien rpm
$ sudo alien oracle-instantclient-basic-10.2.0.4-1.i386.rpm
$ sudo alien oracle-instantclient-devel-10.2.0.4-1.i386.rpm
$ sudo alien oracle-instantclient-sqlplus-10.2.0.4-1.i386.rpm
$ sudo alien oracle-instantclient-jdbc-10.2.0.4-1.i386.rpm
$ sudo alien oracle-instantclient-odbc-10.2.0.4-1.i386.rpm

Unfortunately the oracle-instantclient-basic rpm has a deprecated libstdc++.so.5 dependency, see this link for an excellent explanation of the issue and a solution.

To fix this issue, we need to additionally download the following file (32bit version, other versions are listed here):
http://www.oracle.com/technology/tech/oci/occi/downloads/occi_gcc343_102030.tar.gz

Repackaging the Instant Client Basic package


NOTE: if you are in a hurry, you can skip all of these repackaging steps and just install the deb’s as-is. Once they are installed, then copy the contents of the occi_gcc343_102030.tar.gz file to the $ORACLE_HOME/client/lib directory

Unpack the oracle-instantclient-basic package to a temporary directory to correct the libocci dependency

Extract the package data files

$ dpkg-deb -x oracle-instantclient-basic_10.2.0.4-2_i386.deb \
    tmp/oracle-instantclient-basic_10.2.0.4-2_i386

Extract the package control files

$ dpkg-deb -e oracle-instantclient-basic_10.2.0.4-2_i386.deb \
    tmp/oracle-instantclient-basic_10.2.0.4-2_i386/DEBIAN

Extract the new OCCI library and overwrite the deprecated files extracted from the package

$ tar -zxvf occi_gcc343_102030.tar.gz
$ mv libocci.so.10.1 libocci10.a \
    tmp/oracle-instantclient-basic_10.2.0.4-2_i386/usr/lib/oracle/10.2.0.4/client/lib/

Update the debian control files (Only really need to change the md5sums file)

$ cd tmp/oracle-instantclient-basic_10.2.0.4-2_i386
$ find usr/ -type f | xargs md5sum > DEBIAN/md5sums

Remove the old package in main directory, change ownership of package files to root and rebuild the debian package file

$ rm oracle-instantclient-basic_10.2.0.4-2_i386.deb
$ sudo chown -R root:root tmp/oracle-instantclient-basic_10.2.0.4-2_i386
$ dpkg-deb -b tmp/oracle-instantclient-basic_10.2.0.4-2_i386/ \
    oracle-instantclient-basic_10.2.0.4-2_i386.deb

Installing and Configuring

Now we can finally install the packages!

$ sudo dpkg -i oracle-instantclient-*

At this point you’ll probably want to set up some additional configuration details.

  • Set ORACLE_HOME in your .bashrc, or on the command line, following are all the variables I set
    export ORACLE_HOME=/usr/lib/oracle/10.2.0.4/client
    export PATH=$PATH:$ORACLE_HOME/bin
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
    export TNS_ADMIN=$ORACLE_HOME/network/admin
    
  • If you have a tnsnames.ora file (make sure the filename is all lowercase), you can install it as well
    $ sudo mkdir -p $ORACLE_HOME/network/admin
    $ sudo cp tnsnames.ora $ORACLE_HOME/network/admin
    

You can now test your Oracle client installation by connecting to a database with sqlplus (By the way, putting the password in the command line is not recommended as it can easily be pulled out of your history file by other nosy users if your permissions are too lax).

$ sqlplus 'username/password@SID'

If for some reason you have some trouble connecting, you can create a sqlnet.ora file under $ORACLE_HOME with some tracing options.

$ sudo vi $ORACLE_HOME/network/admin/sqlnet.ora

TRACE_DIRECTORY_CLIENT=/tmp
TRACE_LEVEL_CLIENT=SUPPORT

The next time the Oracle Instant Client is used, it will create a detailed log file under /tmp like the following: cli_1968.trc. Make sure to turn this option off when you are done as the logfile can get quite large!

That’s about it, any questions or suggestions, please post them!

Setting Up Syntax Highlighting in WordPress

I have seen some very well written blogs out on the interwebs which include clean and well highlighted example code inline with the rest of the document. Turns out it is really easy to implement in WordPress. I browsed around and found a nice comparison of different syntax highlighting tools and settled on the Google Syntax Highlighter. Here is the comparison review.

Getting the Code

You can get the latest version as a WordPress plugin either by searching for “Syntax Highlighter” in the plugins admin page for WordPress, or you can download from the WordPress site.

Usage

Just surround your code like this:

<pre class="brush:[code-alias]"> …Your Code Here </pre>

replace the "[code-alias]" segment with the type of code you have. See all the available brush aliases at the plugin author's website. For Example, PHP would be like this:

<pre class="brush:php"> …Your PHP Code Here </pre>

Examples

SQL

SELECT count(1)
FROM some_table
WHERE some_field = 'some value';

C

#include 

main()
{
    printf("hello, world\n");
}

Python

#!/usr/bin/python

print 'Hello World!'

Fixing the touchpad on the Eeepc 1000HE in Linux

The default configuration under eeebuntu 2.0 works pretty well but there are a couple glitches that are annoying. For one the multi-touch scroll is very jumpy and sensitive.

Here is a launchpad bug describing the driver problems in Intrepid with the Elantech toucpad.

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/123775

See also this link for configuring the touchpad via gsynaptics.

https://help.ubuntu.com/community/SynapticsTouchpad#Enabling SHMConfig

This was all discussed in a great post under the above launchpad bug

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/123775/comments/84