Recent

Author Topic: Trying to port the ConsoleIO unit to Lazarus  (Read 4711 times)

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Trying to port the ConsoleIO unit to Lazarus
« on: January 29, 2020, 09:37:50 am »
Hello! I try to port to Lazarus a Delphi unit named ConsoleIO. The unit doesn't compile. I know that I could use the Process unit for the same task, but I would like to understand why the unit doesn't compile.

Here is the unit and the lazarus project (unfinished).

The error I get is

Quote
consoleio.pas(278,36) Error: Incompatible type for arg no. 3: Got "<address of procedure(TConsoleIO);Register>", expected "<procedure variable type of function(Pointer):Int64;Register>"
Hint: Found declaration: BeginThread(Pointer;QWord;TThreadFunc;Pointer;LongWord;var QWord):QWord;

Would you have an idea of the way to solve this issue?

Thanks.
My projects are on Gitlab and on Codeberg.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #1 on: January 29, 2020, 09:57:03 am »
First, the code you included is already mutilated beyond repair by you. So post the original.
My guess is that a simple Delphi project containing the unit will be automatically converted using the convert delphi project option. That will also convert ConsoleIO.pas.
{Actually that is not a guess...}
Anyway, you also need to add {$mode delphi}{$H+}
Specialize a type, not a var.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #2 on: January 29, 2020, 09:59:34 am »
When converting from Delphi it is always a good idea to first add the {$MODE DELPHI} directive at the top. Doing this, and removing the @ in Classes.AllocateHWnd(@WndProc) made the unit compile for me; I did no functional tests, though.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #3 on: January 29, 2020, 10:24:19 am »
@wp
It works, I tested it if that was not already obvious.. :)
Specialize a type, not a var.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #4 on: January 29, 2020, 10:30:07 am »
Thank you for your answers.

I will finish my demo project to see if all is OK.

By the way, the original package (with its demo project) is included in the composant/archive folder. It's true that I should have tried an automatic conversion starting from the original source. I will try.

Regards.

Roland
« Last Edit: January 29, 2020, 10:32:06 am by Roland57 »
My projects are on Gitlab and on Codeberg.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #5 on: January 29, 2020, 10:34:24 am »
If not, report back and I show you my minimal changes that work.
Specialize a type, not a var.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #6 on: January 29, 2020, 10:57:29 am »
If not, report back and I show you my minimal changes that work.

I finished a first draft of my project but I get a runtime error 211.

If you have a working version, I am your friend.  :)

I have to leave. See you later!
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #7 on: January 30, 2020, 07:38:17 am »
Hello! I restarted from the original source and made an automatic conversion. I removed from the *.lfm the part related to the component, and removed the register procedure in the unit. I added code for component creation in FormCreate.

The project compiles but I get an error 211 when I start the application. I don't see what is wrong.

Here is the source of the project.
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #8 on: January 30, 2020, 08:14:10 am »
Maybe there is a relation with what is said in this message?

https://forum.lazarus.freepascal.org/index.php/topic,46477.msg332924.html#msg332924
My projects are on Gitlab and on Codeberg.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #9 on: January 30, 2020, 08:20:24 am »
211 is an abstract error and there are no abstracts in the ConsoleIO unit.
The consoleIO unit itself seems correct, but only for 32 bit Windows. You need change the integer cast for the procedure pointer  to PtrInt or PtrUint for it to work on both 32 and 64 bit Windows.
I did not examine the rest of the project yet.
« Last Edit: January 30, 2020, 08:27:17 am by Thaddy »
Specialize a type, not a var.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #10 on: January 30, 2020, 08:30:50 am »
211 is an abstract error and there are no abstracts in the ConsoleIO unit.
The consoleIO unit itself seems correct, but only for 32 bit Windows. You need change the integer cast for the procedure pointer  to PtrInt or PtrUint for it to work on both 32 and 64 bit Windows.
I did not examine the rest of the project yet.

Thank you for your message. I already did that. It seems that the problem comes from AllocateHWnd, and it seems that a solution is given here:

https://forum.lazarus.freepascal.org/index.php/topic,36449.msg243056.html#msg243056

Now I can start the application without error.
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
My projects are on Gitlab and on Codeberg.

Roland57

  • Sr. Member
  • ****
  • Posts: 421
    • msegui.net
Re: Trying to port the ConsoleIO unit to Lazarus
« Reply #12 on: January 30, 2020, 07:36:44 pm »
Here is the corrected version of the unit, with a demo project.

My projects are on Gitlab and on Codeberg.

 

TinyPortal © 2005-2018