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' {} \;

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*