Forum > General
Incompatible type for arg... address of function.... is nested
440bx:
Hello,
I am porting some Delphi 2 code which compiles and runs fine (that is, on the platform it was built to run on.) I am getting the following error from FPC:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---(5089,66) Error: Incompatible type for arg no. 2: Got "<address of function(LongInt;LongInt;LongInt):LongInt is nested;StdCall>", expected "<procedure variable type of function(LongInt;LongInt;LongInt):LongInt;StdCall>"the parameter types and result all seem fine but, the message has "is nested" after the function result.
The function isn't nested into another function or procedure. It's a normal function.
What is the meaning of "is nested" and what am I supposed to change to make it acceptable to FPC ?
just in case it helps, the error takes place on the line that calls SetWindowsHookEx:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- case Captured of TRUE: begin Scroll32Hook := SetWindowsHookEx(WH_MSGFILTER, @ScrollHookMsgFilter, 0, { local hook } GetCurrentThreadId); end; FALSE: begin if Scroll32Hook <> 0 then UnhookWindowsHookEx(Scroll32Hook); Scroll32Hook := 0; end; end; { case Captured }
the hook function is:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function ScrollHookMsgFilter(Code : longint; wParam : ptrint; Msg : ptrint) : ptrint; stdcall;var MsgPtr : PMsg absolute Msg; BoxInfoPtr : PBoxInfo; begin BoxInfoPtr := pointer(GetWindowLong(GetCapture, 0)); with BoxInfoPtr^, MsgPtr^ do begin Scroll32PosB := Pt; ScreenToClient(hWnd, Scroll32PosB); end; Result := 0;end;
NOTE: I'm currently porting it to FPC in 32bit. I am not yet focusing on changing the data types and function calls to make it runnable in 64bit (e.g, GetWindowLong to GetWindowLongPtr, etc.)
Thank you for your help.
marcov:
Nested procvars are a separate type of proc/methods vars.
So you have normal procedures variables for global functions, procedure "of object" for methods, and "is nested" for nested functions.
Nested functions are a bit like method vars, in that the procvars are two pointers and have limited validity.
* method vars contain code: function address and data :self, and validity till the object is freed.
* nested procvar contain code: function address and data: framepointer, and validity till the outer procedure is finished and the framepointer is thus no longer valid
In short, it is is a fairly pascal specific feature, and I doubt it will be of use in windows interfacing. I suspect you are accidentally trying to passa nested function to something expecting a global function, and you are not in {$mode delphi}
jamie:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function SetWindowsHookEx(idHook:longint; lpfn:HOOKPROC; hmod:HINST; dwThreadId:DWORD):HHOOK;
Try Casting around your address of your callback...
HOCKRPOC(@YourcallBack)
440bx:
--- Quote from: marcov on March 12, 2019, 10:06:47 pm ---Nested procvars are a separate type of proc/methods vars.
So you have normal procedures variables for global functions, procedure "of object" for methods, and "is nested" for nested functions.
Nested functions are a bit like method vars, in that the procvars are two pointers and have limited validity.
* method vars contain code: function address and data :self, and validity till the object is freed.
* nested procvar contain code: function address and data: framepointer, and validity till the outer procedure is finished and the framepointer is thus no longer valid
In short, it is is a fairly pascal specific feature, and I doubt it will be of use in windows interfacing. I suspect you are accidentally trying to passa nested function to something expecting a global function, and you are not in {$mode delphi}
--- End quote ---
@Marco
The thing is, the function is not a method, and is not nested. It's just a plain vanilla function. Nothing special about it other than being called by a hook. I am not in {$MODE DELPHI}, I haven't needed it to specify callbacks in other cases (such as the examples I've given in the bug tracker for various enumeration APIs, none have required {$MODE DELPHI}.)
Maybe there is something in the code that makes it believe the function is nested into another. I'll double check the code.
@Jamie
--- Quote from: jamie on March 12, 2019, 10:12:10 pm ---Try Casting around your address of your callback...
HOCKRPOC(@YourcallBack)
--- End quote ---
Thank you Jamie, that works. I don't see why I have to cast it but, for now, I'll take it. I'm sure that's going to bite me later but, at least for now, I can move forward.
There must be something in the code that is confusing FPC. It will be interesting to find out what it is.
Remy Lebeau:
--- Quote from: 440bx on March 12, 2019, 10:27:27 pm ---The thing is, the function is not a method, and is not nested. It's just a plain vanilla function.
...
There must be something in the code that is confusing FPC. It will be interesting to find out what it is.
--- End quote ---
Kind of hard to judge that when you did not show the full code.
Navigation
[0] Message Index
[#] Next page