<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Siliconfuture.net &#187; Programming</title>
	<atom:link href="http://www.siliconfuture.net/blog/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.siliconfuture.net/blog</link>
	<description>An Engineering Masterpiece, Really!</description>
	<lastBuildDate>Sun, 25 Jul 2010 20:19:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Porting DB Designer Fork to Lazarus and the Free Pascal Compiler</title>
		<link>http://www.siliconfuture.net/blog/2010/07/porting-db-designer-fork-to-lazarus-and-the-free-pascal-compiler/</link>
		<comments>http://www.siliconfuture.net/blog/2010/07/porting-db-designer-fork-to-lazarus-and-the-free-pascal-compiler/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 20:19:10 +0000</pubDate>
		<dc:creator>Sam Nelson</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.siliconfuture.net/blog/?p=195</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>DB Designer is an excellent visual database design tool that was originally written and maintained by <a href="http://www.fabforce.net">fabFORCE</a>.  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 <a href="http://sourceforge.net/projects/dbdesigner-fork/">project</a> 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.</p>
<p>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.</p>
<ul>
<li>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.</li>
<li>It would also (in my own opinion) make the project more supportable by using a current and actively developed compiler / library.</li>
<li>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.</li>
<li>Unicode support has been in Lazarus for some time compared to Delphi which only started supporting Unicode in Delphi 2007.</li>
</ul>
<p>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.</p>
<h2>Getting the Code</h2>
<p>I&#8217;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 &#8220;official&#8221; Ubuntu revision control software.  However, it was slow and kind of clunky.  I stumbled upon git after watching a rather humorous <a href="http://www.youtube.com/watch?v=4XpnKHJAok8">video</a> of Linus Torvalds speaking on git and his rant about how much he couldn&#8217;t stand CVS and SVN.  Now I&#8217;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 <em>git-svn</em>.  It allows you to interface with subversion projects using the git tools I am familiar with.  Enough talk, lets do some work!</p>
<p>Using git-svn<br />
<a href="http://www.viget.com/extend/effectively-using-git-with-subversion/">http://www.viget.com/extend/effectively-using-git-with-subversion/</a><br />
<a href="http://www.kernel.org/pub/software/scm/git/docs/git-svn.html">http://www.kernel.org/pub/software/scm/git/docs/git-svn.html</a></p>
<p>First, install the git-svn package (instructions for Ubuntu 9.10)</p>
<pre>$ sudo apt-get install git-svn</pre>
<p>I keep all my code projects under the <em>src</em> directory in my home:</p>
<pre>$ cd src </pre>
<p>Now clone the existing dbdesigner-fork repository into the src directory</p>
<pre>$ git svn clone https://dbdesigner-fork.svn.sourceforge.net/svnroot/dbdesigner-fork</pre>
<p>The full source tree with revisions checked out is only 52Mb, not bad.</p>
<pre>$ du -sh dbdesigner-fork/
52M	dbdesigner-fork/</pre>
<p>I also created and switched to a new branch for the Lazarus porting work:</p>
<pre>$ cd dbdesigner-fork
$ git branch lazarus-dev
$ git checkout lazarus-dev
</pre>
<h2>Installing Lazarus</h2>
<p>Very easy under either Linux or Windows.  Following are instructions for Ubuntu 9.10.</p>
<p>Get the Lazarus package (includes dependencies such as FPC)</p>
<pre>$ sudo apt-get install lazarus</pre>
<h2>Resources</h2>
<p>There are several resources on the Lazarus <a href="http://wiki.lazarus.freepascal.org">wiki</a> that give guidance on how to port software from Delphi/Kylix over to Lazarus/FPC.</p>
<ul>
<li><a href="http://wiki.lazarus.freepascal.org/Lazarus_Components">Lazarus Components</a> &#8211; Comparison between Lazarus and Turbo Delphi components</li>
<li><a href="http://wiki.lazarus.freepascal.org/Lazarus_For_Delphi_Users">Lazarus For Delphi Users</a> &#8211; For Delphi users who are getting started with Lazarus</li>
<li><a href="http://wiki.lazarus.freepascal.org/Code_Conversion_Guide">Code Conversion Guide</a> &#8211; How to convert existing code and components from Delphi and Kylix</li>
</ul>
<p>In addition to these, some background information on Delphi is helpful</p>
<ul>
<li><a href="http://www.blong.com/Conferences/DCon2001/VCLvsCLX/VCLvsCLX.htm">CLX vs VCL</a></li>
<li><a href="http://port2laz.blogspot.com/2005/12/from-clx-to-vcl.html">Porting from Delphi to Lazarus</a></li>
</ul>
<p>Some possible drawbacks to using Lazarus<br />
No MDI:</p>
<p>http://wiki.lazarus.freepascal.org/index.php/MultiDoc</p>
<p>http://objectmix.com/pascal/78231-lazarus.html</p>
<h2>Modifying the Code</h2>
<p>I&#8217;m going to start the porting process by following the instructions listed on the Lazarus <a href="http://wiki.lazarus.freepascal.org/Code_Conversion_Guide#Another_method_to_convert_a_Delphi_or_Kylix_project_to_Lazarus">Code Conversion Guide</a>.</p>
<h4>Renaming Files</h4>
<p>First, rename .xfm files to .lfm (kind of a clunky way to do it using bash, I welcome suggestions on how to improve this!)</p>
<pre>for i in $(find ~/src/dbdesigner-fork/ -name "*.xfm"); do mv $i ${i%%.*}.lfm; done</pre>
<p>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:</p>
<pre>$ git add .</pre>
<p>Commit the changes (I&#8217;m paranoid so I commit alot&#8230;), by the way, the &#8216;-a&#8217; option here ensures that the rename from xfm to lfm is properly tracked.</p>
<pre>$ git commit -a -m "Renamed form data files"</pre>
<p><strong>Lesson Learned:</strong> 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.</p>
<pre>git reset --hard HEAD^</pre>
<p>Now rename the main project file and update repository</p>
<pre>$ mv DBDesignerFork.dpr DBDesignerFork.lpr
$ git add DBDesignerFork.lpr
$ git commit -a -m "Renamed main project file"</pre>
<h2>Editing Main Project File</h2>
<p>Following the directions in the code conversion guide again.</p>
<ol>
<li>Add {$mode delphi}{$H+} or {$mode objfpc}{H+} directives</li>
<li>Add &#8216;Interfaces&#8217; to uses clause</li>
<li>Comment out or delete {$R *.res} or directive</li>
</ol>
<p>Commit changes</p>
<pre>$ git commit -m "Added new directives and changed uses clause." DBDesignerFork.lpr</pre>
<h2>Creating the Resource Files</h2>
<p>Need to create the resource files that will be referenced by the .pas unit files.</p>
<pre>for i in $(find ~/src/dbdesigner-fork/ -name "*.lfm"); do lazres ${i%%.*}.lrs $i; done</pre>
<h2>Editing .pas Unit Files</h2>
<p>For this step I am going to make the following changes (if needed) to the list of files below:</p>
<ol>
<li>Add {$mode delphi}{$H+} or {$mode objfpc}{H+} directives</li>
<li>Add &#8216;LResources&#8217;</li>
<li>Comment out or delete {$R *.dfm} or {$R *.xfm} directive</li>
<li>Add &#8216;Initialization&#8217; section at the end of each unit file, and add {$I unitname.lrs} directive in it </li>
</ol>
<p>DBConnEditor.pas <strong>DONE</strong><br />
DBConnLogin.pas <strong>DONE</strong><br />
DBConnSelect.pas <strong>DONE</strong><br />
DBDM.pas <strong>DONE</strong><br />
DBEERDM.pas <strong>DONE</strong><br />
EditorDatatype.pas <strong>DONE</strong><br />
EditorImage.pas <strong>DONE</strong><br />
EditorNote.pas <strong>DONE</strong><br />
EditorQueryDragTarget.pas <strong>DONE</strong><br />
EditorQuery.pas <strong>DONE</strong><br />
EditorRegion.pas <strong>DONE</strong><br />
EditorRelation.pas <strong>DONE</strong><br />
EditorString.pas <strong>DONE</strong><br />
EditorTableData.pas <strong>DONE</strong><br />
EditorTableFieldDatatypeInplace.pas <strong>DONE</strong><br />
EditorTableFieldParam.pas <strong>DONE</strong><br />
EditorTableField.pas <strong>DONE</strong><br />
EditorTable.pas <strong>DONE</strong><br />
EERDM.pas <strong>DONE</strong><br />
EERExportImportDM.pas <strong>DONE</strong><br />
EERExportSQLScript.pas <strong>DONE</strong><br />
EERModel.pas <strong>DONE</strong><br />
EERModel_XML_ERwin41_Import.pas <strong>DONE</strong><br />
EERModel_XML.pas <strong>DONE</strong><br />
EERPageSetup.pas <strong>DONE</strong><br />
EER.pas <strong>DONE</strong><br />
EERPlaceModel.pas <strong>DONE</strong><br />
EERReverseEngineering.pas <strong>DONE</strong><br />
EERStoreInDatabase.pas <strong>DONE</strong><br />
EERSynchronisation.pas <strong>DONE</strong><br />
GlobalSysFunctions.pas <strong>DONE</strong><br />
GUIDM.pas <strong>DONE</strong><br />
LibXmlParser.pas<br />
MainDM.pas <strong>DONE</strong><br />
Main.pas <strong>DONE</strong><br />
OptionsModel.pas <strong>DONE</strong><br />
Options.pas <strong>DONE</strong><br />
PaletteDatatypes.pas <strong>DONE</strong><br />
PaletteDataTypesReplace.pas <strong>DONE</strong><br />
PaletteModel.pas <strong>DONE</strong><br />
PaletteNav.pas <strong>DONE</strong><br />
PaletteTools.pas <strong>DONE</strong><br />
PrinterSettings.pas <strong>DONE</strong><br />
RegExpr.pas<br />
Splash.pas <strong>DONE</strong><br />
Tips.pas <strong>DONE</strong><br />
ZoomSel.pas <strong>DONE</strong></p>
<p><strong>Now a little cleanup</strong><br />
Change all instances of CLX &#8216;Q&#8217; modules in the uses clause to their respective FPC module names</p>
<pre>
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' {} \;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.siliconfuture.net/blog/2010/07/porting-db-designer-fork-to-lazarus-and-the-free-pascal-compiler/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

