Recent

Author Topic: [SOLVED]Error converting Delphi component to Lazarus  (Read 3178 times)

jraviles

  • Newbie
  • Posts: 6
[SOLVED]Error converting Delphi component to Lazarus
« on: November 02, 2018, 10:45:48 pm »
Hello. I use a component called TAutoUpdate which updates and implements executable updates of a project via FTP, the component and the sources are in this repository for anyone who wants to use it a lot: https://bitbucket.org/redid_software/autoupdate/src/master/Lazarus/ in Dephi it works perfectly. Before long I started to convert some Delphi projects to Lazarus and I started with my components, the visual components I was able to convert normally, but this specific component, TAutoUpdate, is presenting an error when compiling the line 704 Client.OnWorkBegin: = FTPWorkBegin; Already tried to pass as pointer Client.OnWorkBegin: = @FTPWorkBegin; change the parser to Delphi mode, but nothing worked. Help me I do not dominate component building, I really do not know what I'm doing wrong.

Thank you.
« Last Edit: November 06, 2018, 11:55:36 am by jraviles »

Akira1364

  • Hero Member
  • *****
  • Posts: 563
Re: Error converting Delphi component to Lazarus
« Reply #1 on: November 03, 2018, 04:33:11 am »
In the Lazarus version of Indy, TWorkBeginEvent and TWorkEvent are declared like this:

Code: Pascal  [Select][+][-]
  1. TWorkBeginEvent = procedure(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64) of object;
  2. TWorkEvent = procedure(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64) of object;

However, in your component, the FTPWorkBegin and FTPWork event handlers from the TAutoUpdate class you're trying to use are declared like this:

Code: Pascal  [Select][+][-]
  1. procedure FTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Int64);
  2. procedure FTPWork(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Int64);

The difference being that the Int64 fields are marked const in your code, but Indy is expecting procedures without the const specifier. If you just switch them to not be const, the package compiles and installs fine (I tried it myself).
« Last Edit: November 03, 2018, 07:24:40 am by Akira1364 »

jamie

  • Hero Member
  • *****
  • Posts: 6880
Re: Error converting Delphi component to Lazarus
« Reply #2 on: November 03, 2018, 02:56:39 pm »
more than likely he isn't using the DELPHI mode switch, which makes naming a little more flexible.
The only true wisdom is knowing you know nothing

Thaddy

  • Hero Member
  • *****
  • Posts: 16832
  • Ceterum censeo Trump esse delendam
Re: Error converting Delphi component to Lazarus
« Reply #3 on: November 03, 2018, 04:21:29 pm »
Not in this case. const is necessary for his problem (and never related to incompatibilities between objfpc and delphi mode!)
Maybe Delphi is using a newer version of the underlying library. const is a common later optimization.
Maybe Remy knows?
« Last Edit: November 03, 2018, 04:25:14 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Akira1364

  • Hero Member
  • *****
  • Posts: 563
Re: Error converting Delphi component to Lazarus
« Reply #4 on: November 03, 2018, 05:27:32 pm »
more than likely he isn't using the DELPHI mode switch, which makes naming a little more flexible.

He said he tried that, actually. That kind of thing (differing method signatures for callbacks) never worked in any version of Delphi either though (correctly so.) In Delphi it would give an error that says "Incompatible types: Parameter lists differ".

Anyways, as I suggested, literally all he needs to do is remove the two "consts" from the procedure headings in his code.
« Last Edit: November 03, 2018, 08:20:06 pm by Akira1364 »

jraviles

  • Newbie
  • Posts: 6
Re: Error converting Delphi component to Lazarus
« Reply #5 on: November 06, 2018, 11:55:20 am »
Good morning everyone I followed what was said and the package compiled perfectly, now I'm going to make some adjustments because it seems to me that Indy for Lazarus has some different behaviors from Indy to Delphi, the component works but, with some errors. Thank you very much for your help, Akira, Jamie, Thaddy, thank you very much you showed me the north.

Thaddy

  • Hero Member
  • *****
  • Posts: 16832
  • Ceterum censeo Trump esse delendam
Re: Error converting Delphi component to Lazarus
« Reply #6 on: November 06, 2018, 02:47:20 pm »
more than likely he isn't using the DELPHI mode switch, which makes naming a little more flexible.

He said he tried that, actually. That kind of thing (differing method signatures for callbacks) never worked in any version of Delphi either though (correctly so.) In Delphi it would give an error that says "Incompatible types: Parameter lists differ".

Anyways, as I suggested, literally all he needs to do is remove the two "consts" from the procedure headings in his code.
I believe newer Indy for Delphi has the const modifier, but not in the FPC Indy (which lags). As I read it, HE did not introduce the const...
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

 

TinyPortal © 2005-2018