Board index » cppbuilder » How to call event from another even handler

How to call event from another even handler

Hi everyone,

I'm trying to call an event handler from another even handler, but I'm
getting an error on the last line of this code. Any ideas for a
beginner?

//---------------------------------------------------------------------------
void __fastcall TForm1::URLComboBoxClick(TObject *Sender)
{
    if (URLComboBox->Text != "")
    {
    wchar_t buff[100];
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
      URLComboBox->Text.c_str() , sizeof(URLComboBox->Text),
      buff, sizeof(buff));
    WebBrowser_V1Proxy->Navigate(buff, 0, 0, 0, 0);
    }

Quote
}

//---------------------------------------------------------------------------
void __fastcall TForm1::URLComboBoxKeyPress(TObject *Sender, char
&Key)
{
     if (Key == VK_RETURN)
     {
       Key = 0;
       URLComboBoxClick(TObject sender);   <----- HERE'S MY PROBLEM
     }                                                        BUT WHY?
//--------------------------------------------------------------------------
 

Re:How to call event from another even handler


Fixed it already. I was initially using sender and not Sender as
arguement. That Case Sensitivity got me again.

Re:How to call event from another even handler


backdoor,

Quote
>       URLComboBoxClick(TObject sender);   <----- HERE'S MY PROBLEM
>     }                                                        BUT WHY?

Aside from the case problem (s.b., Sender, not sender), put the "common"
code in a separate function, and call that function from both handlers.
This separates 'what' the program does from 'how' the user accesses the
functionality.

Good luck - keep at it,
Dave

Re:How to call event from another even handler


Also, this isn't legal syntax in C++

    URLComboBoxClick(TObject sender);

though

    URLComboBoxClick(Sender);

would be OK.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:How to call event from another even handler


I have been told you can always set Sender to NULL e.g. URLComboBoxClick(NULL).
This at least doesn't leave me wondering why I need to use Sender at all.
Quote
backdoor wrote:
> Hi everyone,

> I'm trying to call an event handler from another even handler, but I'm
> getting an error on the last line of this code. Any ideas for a
> beginner?

> //---------------------------------------------------------------------------
> void __fastcall TForm1::URLComboBoxClick(TObject *Sender)
> {
>     if (URLComboBox->Text != "")
>     {
>     wchar_t buff[100];
>     MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
>       URLComboBox->Text.c_str() , sizeof(URLComboBox->Text),
>       buff, sizeof(buff));
>     WebBrowser_V1Proxy->Navigate(buff, 0, 0, 0, 0);
>     }
> }
> //---------------------------------------------------------------------------
> void __fastcall TForm1::URLComboBoxKeyPress(TObject *Sender, char
> &Key)
> {
>      if (Key == VK_RETURN)
>      {
>        Key = 0;
>        URLComboBoxClick(TObject sender);   <----- HERE'S MY PROBLEM
>      }                                                        BUT WHY?
> //--------------------------------------------------------------------------

Other Threads