Delphi to Lazarus Forms lazarus / 10-Designer ---------------------------------------------------------------------- cycle · 2023-07-19 17:35 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 · 2023-07-20 08:56 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. ---------------------------------------------------------------------- BrunoK · 2023-07-20 09:10 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 · 2023-07-20 10:57 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 · 2023-07-20 15:51 Quote from: wp on July 20, 2023, 12:57:13 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? ---------------------------------------------------------------------- cycle · 2023-07-20 18:51 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 · 2023-07-20 19:34 Quote from: JuhaManninen on July 20, 2023, 05:51:36 pmQuote from: wp on July 20, 2023, 12:57:13 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 · 2023-07-20 20:02 Quote from: mdlincoln on July 20, 2023, 08:51:27 pmSince 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. Quote from: mdlincoln on July 20, 2023, 08:51:27 pmI 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. Quote from: mdlincoln on July 20, 2023, 08:51:27 pmI 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 · 2023-07-20 22:09 QuoteDon'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 · 2023-07-20 23:06 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 · 2023-07-21 04:18 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. ---------------------------------------------------------------------- BrunoK · 2023-07-21 04:58 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 · 2023-07-21 05:03 That check box form makes me think that it is built at run time in 96 dpi measurment. ---------------------------------------------------------------------- wp · 2023-07-21 08:41 Quote from: BrunoK on July 21, 2023, 06:58:46 amMaybe 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 · 2023-07-27 15:16 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? ---------------------------------------------------------------------- JuhaManninen · 2023-07-27 17:44 Quote from: cycle on July 27, 2023, 05:16:53 pmApparently, the DesignTimePPI property in Lazarus for my form is set to 192.  If I try to change it, it gets reset back to 192. Where do you change it? In Object Inspector? The only way may be to edit the form's .lfm file. Close the project, edit it and then reopen the project. ---------------------------------------------------------------------- cycle · 2023-07-27 19:28 I have tried changing it in the object inspector and in the dfm file but when I open the form editor, it changes it back to 192.  There has to be a way to get the Lazarus Form Designer to work but so far it just will not behave.  This is beyond frustrating. ---------------------------------------------------------------------- JuhaManninen · 2023-07-28 12:40 Quote from: cycle on July 27, 2023, 09:28:04 pmI have tried changing it in the object inspector and in the dfm file but when I open the form editor, it changes it back to 192. Did you have the project closed when editing the dfm file? Close Lazarus and use another text editor to be sure. I can change DesignTimePPI in OI in my test project. I don't know what is going on there. ---------------------------------------------------------------------- wp · 2023-07-28 20:26 Quote from: cycle on July 27, 2023, 05:16:53 pmOkay, 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? Seems like you are working on a machine with 192ppi. Whenever you save a form on this machine all dimensions are valid for 192ppi, and Lazarus MUST write the DesignTimePPI to be 192 - this is the unit of measurement, like centimeters, millimeters or inches. If you remove the DesignTimePPI and you open this form on the same machine the next time, the missing DesignTimePPI is interpreted as if the form were saved on a 96ppi machine. And therefore the IDE recalculates all dimensions found in the form, iow: when a control has a width of 100 px and is saved at 192ppi it will become twice as large when you remove the DesigntimePPI and reopen the form at 192ppi again. If you don't want this automatic rescaling you should turn off the LCLScaling checkbox, or if only single form bothers you, you can also turn off its Scaled property. But don't blame anybody here that the size of the controls changes when you move to a monitor with a different resolution. ---------------------------------------------------------------------- cycle · 2023-08-01 19:31 The part I cannot get past is that if I open the form in Delphi, the Form Designer in the Delphi IDE scales everything properly.  I do not need to tell it anything about the form, the scaling, or the resolution.  It just works.  When I open it in Lazarus, Lazarus is unable to figure out how to properly display the form in the Lazarus Form Designer.  This seems like a huge deficiency. Since I am new to Lazarus, I am willing to concede that I am doing something wrong in Lazarus, however, every suggestion that has been provided has proven ineffectual.  There has to be a way to make the Lazarus Form Designer work just like the Delphi Form Designer.  I cannot believe that what I am asking is impossible.  Basically, if someone can provide the "check this" and "uncheck that" and "assign this or that property value" cookbook recipe, I would be greatly appreciative.