Recent

Author Topic: Question about overloaded procedures/functions  (Read 456 times)

HotShoe

  • New Member
  • *
  • Posts: 36
Question about overloaded procedures/functions
« on: November 13, 2024, 08:02:04 pm »
First, this is all being run on a Ryzen 7 laptop with 32G memory, 512g ssd and 1TB hd running KDE Neon Linux. I have Lazarus & FPC installed from .deb packages from here, and I have a separate laz/fpc install via fpcupdeluxe for cross compiling. both installs are isolated.

I hate to be a pain in the butt. I am working on the Ale editor that is part of the DT package from previous posts. So I am again working on a console application using Ncurses for cursor control and framed windows.

I want to use the newer nk keys for input (nkup, nkend, nkhome, etc) These are returned as integer values instead of characters for a more useful range. Using the edit function of the TnWindow object, I can't get the overlaid function that returns the last keystroke as an integer.

These are the overlaid functions of edit in the TnWindow object:
Code: Pascal  [Select][+][-]
  1. Function Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : integer) : String;
  2. Function Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  3. Function Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  4. Function Edit(x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  5. Function Edit(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  6. Function Edit(x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;
  7.  
The parser is complaining about expecting a char instead of an integer. So, the parser is not seeing the instance that uses an integer instead of a char.... but it is seeing all of them as seen in the attached screenshot of the messages window.

I have solved this for the present time by making my own version of the Ocrt unit including Ncrt.inc file. I have renamed each instance and corrected the code to match.

Code: Pascal  [Select][+][-]
  1. Function EditSi(x,y,att,z,CursPos:Integer;es:String;Var ch : integer) : String;
  2.  Function EditLi(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : integer) : LongInt;
  3.  Function EditRi(x,y,att,z,CursPos:Integer;es:Real;Var ch : integer) : Real;
  4.  Function EditSch(x,y,att,z,CursPos:Integer;es:String;Var ch : Char) : String;
  5.  Function EditLch(x,y,att,z,CursPos:Integer;es:LongInt;Var ch : Char) : LongInt;
  6.  Function EditRch(x,y,att,z,CursPos:Integer;es:Real;Var ch : Char) : Real;

These in turn call the variants in ncrt.inc. Is there a way to force a variant to be used? In the past overloaded variants just worked without any intervention. I understand that the old console stuff is not used nearly as often as Lazarus and the LCL stuff.

I am only reporting this here in the hope that it may help others in the future. I know laz is the present and future and I would not be finding these little things if I hadn't decided to revisit an old project that I may be the only one that ever uses. I have attached a test project to demonstrate the problem.

Thanks,
--- Jem


Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1235
Re: Question about overloaded procedures/functions
« Reply #1 on: November 14, 2024, 01:51:25 am »
What do the hints say? Also have you tried using OVERLOAD after the procedure declarations?
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

HotShoe

  • New Member
  • *
  • Posts: 36
Re: Question about overloaded procedures/functions
« Reply #2 on: November 14, 2024, 02:28:24 am »
What do the hints say? Also have you tried using OVERLOAD after the procedure declarations?
Click on the screenshot I attached and see.

Also have you tried using OVERLOAD after the procedure declarations?
I agree! I think you should get right on that.

Thanks,
--- Jem

TRon

  • Hero Member
  • *****
  • Posts: 3650
Re: Question about overloaded procedures/functions
« Reply #3 on: November 14, 2024, 05:30:35 pm »
fwiw this is driving me nuts as well.

Created my own routines doing exactly the same and that works. But, the pesky tnWindow object from oCrt unit keeps resisting for some reason  :o

edit:
Change your declaration:
Code: Pascal  [Select][+][-]
  1. var
  2.    i : longint;
  3.    ci,
  4.    rows,
  5.    cols : integer;
  6.  
into
Code: Pascal  [Select][+][-]
  1. var
  2.    i : longint;
  3.    ci,
  4.    rows,
  5.    cols : smallint;
  6.  

reason:
Mode objfpc changes the sizes of the integers while the oCrt unit is not using mode objfpc. So the sizes of the integers between the different units differ.
« Last Edit: November 14, 2024, 06:38:25 pm by TRon »
This tagline is powered by AI (AI advertisement: Free Pascal the only programming language that matters)

 

TinyPortal © 2005-2018