Going from Delphi to FPC/Lazarus, my first steps
After analize my options to migrate from win32 to linux some Object pascal projects, and under take little test i finally get the trip. My choice is to give a try to FPC/Lazarus.
I start migrating a server from Delphi/Win32 to FPC/Linux that weekend.
The first thing i do is get the latest beta version of RO/DA libraries for FPC and make it compile under lazarus. After a little work i have RO/DA in my lazarus palette. Happiness!
RemObjects SDK palette
Data Abstracts palette
Next, i copy all my sources to a new folder, allowing to advance in my experiment with peace of mind.
Lazarus IDE have severals experts to do that help that job. One is the delphi project converter. I try that and the result was part of the project work and another forms complains about strange chars in several dfms , maybe because of the spanish language used in mostly of them.
So, i start the manual process. First converting DFM files to LFM files, and then editing all my units to make it FPC friendly.
The process is almost trivial, the main points you must have in account are:
- Most of third parties components are delphi/windows related, so before start the process get out that libraries of
your code or you will have several headaches. - Activate Delphi mode in the project options. In my experience i also must do in the unit itself {$MODE delphi}
- Add to your unit a def to change between LResources unit and windows unit. Example:
<br></br>
unit fServerForm;```
{$ifdef FPC}
{$MODE delphi}
{$endif}
interface
uses
{$ifdef FPC}
LResources,
{$else}
windows,
{$endif}
uDAMemDataTable;
type
I put whenever i can defines.My idea is maintain a unique code base, merging that experiment with the project delphi codebase when work done.
4)Remove or embrace in ifdef the *.dfm line.
{$ifndef FPC}
{$R *.dfm}
{$endif} ```
- If already no defined add initialization section including lrs files.
initialization
{$i aService_Impl.lrs}
- Threading is a little diff,example;
{$ifdef FPC}<br></br>
InitCriticalSection(aCriticalSection);<br></br>
{$else}<br></br>
InitializeCriticalSection(aCriticalSection);<br></br>
{$endif} ```
TryEnterCriticalSection not implemented, use EnterCrticialSections instead.
{$IFDEF FPC}
DoneCriticalSection(aCriticalSection);
{$ELSE}
DeleteCriticalSection(aCriticalSection);
{$ENDIF}
7) Fomclose have slightly diff params.
{$ifdef FPC}
procedure TfmInputOutput.FormClose(Sender: TObject;
var CloseAction: TCloseAction);
{$else}
procedure TfmInputOutput.FormClose(Sender: TObject; var Action: TCloseAction);
{$endif}
begin
Poweroff;
end; ```
I think is invaluable the possibility of compile native servers, cross platforms using remobjects framework. Is worth the effort to make it works.
I love Delphi, but in the meantime, while codegears shareholders or anyone taking the path to other platforms give the needed step i will give a try to Lazarus.
What do you think? Is some of the several platforms offered by FPC a need for you in the short time?
I appreciate any comments.