Конференция "KOL" » How check Event is Dummy?
 
  • f417support © (24.01.11 04:19) [0]
    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;
  • Vladimir Kladov © (24.01.11 15:36) [1]
    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.
  • f417support © (25.01.11 04:00) [2]
    if Assigned(Form.OnMessage) then
    begin
      MsgOk("Assigned");
    end;
    MsgOk Is Always called even use NIL_EVENTS
  • Vladimir Kladov © (27.01.11 16:45) [3]
        if Assigned( TMethod( Form.OnMessage ).Data ) then
           ShowMsg( 'OK', MB_OK );



    does work: no message 'OK' when OnMessage not assigned.
  • f417support © (28.01.11 03:55) [4]
    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.
  • Jon © (30.01.11 03:41) [5]
    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.

  • Vladimir Kladov © (30.01.11 18:37) [6]
    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);

 
Конференция "KOL" » How check Event is Dummy?
Есть новые Нет новых   [134430   +4][b:0][p:0.001]