Recent

Author Topic: Delphi to Lazarus Forms  (Read 8005 times)

cycle

  • Newbie
  • Posts: 6
Delphi to Lazarus Forms
« on: July 19, 2023, 07:35:34 pm »
I have a legacy Delphi application that I want to convert to Lazarus.  It is critical to some of our systems so I need to continue to support it.  I have performed the conversion process and the application is now a Lazarus application.  It uses Visual Forms Inheritance and that all seems to be working.  The application compiles and runs as designed.  There is one problem though.  When I bring the main form up in the Lazarus Form Designer, all of the components on the form are not where they belong.  Many of them are clumped together without proper spacing making them very hard to deal with.  I need to add some additional components to the form but this situation makes that impossible.  Is this a known issue with the Lazarus Form Designer?  I am using Lazarus 2.2.6 on Windows 11.  Both my Dell laptop and my Dell monitor are 4K with the laptop using 200% scale and the monitor using 125% scale.  Any suggestions would be greatly appreciated.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4660
  • I like bugs.
Re: Delphi to Lazarus Forms
« Reply #1 on: July 20, 2023, 10:56:36 am »
Designing with a scaled display can be tricky. I don't even know what is the recommended way to deal with it.
You should use anchors extensively. View -> Anchor Editor.
Anchor all components to each other and to form edges. It will also help when you compile your application for a different widgetset / OS. Window managers and widget libraries can have different border widths in their controls. Anchors ensure the layout looks good with them all.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

BrunoK

  • Hero Member
  • *****
  • Posts: 762
  • Retired programmer
Re: Delphi to Lazarus Forms
« Reply #2 on: July 20, 2023, 11:10:23 am »
Question that come to mind (I suppose the answer is yes) did you specify Use LCL scaling + DPI awareness on in project options ?

Maybe you could post a simplified form (.pas+ .lfm) down form showing the problem here so one might take a look at what may happen.

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Delphi to Lazarus Forms
« Reply #3 on: July 20, 2023, 12:57:13 pm »
To understand what's going on I wrote a simple project in Delphi 7, switched my Windows to a user which runs at 144ppi (150%, my normal resolution is 96ppi (100%)) and converted the Delphi project to Lazarus there. I noticed that the converter does not handle LCL scaling at all. This means that when I create an exe at the 144ppi  resolution and run it at a 96ppi the application will not scale.

Therefore, I'd suggest to open the project options after the conversion and to check the boxes "Use LCLScaling" and "Use manifest resource" as well as to select one of the "on" settings in the "DPI awareness" combobox - this is the standard procedure how to create a high-dpi aware application. When I handle the application like this is scales correctly at the resolutions in my test.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4660
  • I like bugs.
Re: Delphi to Lazarus Forms
« Reply #4 on: July 20, 2023, 05:51:36 pm »
... and to check the boxes "Use LCLScaling" and "Use manifest resource" as well as to select one of the "on" settings in the "DPI awareness" combobox - this is the standard procedure how to create a high-dpi aware application.
Should Delphi converter add those settings always for every project?
Then a question arises: When should those settings be off? Is there a situation where high-dpi awareness is not desired?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

cycle

  • Newbie
  • Posts: 6
Re: Delphi to Lazarus Forms
« Reply #5 on: July 20, 2023, 08:51:27 pm »
Thank you for the suggestions.  Since this is the first time I have used Lazarus, I am flying a little blind on how the Lazarus Forms Designer works and why it is behaving the way it does.  I had to do some experimentation to get to this point.

For example, to get the code for some of my units to compile, I had to add {$MODE DELPHI} and to get the Visual Forms Inheritance to work, I had to use the original Delphi .dfm files with the {$R *.dfm}  directive in the associated units.  Doing this enables the application to to compile and run as expected regardless of scaling.  The problem is the Lazarus Form Designer.  It does not seem to understand how to render the components on the main form and the main form is very complex with multiple levels of tabs and probably at least 1000 components for data entry.

I have attached two screen shots, one of the running application compiled and built with Lazarus which works perfectly, and the other in the Lazarus Forms Designer which is a mess.  I need to add some components in the Lazarus Forms Designer for new features, however, that does not seem possible because the Lazarus Forms Designer seems to be confused.

Any suggestions on how to get the Lazarus Forms Designer to render the form correctly so that I can edit the form?

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Delphi to Lazarus Forms
« Reply #6 on: July 20, 2023, 09:34:24 pm »
... and to check the boxes "Use LCLScaling" and "Use manifest resource" as well as to select one of the "on" settings in the "DPI awareness" combobox - this is the standard procedure how to create a high-dpi aware application.
Should Delphi converter add those settings always for every project?
Then a question arises: When should those settings be off? Is there a situation where high-dpi awareness is not desired?
I think current Delphi has its own high-dpi handling now, and it can be assumed that it is not compatibile with how we do it. Therefore I would not suggest to use these settings by default. But it would be a good idea to have an checkbox "activate LCL scaling" among the other converter options. Then the user can decide on what to do, in the same way as he can decide on "Add defines simulating Delphi 7" or "Make backup of changed files".

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Delphi to Lazarus Forms
« Reply #7 on: July 20, 2023, 10:02:44 pm »
Since this is the first time I have used Lazarus, I am flying a little blind on how the Lazarus Forms Designer works and why it is behaving the way it does. 
Going into detail you'll find that there are many differences between Delphi and Lazarus, and I think you absolutely must create several projects in Lazarus before approaching conversion of Delphi projects.  Pick one of your simplest Delphi projects, ideally with a single form only, and try to achieve the same functionality by rewriting it from scratch in Lazarus. In the next step try to convert this simple Delphi project to Lazarus and learn about the conversion. Then repeat with more complex projects. Without being familiar with Lazarus at least to some introductory degree you will soon become disappointed... Converting a project with form inheritance and 1000 controls per form really is not an easy job.

To make sure: Do you use the Delphi converter of the Lazarus IDE to migrate the Delphi project to Lazarus, or do you convert manually? From which Delphi version are you converting? At which screen pixel density were the original forms created? And what is the resolution of the monitor at which Lazarus runs? I need this information to be able to simulate the situation, and to give you precise advice.

I had to use the original Delphi .dfm files with the {$R *.dfm}  directive in the associated units.
Do you plan to access the project again in Delphi after you converted it to Lazarus? Then using the .dfm files in Lazarus is not a good idea, because Lazarus adds a few properties to it which Delphi cannot understand, and thus you will not be able to open the forms in Delphi any more... Better to copy the *.dfm files to *.lfm files and to replace the {$R *.dfm} directive by {$R *.lfm} or, if you want to reuse the same form in Delphi by {$IFDEF FPC}{$R *.lfm}{$ELSE}{$*.dfm}. The Delphi converter should do this when set up appropriately.

I need to add some components in the Lazarus Forms Designer for new features
Don't do this before the converted form is working correctly.

Do the projects that you want to convert to use in Lazarus contain any third-party components? Even built-in components in newer Delphi versions may not exist in Lazarus! If this is the case you first must make sure that each component has a counterpart in Lazarus and is working (in Lazarus components are compiled into the IDE, and if they don't work they may crash the IDE!). If there is no Lazarus version of the used components you must seek replacement components. Ask here for help on finding replacement components. If there is no way for you how to handle all  components you cannot convert the project, as simple as that - any effort will be wasted time.

cycle

  • Newbie
  • Posts: 6
Re: Delphi to Lazarus Forms
« Reply #8 on: July 21, 2023, 12:09:02 am »
Quote
Don't do this before the converted form is working correctly.

The application works correctly.  It compiles and runs correctly.  The Lazarus Forms Designer just cannot seem to handle it.

At this point, I want to be very honest.  I was really hoping that there would be a really easy way to convert this one form Delphi 6 app to Lazarus without having to do a lot of digging and refactoring.  It only uses plain vanilla Delphi 6 components.  Nothing special.  No database stuff.  No third party anything.  It just has a lot of components within tabs on the one form.  I would love to get it running and supported in Lazarus but it makes little sense if it is going to require me to spend a lot of time.  If Lazarus cannot handle this and I am going to need to spend a lot of time refactoring it, then I am just going to rewrite it in something else.

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Delphi to Lazarus Forms
« Reply #9 on: July 21, 2023, 01:06:39 am »
Delphi 6, no database, no third-parties - these are good news. I cannot imagine that this cannot be handled.

Could you upload the Delphi "monster" form here? you can remove all the code. I just want to play with it so that I can give you detailed instructions how to convert this correctly so that LCLScaling is not broken.
Please pack the dfm file and the associated pas file into a zip which you can upload here.

And did I understand your earlier post correctly, that your Lazarus machines have resolutions of 125% and 200%?

Boleeman

  • Hero Member
  • *****
  • Posts: 1091
Re: Delphi to Lazarus Forms
« Reply #10 on: July 21, 2023, 06:18:11 am »
I have been playing with the inbuilt Delphi to Lazarus converter to convert some interesting Delphi programs. I noticed that the GUI's were a bit mixed up so I did:

Using Lazarus I converted the code and copied the code to a plain text file.
Then I created a new Lazarus Application and redid the GUI using components in Lazarus.
Lastly I pasted the converted code to the relevant parts.
Seems to work on 3/4 of the projects I have worked on so far.

« Last Edit: July 21, 2023, 06:26:45 am by Boleeman »

BrunoK

  • Hero Member
  • *****
  • Posts: 762
  • Retired programmer
Re: Delphi to Lazarus Forms
« Reply #11 on: July 21, 2023, 06:58:46 am »
Maybe delphi always forces 96 dpi  when storing the .dfm.
It is something I was trying to evaluate if it could be implemented in lazarus.
Being able to save at 96 dpi (or something else intentionnaly) would solve quite a few troubles when submitting patches.

BrunoK

  • Hero Member
  • *****
  • Posts: 762
  • Retired programmer
Re: Delphi to Lazarus Forms
« Reply #12 on: July 21, 2023, 07:03:03 am »
That check box form makes me think that it is built at run time in 96 dpi measurment.

wp

  • Hero Member
  • *****
  • Posts: 13336
Re: Delphi to Lazarus Forms
« Reply #13 on: July 21, 2023, 10:41:22 am »
Maybe delphi always forces 96 dpi  when storing the .dfm.
Delphi - like Lazarus - writes the designtime ppi to the dfm file. This is like the measurement unit of the size and position values of the controls on the form. Since the default is 96ppi Lazarus assumes this vaflue when DesignTimePPI is missing in the lfm (dfm) file.

cycle

  • Newbie
  • Posts: 6
Re: Delphi to Lazarus Forms
« Reply #14 on: July 27, 2023, 05:16:53 pm »
Okay, after much experimenting, I think I have found the problem.  Apparently, the DesignTimePPI property in Lazarus for my form is set to 192.  If I try to change it, it gets reset back to 192.  Regardless of what I do, Lazarus believes it should be 192.  Can someone tell me how to tell Lazarus to allow me to reset this value?

 

TinyPortal © 2005-2018