Recent

Author Topic: Velthuis.Console.pas - Won't compile in Lazarus  (Read 4616 times)

Atak_Snajpera

  • New Member
  • *
  • Posts: 31
Velthuis.Console.pas - Won't compile in Lazarus
« on: May 26, 2024, 05:46:24 pm »
Another incompatibility. This time I'm trying to compile project which uses Velthuis.Console.pas
https://i.postimg.cc/zD9Lk4p1/Capture.png

I'm real noob when it comes to porting from old to new code in lazarus.

jamie

  • Hero Member
  • *****
  • Posts: 6874
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #1 on: May 26, 2024, 05:56:32 pm »
There are two defines to chouse from.

 One is a direct variable of your smallRect and the other is a Pointer..

 Type case the questionable Rect like this

 PSmall_Rect(@Rect);
 
 or maybe remove the "@" and try that.

The only true wisdom is knowing you know nothing

cdbc

  • Hero Member
  • *****
  • Posts: 2098
    • http://www.cdbc.dk
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #2 on: May 26, 2024, 05:56:52 pm »
Hi
From the looks of things, you should skip the '@' in the second 'Rect' parameter?!?
The compiler says, it expects a 'smallrect', but gets a pointer(@Rect) instead...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

TRon

  • Hero Member
  • *****
  • Posts: 4305
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #3 on: May 26, 2024, 05:59:25 pm »
The headers are defined incorrectly for that function, at least in jwawincon. I do not know about which include file gets dragged in for windows because the redef.inc file also seem to define the function header incorrect.

Both rects should be pointers to small_rect.

see also ms
Today is tomorrow's yesterday.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12153
  • FPC developer.
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #4 on: May 26, 2024, 06:27:05 pm »
The headers are defined incorrectly for that function, at least in jwawincon. I do not know about which include file gets dragged in for windows because the redef.inc file also seem to define the function header incorrect.

Redef.inc contains overloads for functions that are either specified as VAR in Delphi or at some point in FPC (the original header conversion favoured changing to VAR) and are kept for historic reasons. Most have pointer definitions elsewhere, in this case in ascfun.inc.

440bx and others have pointed out many remaining problems, and each new release a few more are fixed. If you encounter problems, search trunk rtl/win/wininc for the identifier and see if there is a valid prototype (overload selection is a different problem). If there isn't, report a bug.

Thaddy

  • Hero Member
  • *****
  • Posts: 16803
  • Ceterum censeo Trump esse delendam
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #5 on: May 26, 2024, 06:37:00 pm »
I never had problems using Rudy's code in FPC using my own translation for this particular code and have been using it intensively. As long as the declarations are correct - and they are for Delphi style. Maybe constref?
Note that there is also a rect function, not structure, and as far I can recall that causes problems depending on unit order. We can't asked him, because he passed away a couple of years ago, way to young. Good programming friend. We used to work on C++ interop.
I will look up what I did shortly after the date he published it.
There also exist at least two versions of it: one without dotted notation (older) and the onne with the dotted notation. I have both.
« Last Edit: May 26, 2024, 06:43:37 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

TRon

  • Hero Member
  • *****
  • Posts: 4305
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #6 on: May 26, 2024, 06:39:54 pm »
OK, noted marcov. Thank you for the explanation(s).

@Atak_Snajpera

Change line where it reads:
Code: Pascal  [Select][+][-]
  1. ScrollConsoleScreenBufferA(StdOut, Rect, @Rect, NewPos, Fill);
  2.  
to
Code: Pascal  [Select][+][-]
  1.   ScrollConsoleScreenBufferA(StdOut, @Rect, @Rect, NewPos, @Fill);
  2.  

Then the next problem:
Code: Pascal  [Select][+][-]
  1.   ReadPtr := T.BufPtr;
  2.  
to
Code: Pascal  [Select][+][-]
  1.   ReadPtr := PChar(T.BufPtr);
  2.  

Then you would have to implement your own setinoutres procedure (because I was unable to find it implemented for Free Pascal), see also embarcadero and FPC inoutres var

something like:
Code: Pascal  [Select][+][-]
  1. procedure SetInOutRes(NewValue: Integer);
  2. begin
  3.   InOutRes := NewValue;
  4. end;
  5.  

And finally in the WaitForProcess.lpr file:
Code: Pascal  [Select][+][-]
  1.     info:STARTUPINFO;
  2.  
to
Code: Pascal  [Select][+][-]
  1.     info:STARTUPINFOA;
  2.  

And then the code you posted seem to (cross) compile for me.

edit: updated answer to reflect marcov's explanation(s)
« Last Edit: May 26, 2024, 06:57:28 pm by TRon »
Today is tomorrow's yesterday.

Thaddy

  • Hero Member
  • *****
  • Posts: 16803
  • Ceterum censeo Trump esse delendam
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #7 on: May 26, 2024, 07:08:59 pm »
I looked it up. There are very few changes, a cast and a FPC define.
(I already wondered why people had some much trouble with it, sigh, even diehards)
Here is the working code, I tested it and still works:
« Last Edit: May 26, 2024, 07:12:57 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Atak_Snajpera

  • New Member
  • *
  • Posts: 31
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #8 on: May 26, 2024, 07:26:48 pm »
I copied your updated Velthuis.Console.pas and I get this instead
https://i.postimg.cc/PJt8mDTF/Capture.png

Thaddy

  • Hero Member
  • *****
  • Posts: 16803
  • Ceterum censeo Trump esse delendam
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #9 on: May 26, 2024, 07:45:02 pm »
That is very strange, because that is 16 bit code . I compiled 64bit Windows 11. I will have a look.
Found it: The cheeky dentist made it also Delphi 1 compatible.
Corrected version attached. Both of us did not find that in 2008! We also had a Linux version discussed (Kylix), but was never fnished.
Still using 32 bit Windows? Anyway, I kept it still  somewhat Delphi1 compatible.
In honor of the author.
Try this one, I only changed the order of the Winversion test to be exact:
« Last Edit: May 26, 2024, 08:02:23 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

Atak_Snajpera

  • New Member
  • *
  • Posts: 31
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #10 on: May 26, 2024, 08:52:54 pm »
Still the same error. I'm on win7 x64.
https://i.postimg.cc/0NrQqqCj/Capture.png
« Last Edit: May 26, 2024, 08:54:43 pm by Atak_Snajpera »

Thaddy

  • Hero Member
  • *****
  • Posts: 16803
  • Ceterum censeo Trump esse delendam
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #11 on: May 26, 2024, 09:20:15 pm »
No clue and no time: it will compile 32/64 bit and there are no win7 specifics involved.
The code simply compiles for those two targets. You can remove the hardware calls altogether, but I won't do that.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

jamie

  • Hero Member
  • *****
  • Posts: 6874
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #12 on: May 26, 2024, 10:04:44 pm »
Code: Pascal  [Select][+][-]
  1. var
  2.   NewPos:TCoord;
  3.   Fill:TCharInfo;
  4.   Rect:Small_Rect;
  5. begin
  6. //.......
  7. Windows.ScrollConsoleScreenBuffer(StdOutPutHandle, Rect,Rect, NewPos,Fill)
  8. end;                                                                         [
  9. [code]
  10.  
  11. Compiles.
  12.  
« Last Edit: May 26, 2024, 10:06:51 pm by jamie »
The only true wisdom is knowing you know nothing

Fibonacci

  • Hero Member
  • *****
  • Posts: 669
  • Internal Error Hunter
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #13 on: May 26, 2024, 10:18:04 pm »
Still the same error. I'm on win7 x64.
https://i.postimg.cc/0NrQqqCj/Capture.png

Try adding "assembler" keyword, like this:

Code: Pascal  [Select][+][-]
  1. procedure xxx; assembler;
  2. asm
  3. // ...
  4. end;

And {$asmmode intel} somewhere at the top
« Last Edit: May 26, 2024, 10:20:24 pm by Fibonacci »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12153
  • FPC developer.
Re: Velthuis.Console.pas - Won't compile in Lazarus
« Reply #14 on: May 26, 2024, 10:19:53 pm »
If you try to get Delphi code compiling, make sure you use {$mode delphi}

 

TinyPortal © 2005-2018