Recent

Author Topic: [SOLVED] Is there a common way of declaring FPC and Delphi procedural variables?  (Read 2321 times)

440bx

  • Hero Member
  • *****
  • Posts: 6540
Hello,

I cannot find a common way of declaring and using procedural variables that both FPC and Delphi find acceptable.  Everything I've tried, if it's acceptable to one compiler it isn't to the other.

Attached is a sample program that I'd like to be able to compile (and run of course) without having to use {$ifdef FPC}.... {$else}.... {$endif}

In the attached sample, there doesn't seem to be a way to make the following statement (its intent) acceptable to both compilers
Code: Pascal  [Select][+][-]
  1.     // Delphi doesn't like the statement below.  It likes it without the
  2.     // typecast but then FPC doesn't like it if its not there.
  3.  
  4.     pointer(NtQueryInformationProcessPtr)
  5.            := GetProcAddress(NtdllHandle, 'NtQueryInformationProcess');
  6.  

Is there some way of declaring NtQueryInformationProcessPtr that would make both compilers happy (without using {$ifdef}s ?

Thank you for your help.
« Last Edit: April 23, 2019, 07:21:15 pm by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 19272
  • Glad to be alive.
:= is not =. That should be enough.
objects are fine constructs. You can even initialize them with constructors.

440bx

  • Hero Member
  • *****
  • Posts: 6540
:= is not =. That should be enough.
yeah... := is definitely not =.  Now that's out of the way, do you happen to have one way of declaring procedural variables that both compilers would accept ?
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12905
  • FPC developer.
If I leave the pointer() hack out, it works fine with $Mode delphi

440bx

  • Hero Member
  • *****
  • Posts: 6540
If I leave the pointer() hack out, it works fine with $Mode delphi
Is there a way that would not require {$MODE DELPHI} ?

FPC requires the pointer typecast because GetProcAddress returns a pointer.  Without it, there is type mismatch.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 6540
found the solution... simple too...

Code: Pascal  [Select][+][-]
  1.     NtQueryInformationProcessPtr := TNtQueryInformationProcess(
  2.                GetProcAddress(NtdllHandle, 'NtQueryInformationProcess'));
  3.  
That's acceptable to both compilers.   No directives and no modes needed either. 

ETA:

Marco, thank you.  Your comment made me think about typecasting the output of GetProcAddress instead of typecasting the l-value.
« Last Edit: April 23, 2019, 07:22:59 pm by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

ASBzone

  • Hero Member
  • *****
  • Posts: 733
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
found the solution... simple too...

Code: Pascal  [Select][+][-]
  1.     NtQueryInformationProcessPtr := TNtQueryInformationProcess(
  2.                GetProcAddress(NtdllHandle, 'NtQueryInformationProcess'));
  3.  
That's acceptable to both compilers.   No directives and no modes needed either. 

ETA:

Marco, thank you.  Your comment made me think about typecasting the output of GetProcAddress instead of typecasting the l-value.


Inquisitive question, @440bx -- why the need to avoid any directives or mode?   What about them complicates the solution for you?[/size]
-ASB: https://www.BrainWaveCC.com/

Lazarus v4.3.0.0 (bcf314a670) / FreePascal v3.2.3-46-g77716a79dc (aka fixes)
(Windows 64-bit install w/Win32 and Linux on ARM and x64 cross-compilers via FpcUpDeluxe)

My Systems: Windows 10/11 Pro x64 (Current)

 

TinyPortal © 2005-2018