🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14823

Re: Trapping button message

#14823
From: Vladimir Afanasyev
Date: Thu, 31 Jul 2003 07:36
64 lines
3234 bytes
Hi,

"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:

>>          if(SpeedButton1 ==
>dynamic_cast<TSpeedButton*>(cntrl))ShowMessage("Button event catched!");
>
>For what is being asked, do not compare the dynamic_cast to a particular
>pointer, just test whether it succeeded at all:
>
>    if(dynamic_cast<TSpeedButton*>(cntrl))
>        ShowMessage("Button event catched!");
>

No, he ask about one or more speedbuttons and about detection 
what button pressed.

>> void __fastcall TForm1::FormCreate(TObject *Sender)
>
>Do not use the OnCreate event in C++.  It is a Delphi remnant that does not
>work correctly in C++ as it can be called before the constructor, which is
>illegal in C++.  Use the constructor instead.
>

Thank you, I didn't know it. But I think that as a TeamB 
member you need (or should) to send it in Quality project.
Just FormCreate Bor. dev. used in VCL components help for BCB5.
See TApplication::OnMessage example. May be the same in 
BCB6 Help.
BCB6 also has a lot errors - one of this incorrect work 
with Variant type (in definite conitions).

Your code in another letter (recursion) is really perfect!
Frankly saing, I understood these ideas self but 
then was far from Internet. I like recursion but 
think that sometimes recursion is not optimizing.
It is not only my opinion - I read in books about it.
By the way, do you know how .NET think about recursion?
I mean is it good to use recursion in managed code?

My solution is using circle.
void __fastcall TForm1::AppMessage(tagMSG &Msg, bool &Handled)
{
   if(Msg.message == WM_LBUTTONDOWN)
   {
     TWinControl* CurContr=this;
     while(CurContr)
        {
         TPoint click=CurContr->ScreenToClient(Msg.pt);
         TControl* cntrl=dynamic_cast<TControl*>(CurContr->ControlAtPos(click,False,True));
         if(!cntrl)return;
         if(SpeedButton1 == dynamic_cast<TSpeedButton*>(cntrl))
               {
                ShowMessage("Button event catched!");
                Handled=true;
                return;
               }
          else CurContr=dynamic_cast<TWinControl*>(cntrl);
        }
   }
}

Vladimir.
Technical Details
Message-ID: <3f28c71a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f26ea7c$1@newsgroups.borland.com> <3f27c07b$1@newsgroups.borland.com> <3f27f2ed@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,77c37ce9ffa755d1
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-31 00:40:21 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: Trapping button message
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 212.82.216.226 212.82.216.226    
X-Forwarded-For: 192.168.0.147
References:  <3f26ea7c$1@newsgroups.borland.com> <3f27c07b$1@newsgroups.borland.com> <3f27f2ed@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3f28c71a$1@newsgroups.borland.com>
Date: 31 Jul 2003 00:36:58 -0700
X-Trace: newsgroups.borland.com 1059637018 207.105.83.65 (31 Jul 2003 00:36:58 -0700)
Lines: 64
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-06!sn-xit-09!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail