Board index » cppbuilder » TForm::Dispatch & TMessage::Result

TForm::Dispatch & TMessage::Result

Hello All,

I can not find how to use the Result member of the TMessage variable passed
in TForm::Dispatch.

I need to return a value to the caller.  The called uses SendMessage to send
my window the message.  I handle the message with the Dispatch function.
How do I set their return value?

The following does not work:

The calling window calls:

retval = SendMessage(hwnd, WM_APP+1, 0, 0);

My window:

void __fastcall TFrom1::Dispatch(void* Message)
{
    PMessage msg = (PMessage)Message;

    switch(msg->Msg)
    {
    case WM_APP+1:
        msg->Result = 2;
        break;
    default:
        TForm::Dispatch(Message);
    }

Quote
}

In the above example, retval is always 1.

--
Mike Settles

"The significant problems we face cannot be solved by the same level of
thinking that created them."
-Albert Einstein

 

Re:TForm::Dispatch & TMessage::Result


Quote
Mike Settles <none> wrote in message news:3b523c23$1_2@dnews...
> Hello All,

> I can not find how to use the Result member of the TMessage variable
passed
> in TForm::Dispatch.

> I need to return a value to the caller.  The called uses SendMessage
to send
> my window the message.  I handle the message with the Dispatch
function.
> How do I set their return value?

The "Result" is not how the caller gets back information.  Have a look
at this article, and the first link in the article.
http://www.bcbdev.com/faqs/faq17.htm
-------
Timothy H. Buchman
========================================
City Center Theater, New York NY
mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland message archive on http://www.mers.com/searchsite.html

Re:TForm::Dispatch & TMessage::Result


Timothy H. Buchman <tbuch...@citycenter.org> wrote in message
news:3b52d0f6$1_2@dnews...

Quote
> Mike Settles <none> wrote in message news:3b523c23$1_2@dnews...
> > Hello All,

> > I can not find how to use the Result member of the TMessage variable
> passed
> > in TForm::Dispatch.

> > I need to return a value to the caller.  The called uses SendMessage
> to send
> > my window the message.  I handle the message with the Dispatch
> function.
> > How do I set their return value?

> The "Result" is not how the caller gets back information.  Have a look
> at this article, and the first link in the article.
> http://www.bcbdev.com/faqs/faq17.htm

err... did you mean to say the Result IS how the caller gets back
information?

When you set msg.Result in a message handler the result SHOULD be returned
as the return value of SendMessage().  You can test this by writing a simple
event handler that just returns a value via msg.Result like this:

// in the class def
protected:
  int val;
  void TestMsg(TMessage& msg);

BEGIN_MESSAGE_MAP
  MESSAGE_HANDLER(testmsg, TMessage, TestMsg)
END_MESSAGE_MAP(TForm)

void TForm1::TestMsg(TMessage& msg)
{
  msg.Result = ++val;

Quote
}

Add a label and button to the form, with this code for the button:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int res = ::SendMessage(Handle, testmsg, 0, 0);
  Label1->Caption = AnsiString(res);

Quote
}

Now every time you press the button you get the next value in the label.
This definitely works on BCB4Pro... can't imagine why it would be broken on
any other version.

--
Corey Murtagh
The Electric Monk
"Quidquid latine dictum sit, altum viditur."

Re:TForm::Dispatch & TMessage::Result


Timothy H. Buchman <tbuch...@citycenter.org> wrote in message
news:3b52d0f6$1_2@dnews...

Quote
> The "Result" is not how the caller gets back information.

Yes, it is, actually.  VCL message handlers have void return values, thus
the only way they have to return a value to the caller is through
Message.Result (why do you think it's called Result to begin with?)

Quote
> Have a look at this article, and the first link in the article.
> http://www.bcbdev.com/faqs/faq17.htm

Did you actually look at those articles?  Because the first one doesn't show
anything regarding sending responses back to the caller, and the second one
does use Message.Result to return a value.

Gambit

Other Threads