Recent

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

440bx

  • Hero Member
  • *****
  • Posts: 4023
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.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14367
  • Sensorship about opinions does not belong here.
:= is not =. That should be enough.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

440bx

  • Hero Member
  • *****
  • Posts: 4023
:= 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.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

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

440bx

  • Hero Member
  • *****
  • Posts: 4023
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.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 4023
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.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • 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 v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

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

 

TinyPortal © 2005-2018