The usual way of creating an event handler in Delphi is to double-click the right-hand field in the Events tab of the Object Inspector. This creates a method with the proper signature; when the form is loaded, the OnXyzEvent is assigned the method name:
FOnXyzEvent := aForm.XyzEvent;
In theory, it should be possible to do something like this for a typical event handler:
FOnXyzEvent := procedure(Sender: TObject)
begin
doSomething;
end;
However, I have a TpgScript object that has an AfterExecute event with this signature:
procedure TpgScriptEx.DoOnAfterExecute(Sender: TObject; SQL: string);
begin
//
end;
FScript.AfterExecute := DoOnAfterExecute; // this works fine
// but for this, the compiler complains:
// [dcc32 Error] myfile.pas(1258): E2010 Incompatible types: 'TAfterStatementExecuteEvent' and 'Procedure'
FScript.AfterExecute := procedure (Sender: TObject; SQL: string)
begin
//
end;
If I try casting the procedure, I get an Invalid Cast error.
This seems like it should be a compiler bug.
Is there a workaround for this?