I see, the callback function shouldn't be an object.
But I see many declare like this in qt45.pas
QLCLWebView_createWindow_Override = function (WebWindowType : integer):QWebViewH of object cdecl;
How to explain this?
In short. This is because Qt4PassLib is written this way.
Long explanation:
That's because qt45 is using a special wrapper library Qt4PassX.lib (where X is a version of the library).
Where all C++ classes (Qt is C++ based library) are wrapped with C-like functions.
At this moment FPC is not good at calling C++ methods directly. Neither C++ could call FPC methods.
However C functions could be easily called. The C-wrappers are also written in FPC friendly manner.
For example "QLCLWebView_createWindow_Override" is passed to the library as QHook parameter. (You can find the QHook declaration if you donlowd Qt4Pass lib sources). And it 's declared like this:
typedef struct {
void *func;
void *data;
} QHook;
Exactly matching TMethod declaration.
It's also interesting to see on how the passed QHook is used.
Since it's necessary to add an additional hidden (Self) parameter the function type is re declared right before the call to accept the parameter and passes it.
if (paintOverride.func) {
typedef void (*func_type)(void *data, QPainterH painter, const QStyleOptionViewItemH option, const QModelIndexH index);
(*(func_type)paintOverride.func)(paintOverride.data, (QPainterH) painter, (const QStyleOptionViewItemH)&option, (const QModelIndexH)&index);
}
As a matter of fact, this is a hack, but it works.