tags:

views:

151

answers:

2

Hello,

In the declaration of my form,I made a messagehandler:

procedure MessageHandler(var Msg:TMessage);Message MSG_ACCESS;

const
MSG_ASYNC = $BAD;
MSG_ACCESS = $BEEF;

In the message Handler when I check for a message,it works fine,but if i change the declaration like this:

procedure MessageHandler(var Msg:TMessage);Message MSG_ACCESS or MSG_ASYNC;

None of the messages I send are being handled.

How do I make it with two messages?

+11  A: 

Just create two message handlers to call the shared one.

Procedure MessageHandler(var Msg:tMessage);
begin
  // your code here
end;

Procedure MsgAccessHandler(var Msg:Tmessage); message MSG_ACCESS;
begin
  MessageHandler(Msg);
end;

Procedure MsgAsyncHandler(Var Msg:tMessage); message MSG_ASYNC;
begin
  MessageHandler(Msg);
end;
skamradt
That solved the problem. :)
John
+2  A: 

The OR operator in Pascal acts as both a logical and binary OR (|| and |) depending on context. So MSG_ACCESS or MSG_ASYNC is $0BAD OR $BEEF = $BFEF (0x0BAD | 0xBEEF).

So you are trying to handle a Message $BFEF

Another method is to use a MessageHook routine

function MsgHook(var Message: TMessage): Boolean;

in the form create use

Application.HookMainWindow(MsgHook);

ensure you unhook it in the destructor

  Application.UnhookMainWindow(MsgHook);

function TFormMain.MsgHook(var Message: TMessage): Boolean;
begin
  case Message.Msg of
    MSG_ACCESS :
    begin
      // what ever
    end;
    MSG_ASYNC:
    begin
      // what ever
    end;
  end;
  Result := False;
end;

It is also possible to override the WndProc for the form:

procedure WndProc(var Message: TMessage); override;
Gerry