(10-07-2021, 03:00 AM)BartKindt Wrote: But now I got:
Error: Incompatible types: got "<class method type of procedure(TIdContext;TIdHTTPRequestInfo;TIdHTTPResponseInfo) of object;StdCall>" expected "<procedure variable type of procedure(TIdContext;TIdHTTPRequestInfo;TIdHTTPResponseInfo) of object;StdCall>"
Why is the calling convention set to StdCall? I would have expected the default Register instead.
In any case, try one of these workarounds:
Code:
IdHTTPServer1.OnCommandGet := TIdHTTPCommandEvent(@TDebugLogEventHandlers.IdHTTPServer1CommandGet);
IdHTTPServer1.OnException := TIdServerThreadExceptionEvent(@TDebugLogEventHandlers.IdHTTPServer1Exception);
Code:
var
M: TMethod;
begin
M.Data := TDebugLogEventHandlers;
M.Code := @TDebugLogEventHandlers.IdHTTPServer1CommandGet;
IdHTTPServer1.OnCommandGet := TIdHTTPCommandEvent(M);
M.Data := TDebugLogEventHandlers;
M.Code := @TDebugLogEventHandlers.IdHTTPServer1Exception;
IdHTTPServer1.OnException := TIdServerThreadExceptionEvent(M);
end;
Code:
var
OnCommandEvent: TIdHTTPCommandEvent;
OnExceptionEvent: TIdServerThreadExceptionEvent;
begin
TMethod(OnCommandEvent).Data := TDebugLogEventHandlers;
TMethod(OnCommandEvent).Code := @TDebugLogEventHandlers.IdHTTPServer1CommandGet;
IdHTTPServer1.OnCommandGet := OnCommandEvent;
TMethod(OnExceptionEvent).Data := TDebugLogEventHandlers;
TMethod(OnExceptionEvent).Code := @TDebugLogEventHandlers.IdHTTPServer1Exception;
IdHTTPServer1.OnException := OnExceptionEvent;
end;
Or, you could simply compile the unit in {$mode Delphi}, in which case the original code without @ should work.