Forum > Windows

commctrl.pp bug ?

(1/1)

440bx:
Hello,

I came across this definition of an inline macro that seems "suspicious", it 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";}};} ---// Macro 160// #define TreeView_GetItemRect(hwnd, hitem, prc, code) \//     (*(HTREEITEM *)prc = (hitem), (BOOL)SNDMSG((hwnd), TVM_GETITEMRECT, (WPARAM)(code), (LPARAM)(RECT *)(prc))) Function TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM; code : WPARAM; prc : pRECT):BOOL;inline;Begin HTREEITEM(prc):=HITEM; Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, code, LPARAM(prc)));end; Function TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM; var prc : TRECT;code : Bool):BOOL;inline;Begin HTREEITEM(Pointer(@prc)^):=HITEM; Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, WPARAM(code), LPARAM(@prc)));end;  Note that "code" (in line 2) is the last parameter in the macro but, in the definition in line 5, the last parameter is "prc" instead of "code".

Also, on line 7, the parameter "prc" is being assigned the value of "hitem" (typed in capitals instead of in lowercase, which can cause confusion.) "prc" should not be set to "hitem" the _contents_ of "prc" should be set to "hitem".  IOW, in like 7, "prc" should be dereferenced to set the _value_ of the rectangle to "hitem" (as is done in line 13)


marcov:
Ouch, that is long ago, 2003 or so, with FPC 1.1, maybe 1.9. It was done by some heuristic based header translation tool specifically for this header that tried to propagate types back into the macro/inline procedure definition parameter line based on the casts in the sendmessage. Biggest header translation I've ever (manually) done.

I think you are right on both counts, fixed it to follow the original code.


--- 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 TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM;  prc : pRECT; code : WPARAM):BOOL;inline;Begin PHTREEITEM(prc)^:=HITEM; Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, code, LPARAM(prc)));end; 

440bx:

--- Quote from: marcov on May 07, 2022, 10:16:30 pm ---fixed it to follow the original code.

--- End quote ---
Another bug bites the dust :)

marcov:
Yeah, thanks. It probably will not be the last in that unit, that was quite an involved translation

Navigation

[0] Message Index

Go to full version