How i can cast a WNDPROC
to a TWndMethod
so far i try this but give me a invalid typecast
error.
TWndMethod(Pointer(GetWindowLong(FHandle, GWL_WNDPROC)));
How i can cast a WNDPROC
to a TWndMethod
so far i try this but give me a invalid typecast
error.
TWndMethod(Pointer(GetWindowLong(FHandle, GWL_WNDPROC)));
If you want to subclass a window handle (using SetWindowLong) to process window messages in TWndMethod function, you should not cast the value returned by GetWindowLong(FHandle, GWL_WNDPROC) to TWndMethod. You should use MakeObjectInstance function to obtain a value that can be passed to SetWindowLong instead. Read Sertac Akuyz answer for a general idea.
Note that the need to subclass a window handle is very rare in Delphi applications. Delphi provides several other ways to interfere into window message processing, they are more simple and safe.
You've got two problems here. First, GetWindowLong doesn't give you the actual WndProc, but a handle to it.
Second, TWndMethod is defined as procedure(var Message: TMessage) of object;
It's a method pointer, not a function pointer, so you can't cast a normal pointer to it. What exactly are you trying to do?