<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Apr 19, 2011, at 6:04 PM, Mattias Gaertner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><p style="margin: 0px;"><span> </span></p><p style="margin: 0px;"> </p>

    <div style="margin: 5px 0px 5px 0px;">
      <br>
       <a href="mailto:dhkblaszyk@zeelandnet.nl">dhkblaszyk@zeelandnet.nl</a> hat am 19. April 2011 um 17:48 geschrieben:<br>
      <br>

      <blockquote style="margin-left: 0px; padding-left: 10px; border-left: solid 1px blue;" type="cite">
        Hi,<br>
        <br>
         I'm trying to understand how message methods work in FPC. For this I created a simple app that shows a message. I also created a second (identical form) and I expected that all message methods related to MY_MESSAGE would be executed when I pressed either one or the other button. This did not happen however even when dispatching through the Application object. Can someone explain me please?<br>
        <br>
         Regards, Darius
      </blockquote>
    </div><p style="margin: 0px;"> </p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Make sure TMsg starts with</div><p style="margin: 0px;"> </p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">TMsg = record</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">  MsgID: DWord;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">  ...</div></div></blockquote><div><br></div><div>I used a cardinal instead, so no issues there, although I expected to get two messages as I have two forms open (code for both identical to the code shown below). Instead when I dispatch the message only the class which dispatches the message receives it. The other class never does. So how is the message handler traversing the classes within the process? I must be missing something obvious.</div><div><br></div><div>Darius</div><br><blockquote type="cite"><div>

    <div style="margin: 5px 0px 5px 0px;">
      <blockquote style="margin-left: 0px; padding-left: 10px; border-left: solid 1px blue;" type="cite">
        <br>
        <br>

        <div><p>  TForm1 = class(TForm)<br>
               Button1: TButton;<br>
               Button2: TButton;<br>
               procedure Button1Click(Sender: TObject);<br>
               procedure Button2Click(Sender: TObject);<br>
               procedure MessageReceiver(var msg: TMsg); message MY_MESSAGE;<br>
             private<br>
               { private declarations }<br>
             public<br>
               { public declarations }<br>
             end;</p><p>var    Form1: TForm1;</p><p>implementation</p><p>{$R *.lfm}</p><p>{ TForm1 }</p><p>procedure TForm1.Button1Click(Sender: TObject);<br>
           begin<br>
             msg.MSGID := MY_MESSAGE;<br>
             msg.Data := 'Hello World!';<br>
             Dispatch(msg);<br>
           end;</p><p>procedure TForm1.Button2Click(Sender: TObject);<br>
           begin<br>
             Form2.Show;<br>
           end;</p><p>procedure TForm1.MessageReceiver(var msg: TMsg);<br>
           begin<br>
             ShowMessage(msg.Data);<br>
           end;   </p>
        </div>
      </blockquote>
    </div><p style="margin: 0px;"> </p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Mattias</div><p style="margin: 0px;"> </p>
  </div>
_______________________________________________<br>fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br><a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a></blockquote></div><br></body></html>