-
How check Event is Dummy? becase a lot of my code use
if Assigned(Form.OnMessage) then begin // Do SomeThing // variable = Form.OnMessage(...), if OnMessage Is Dummy, Varible will not be correct end;
-
If you do not want use NIL_EVENTS, you can check only Data field of the event: if Assigned( TMethod( Form.OnMessage ).Data ) then ...
There only a problem with such check if you set you handler to a NIL object too.
-
if Assigned(Form.OnMessage) then begin MsgOk("Assigned"); end; MsgOk Is Always called even use NIL_EVENTS
-
if Assigned( TMethod( Form.OnMessage ).Data ) then
ShowMsg( 'OK', MB_OK ); does work: no message 'OK' when OnMessage not assigned.
-
i have a lot of code in old style, i think if define NIL_EVENTS , old code can still work, it suite for me. otherwize, convert kol2.94 project to kol 3.00, it is a hard work. thank for your reply.
-
I do not understand - what should I see here?
program Test;
uses Windows, KOL;
var
Button1, Button2: PControl;
procedure Button1Click(Dummy: Pointer; Sender: PObj);
begin
if Assigned(TMethod(Applet.OnMessage).Data) then
ShowMsg('OK', MB_OK);
end;
procedure Button2Click(Dummy: Pointer; Sender: PObj);
begin
Applet.OnMessage := nil;
end;
function AppMessage(Dummy: Pointer; var Msg: tagMSG; var Rslt: Integer): Boolean;
var
Index: Integer;
begin
Result := False;
end;
begin
Applet := NewForm(nil, 'Test');
Applet.OnMessage := TOnMessage(MakeMethod(nil, @AppMessage));
Button1 := NewButton(Applet, 'Button1');
Button1.OnClick := TonEvent(MakeMethod(nil, @Button1Click));
Button2 := NewButton(Applet, 'Button2').PlaceRight;
Button2.OnClick := TonEvent(MakeMethod(nil, @Button2Click));
Run(Applet);
end.
-
Nothing. In your case Data always is nil. When use MCK, it is usually an object which method is assigned as an even handler. In case of non-MCK it is sufficient to pass something else then nil in MakeMethod. E.g.:
Applet := NewForm(nil, 'Test');
Applet.OnMessage := TOnMessage(MakeMethod(Applet, @AppMessage));
Button1 := NewButton(Applet, 'Button1');
Button1.OnClick := TonEvent(MakeMethod(Applet, @Button1Click));
Button2 := NewButton(Applet, 'Button2').PlaceRight;
Button2.OnClick := TonEvent(MakeMethod(Applet, @Button2Click));
Run(Applet);
|