Recent

Author Topic: Same source for Delphi and Lazarus  (Read 5727 times)

tk

  • Sr. Member
  • ****
  • Posts: 364
Same source for Delphi and Lazarus
« on: June 08, 2014, 06:11:48 pm »
Hello,
we need to convert a Delphi project to Lazarus to make native Linux app.
Nothing extraordinary :)
But what we need is to maintain this project both in Delphi and Lazarus later, from single source code (the same DPR, PAS, DFM), for many reasons, e.g.:
-easier maintenance,
-certain components we use in Delphi we still have to use, because customers are used to it (e.g. Alphacontrols), there is no exact counterpart in Lazarus, so we have to shrink the functionality in Linux a bit, make dummy component sets etc.

This far everything ok, we converted everything we wanted in PAS files.
However, we have problems with DFM files.
Of course we had to make those dummy components for Lazarus with properties we used in Delphi, thanks a lot for that missing property highligher!

However, certain properties Delphi is using in standard components (inclusive TMainForm, TFrame) are missing in Lazarus!
This is very annoying when I switch to/from Delphi/Lazarus, I always have to confirm when certain properties are missing.

My question is, is there some strategy how Delphi properties will or should be implemented in Lazarus? At least as dummy properties?
E.g.
TMainForm.OldCreateOrder, TMainForm.DesignSize, TMainForm.TextHeight TFrame.ParentBackground etc.
Or is there some common strategy to maintain these "combined" projects (I believe I am not alone with that problem:))?
Except for those missing Delphi properties it seems that managing the same projects in both IDEs is possible (EDIT: it was not in the old 0.9 Lazarus days...).

Thanks a lot
tk

Lazarus 1.22, FPC 2.6.4
« Last Edit: June 08, 2014, 06:15:57 pm by tk »

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Same source for Delphi and Lazarus
« Reply #1 on: June 08, 2014, 10:21:32 pm »
As I've already got the same problem (though not with any third party Delphi components), here is my own experience.

I guess you've already got a look at the Lazarus tools for converting Delphi projects/units/packets to Lazarus/FPC. Of course, they are not really supposed to be used in maintaining both kinds of applications; they are rather devoted to help to migrate from Delphi to Lazarus.

There are still a few minor but annoying differences between Delphi and Lazarus.

But it's still quite enough; for instance (a few other ones to add to your own list):

-form files: textheight, font.style = [], pixelsperinch, ... properties; txpmanifest control (i.e. xpman); size of forms, position of sub-controls into tgroupbox (i.e. left and top properties),

-unit files: as it's possible to make conditional compilation (.i.e.{$IFDEF FPC}), it's seems to be that there is no problem to maintain only one copy for each unit. Except that Delphi uses internally ANSI or Unicode(wide char) by default for its strings, while Lazarus uses Unicode(UTF8). AFAIK, it's necessary to always convert them before using them (i.e. if you maintain only one kind of source code). For instance, there is no "automatic" solution for something like:
Code: [Select]
Edit1.Text := 'Something with non basic ASCII characters: é è ï ä ö ß';

Unless using directly the numeric code values for these characters in both cases with conditional compilations. Has someone else another simple solution (full internalization with external files was too much longer for me, according to the time I could devoted to the migration) ?

Finally, it was enough (at least for me) to prevent from using only one copy for forms and units in both cases.

So, I decided to maintain only one kind of source code (i.e. Delphi or Lazarus), and to copy them into the other one after each modification. I've coded my own very, very basic tools to convert all the form files or units inside a directory, and I just use them after the copy.

The units conversion transforms only unit files from UTF8 to ANSI, or the inverse (any other text conversion tool could do the trick, but they are generally processing one file at a time only). While the forms conversion is dealing with each little troubles I've found during my own projects conversions.

It's certainly not perfect and it sounds a bit "odd", but at least I have the control above any new problem I could encounter in the future.

Just my 2 cents...
« Last Edit: June 08, 2014, 10:37:54 pm by ChrisF »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3645
  • I like bugs.
Re: Same source for Delphi and Lazarus
« Reply #2 on: June 09, 2014, 05:27:45 pm »
Or is there some common strategy to maintain these "combined" projects (I believe I am not alone with that problem:))?

One strategy is to use separate form files, .dfm for Delphi and .lfm for Lazarus.
As you probably noticed the Delphi converter in Lazarus has an option for "Use the same DFM form file".
Unfortunately the properties will never be exactly the same. In a form file you cannot use IFDEFs like you can in a Pascal source.

Using 2 form files makes it more flexible for you to use different components in Delphi and Lazarus. You still must use IFDEF in the Pascal unit but you don't need to make dummy components.
The downside is that you must do any GUI changes twice.
« Last Edit: June 09, 2014, 08:29:56 pm by JuhaManninen »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7499
Re: Same source for Delphi and Lazarus
« Reply #3 on: June 09, 2014, 07:00:08 pm »
For instance, there is no "automatic" solution for something like:
Code: [Select]
Edit1.Text := 'Something with non basic ASCII characters: é è ï ä ö ß';

Afaik that works fine in both Unicode Delphi as Lazarus. Since both use utf8 source encoding.

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: Same source for Delphi and Lazarus
« Reply #4 on: June 09, 2014, 09:31:45 pm »
Thanks for the info.

As I don't have any access to a unicode version of Delphi, I wrongly thought the default format for the source code was UTF16 in this case.

So, it's only true for very old versions of Delphi, with source code in ANSI format.

tk

  • Sr. Member
  • ****
  • Posts: 364
Re: Same source for Delphi and Lazarus
« Reply #5 on: June 13, 2014, 02:40:46 pm »
Thank you for replies.
Yes I had to modify all strings in forms to English because my Delphi XE encodes forms in UTF16 and Lazarus in UTF8 (or is there an option in Delphi to switch dfm encoding to UTF8?).
Further I had to implement missing properties in Lazarus, I made extra package with dummy controls for alphacontrols and a unit alias for Teechart, im my case.

After this work (which took me almost one week) I was able to compile both from Delphi and Lazarus from the same source code. And this was the goal.
I realized that for controls available in Delphi with no exact counterpart in lazarus you better set as much properties and events in pas files, not in dfm files.
For example TeeChart/TAChart.
Much easier to set properties and events in code (differently for Delphi and Lazarus with IFDEFs) than to make some special TeeChart compatibility control for Lazarus.

EDIT: And of course when doing this a version tracking tool is a must, to see the differences in dfm files when either Lazarus or Delphi messes them up...

tk
« Last Edit: June 13, 2014, 02:45:23 pm by tk »