#1 2016-07-10 10:36:53

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

What's your sugestions on preparing a GUI program for Lazarus?

It might be a good idea to make our code as much prepared for Lazarus/FPC as possible, while still using Delphi as the development tool for the sake of productivity.

And the following are my initial thoughts, I encourage you to add your valuable points, since this can be served as a general guide for the community smile

Prerequisites
===
We must split our program into modules - the app logic and the services (including UI service and other system services such as service for accessing the file system.


The idea
===
The idea behind the following opinions is **prepare for changes**, which itself is a general rule of developing software.

The plan
===

So let's see what might change for a Delphi GUI program that needs to be compiled with FPC and also run other desktop OSs supported by LCL:

* The language. There is not much we can do for this, maybe don't use language features those not supported/compatible by FPC, for example, anonymous methods and generics.

* The RTL.  The run-time library is actually application services needed by our program. We should organize and encapsulate the services into interfaces, for example, all functions for accessing the file system should be defined by the IFileSys interface, and we can implement it separately for Delphi and FPC - we can even have one implementation for Linux while another for Mac OS.


* The basic data types - especially the **strings**. The String in Delphi and the String in FPC is different - they are not binary-compatible. I also heard that FPC has a recent breaking change and broke some existing code, and they seem also has a plan to change it for utf16 IIRC (links pending). So it might be a good idea to use a fixed string type as the foundation for our program from the very start.

In this regard my first idea is to use UTF8string across the compiler and platform, for two reasons:
- utf8 is proven and is vastly widely used.
- The SynCommons.pas included by the mORMot framework already has a lot of **cross-platform** functions for string manipulation, that are already compatible by both Delphi and FPC.

A sidenote: We should really consider using SynCommons.pas as the "RTL" - it's feature rich, and it is already compile-able under Delphi and FPC for Windows and Linux.


It's just my humble options, and I'll be appreciated if you can provide any help on this.

---
Edwin Yip

Last edited by edwinsn (2016-07-10 10:48:23)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#2 2016-07-10 11:45:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,134
Website

Re: What's your sugestions on preparing a GUI program for Lazarus?

Yes, the main point about SynCommons.pas is that it contains a lot of functions and classes which are cross-platform and cross-compiler.
In most cases, SynCommons + Classes + SysUtils - which are common to Delphi and FPC, should be enough.

AFAIR there is good generics support in FPC, if you switch to the Delphi language mode.
The easiest is to include the following line in all your units:

interface

{$I Synopse.inc} // define HASINLINE USETYPEINFO CPU32 CPU64

So it would define all conditional needed to identify the compiler features (e.g. HASINLINE), and switch the FPC compiler to the Delphi mode.

This is what is documented in http://synopse.info/files/html/Synopse% … ml#TITL_45

And the main .dpr may start as such:

program Project01;

uses
  {$I SynDprUses.inc} // use FastMM4 on older Delphi, or set FPC threads
...

See most supplied samples.

Offline

Board footer

Powered by FluxBB