Recent

Author Topic: Convert Errors Delphi -> Lazarus  (Read 2790 times)

Moombas

  • New Member
  • *
  • Posts: 24
Convert Errors Delphi -> Lazarus
« on: August 20, 2019, 11:47:15 am »
Hi there,

I am new to Lazarus and I am coming from Emba Delphi Rio 10.3.2. I have to change because of decision of the company.
Now i tryed to Convert my Delphi Projekt into Lazarus, but there seem to be something todo for me manually.

1. I tryed to convert the unit, but i get two errors:
   A.: Problem when trying to repair the form file C:\....\*.lfm
   B:  Converting failed // i think because of the Problem above
2. I tryed to convert the project:
   A. Units missing: Vcl.Forms, Vcl. Themes, Vcl.Styles   //I are there Units from Lazarus to replace these (LCL.Forms or like that?)
   if I skip them i got additional:
   B. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System. Classes, Vcl.Graphics, Vcl.Controls, Vcl.Dialogs, Vcl.StdCtrls,
       Vcl.ComCtrls, Vcl.Grids, Vcl.ExtCtrls, System. UITypes, Data.DB, Vcl. DBGrids, System.StrUtils, FireDAC.Stan.Intf, FireDAC.Stan.Option,
       FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
       FireDAC.Phys.MySQL, FireDAC.MySQL.Def, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
       System.Win.Registry, FireDAC..Comp.Dataset, FireDAC.Client

Can someone tell me what to do or where i can find information to fix this to use in Lazarus?

Ok, i think most of them i could fix, but the firedac are missing and the "Problem when trying to repair the form file C:\....\*.lfm" is the most significant one which i can't fix.
« Last Edit: October 08, 2019, 03:41:20 pm by Moombas »
The path is the destination but you should never lose sight of the destination on the way.

k1ng

  • New Member
  • *
  • Posts: 36
Re: Convert Errors Delphi -> Lazarus
« Reply #1 on: August 20, 2019, 02:21:32 pm »
   B. Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System. Classes, Vcl.Graphics, Vcl.Controls, Vcl.Dialogs, Vcl.StdCtrls,
       Vcl.ComCtrls, Vcl.Grids, Vcl.ExtCtrls, System. UITypes, Data.DB, Vcl. DBGrids, System.StrUtils, FireDAC.Stan.Intf, FireDAC.Stan.Option,
       FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
       FireDAC.Phys.MySQL, FireDAC.MySQL.Def, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
       System.Win.Registry, FireDAC..Comp.Dataset, FireDAC.Client

  • I'm not sure but I think FPC/Lazarus don't know namespaces, so Winapi.Windows should become Windows to get it compiling
  • FireDAC is an Embarcadero thing, so guess you would need to rewrite the code using mORMot, ZeosLib or with one of the included library in FPC
  • the VCL replacement in Lazarus is the LCL

valdir.marcos

  • Hero Member
  • *****
  • Posts: 822
Re: Convert Errors Delphi -> Lazarus
« Reply #2 on: August 20, 2019, 03:33:43 pm »
I am new to Lazarus and I am coming from Emba Delphi Rio 10.3.2. I have to change because of decision of the company.
Now i tryed to Convert my Delphi Projekt into Lazarus, but there seem to be something todo for me manually.
...
Can someone tell me what to do or where i can find information to fix this to use in Lazarus?
I think you should step back and learn a little more about Lazarus before converting your Delphi project.
Maybe this information helps you:
https://wiki.freepascal.org/Databases
https://wiki.freepascal.org/SQLdb_Programming_Reference
https://wiki.freepascal.org/SQLdb_Package
https://wiki.lazarus.freepascal.org/SqlDBHowto
https://wiki.freepascal.org/Lazarus_Database_Overview

Moombas

  • New Member
  • *
  • Posts: 24
Re: Convert Errors Delphi -> Lazarus
« Reply #3 on: August 20, 2019, 04:00:59 pm »
I solved it now.
I Removed FireDAC completely and put in the LAzarus Components instead and so the lfm works as fine as suspected.
And the other issues i got solved too ("System." etc. removed).
T hink i have a bit to learn where Lazarus works different from IDE.  ;)
The path is the destination but you should never lose sight of the destination on the way.

wp

  • Hero Member
  • *****
  • Posts: 6231
Re: Convert Errors Delphi -> Lazarus
« Reply #4 on: August 20, 2019, 04:03:48 pm »
I think you should step back and learn a little more about Lazarus before converting your Delphi project.
Absolutely! Begin with small projects and try to learn Lazarus and in particular what is different from Delphi. When you feel comfortable convert small Delphi projects to Lazarus using only VCL classes (no fancy database and third-party stuff). The basic conversion principles are for me:
  • Remove the namespaces
  • Rename the form's dfm file to lfm (but keep the original). Rewrite the {$R *.dfm} to {$R *.lfm}
  • Rename the dpr project file to lpr (but keep the original). Add  "InterfaceBase" as first unit to the uses clause.
  • Write {$mode Delphi} to the head of the unit. You can also use {$mode objfpc}{$H+} but be prepared for some subtle syntax changes.
  • When there is messsage handling rename all WM_* to LM_*, TMessage to TLMessage, TWMLButtonDown to TLMLButtonDown and so on.
  • When you want to keep using your project in Delphi surround all your Lazarus-related changes by an {IFDEF FPC}...your code ...{$ELSE}... original code... {$ENDIF}. This is not so easy is it seems!
  • When you want to make your project cross-platform replace the Windows and Messages units by LCLIntf, LCLType, LMessages, and fight with numerous tiny issues - this is the hardest task. Some projects cannot be made cross-platform without deep understand of the related platforms.
  • All (?) of this work can be handled by the Delphi-to-Lazarus converter. But I never understood what it is doing. And it is more fun to understand what is happening.
  • Third-party libraries cannot be used if you don't have the source code. And even if you have the sources - conversion of libraries is another project on its own... Make up your mind if these libraries are really needed and if they can be replaced by some more-or-less established Lazarus components. Look at the Online-Package-Manager to see what's available (it is a lot!). Using third-party Lazarus packages may make your project not usable in Delphi any more.
« Last Edit: August 20, 2019, 04:08:23 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

valdir.marcos

  • Hero Member
  • *****
  • Posts: 822
Re: Convert Errors Delphi -> Lazarus
« Reply #5 on: August 20, 2019, 05:33:17 pm »
Can someone tell me what to do or where i can find information to fix this to use in Lazarus?
Try to search the Lazaruz Forum as much as you can. There are many great discussions as the one below about converting or migrating Delphi projects to Lazarus:
extracting part of a Delphi5 dfm

avra

  • Hero Member
  • *****
  • Posts: 1686
    • Additional info
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Moombas

  • New Member
  • *
  • Posts: 24
Re: Convert Errors Delphi -> Lazarus
« Reply #7 on: August 22, 2019, 08:39:30 am »
All differences have been found and the project now works as in Delphi.
A second project has been transfered succesfully too.

Is there a way that lazarus removes the namespaces (e.g.  "System.") by itself when it transfers the project?
The path is the destination but you should never lose sight of the destination on the way.

Thaddy

  • Hero Member
  • *****
  • Posts: 8911
Re: Convert Errors Delphi -> Lazarus
« Reply #8 on: August 22, 2019, 09:23:55 am »
All differences have been found and the project now works as in Delphi.
A second project has been transfered succesfully too.

Is there a way that lazarus removes the namespaces (e.g.  "System.") by itself when it transfers the project?

Actually you do not have to remove them at all. You can use the -FN compiler option to add the namespaces.
https://wiki.freepascal.org/FPC_New_Features_3.0#Delphi-like_namespaces_units.

(This feature somehow went under the radar of lazarus developers)
« Last Edit: August 22, 2019, 09:35:24 am by Thaddy »
Most people that want to use threading should learn to patch their jeans first: use a needle.

Moombas

  • New Member
  • *
  • Posts: 24
Re: Convert Errors Delphi -> Lazarus
« Reply #9 on: August 22, 2019, 11:29:45 am »
Hmm i wil take a look at this.

I am a bit confused of a malfunction from "movefile"

Lazarus has problems with umlauts (is this the right translation?).  So if i try to copy a file with umlauts, it doesn't work.

How to fix this?
« Last Edit: August 22, 2019, 11:50:00 am by Moombas »
The path is the destination but you should never lose sight of the destination on the way.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7438
Re: Convert Errors Delphi -> Lazarus
« Reply #10 on: August 22, 2019, 01:19:34 pm »
  • Rename the form's dfm file to lfm (but keep the original). Rewrite the {$R *.dfm} to {$R *.lfm}
  • Rename the dpr project file to lpr (but keep the original). Add  "InterfaceBase" as first unit to the uses clause.

dfm and .dpr can be kept. It is not necessary to change this. Only the conversion wizard is still biassed to do this conversion (and similarly to force objfpc on unsuspecting users), but this is no longer necessary, which is why I avoid it as the plague.

I include a .inc file after the 'interface" line in every unit.  I handle mode setting there. (for both fpc and delphi, e.g. in Delphi it turns pointermath on, for FPC compat )

Quote
  • When there is messsage handling rename all WM_* to LM_*, TMessage to TLMessage, TWMLButtonDown to TLMLButtonDown and so on.

But only for GUI related messages (the ones that Lazarus emulates). WM_USER and system messages should be kept WM_

Quote
  • All (?) of this work can be handled by the Delphi-to-Lazarus converter. But I never understood what it is doing. And it is more fun to understand what is happening.

IMHO causes more troubles than it solves. Just open the Dpr, and the forms one by one. If you do it repeatedly (e.g. you keep the main codebase in delphi), look for "dfmcleaner (By Alan Bauer?). Oriignally meant for dfm conversion between delphi versions, you can routinely clean your dfm of certain properties (like dropdownrows below).

I worked on conversion of a simple zeos db app a few weeks back, note I skipped some things that are already fixed, but might not be in release versions.

  • fpc has overloads uppercase/lowercase with char versions. If you get "can't determine which overloaded" like errors on uppercase/lowercase, this is probably it
  • There is no mask unit, it is called maskutils
  • TApplicationEvents becomes TApplicationProperties for some reason which has much fewer options. (solved by instantiation in code)
  • TMonthcalendar doesn't exist, replace with TCalendar with certain options (for me it was mostly about viewing weeknumbers)
  • Using tdbgrid.DrawColumnCell event to change color fails, move the change of color and brush to onpreparecanvas
  • Lazurus supports uitypes, but that doesn't contain anything color related. It should move to FPC anyway. This means that you must colorref from lcltype. There is no alternative for windows.rgb() macro
  • TDBLookupComboBo.dropdownrows is missing
  • Anything IUnknown related requires a lot of fixes due to constref and calling conventions
  • some of application internal benchmarking used queryperformance(). I substituted it with sysutils.gettickcount64 under ifdef linux, but that is ms resolution only.;
  • I used a windows message to shutdown the application asynchronous (which is safer than application.terminate when doing emergency shutdown with many events still flowing) -> change for linux  to application..terminate under ifdef
  • Some components that I used (dcpcrypt and indy) had mixed case filenames -> had to rename them to lower case or make uses clauses match
  • I had some winapi code to capture hotkeys (global keyboard hook). Disabled that for now for Linux.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7438
Re: Convert Errors Delphi -> Lazarus
« Reply #11 on: August 22, 2019, 01:21:17 pm »
Actually you do not have to remove them at all. You can use the -FN compiler option to add the namespaces.
https://wiki.freepascal.org/FPC_New_Features_3.0#Delphi-like_namespaces_units.

Afaik 3.0 has dotted units, but only 3.2 has -FN

wp

  • Hero Member
  • *****
  • Posts: 6231
Re: Convert Errors Delphi -> Lazarus
« Reply #12 on: August 22, 2019, 02:07:46 pm »
But when he keeps Delphi's dotted unit names in the unit then shouldn't the unit files be named in the same way? I doubt that Lazarus is searching for a file "vcl.forms.pas" when "vcl.forms" is in the uses clause.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7438
Re: Convert Errors Delphi -> Lazarus
« Reply #13 on: August 22, 2019, 02:14:55 pm »
But when he keeps Delphi's dotted unit names in the unit then shouldn't the unit files be named in the same way? I doubt that Lazarus is searching for a file "vcl.forms.pas" when "vcl.forms" is in the uses clause.

Yes indeed. -FN works for the opposite case ("forms" in source and vcl.forms on disc).  Manually trimming prefixes , and configuring the prefixes in Delphi to keep it working is the easiest way long term in my experience.

Moombas

  • New Member
  • *
  • Posts: 24
Re: Convert Errors Delphi -> Lazarus
« Reply #14 on: August 22, 2019, 02:52:32 pm »
I Think this is for now not my problem but thanks for the help.

Actually i have these problems on my converted project:

1. A malfunction from "movefile": Lazarus has problems with umlauts.  So if i try to move a file with umlauts, it doesn't work. Is there any way to fix it (or have i work without umlauts)?

Code: Pascal  [Select]
  1.   movefile(PChar(Path + CSVList.Items.Strings[i]), PChar(Path + 'Archiv\' + CSVList.Items.Strings[i]));
  2.  


2. - fixed - logic failure
« Last Edit: August 22, 2019, 03:45:42 pm by Moombas »
The path is the destination but you should never lose sight of the destination on the way.