Board index » cppbuilder » Re: Class

Re: Class


2005-02-04 02:46:26 AM
cppbuilder87
"Arnaldo Giacomitti Junior" < XXXX@XXXXX.COM >wrote in message
Quote
I have inside of TWinControl two components TLabel, and TMyMaskEdit
If I assign event for this components I am doing the things right? Or have
another approach to do this?
If a component has sub-components, the main component can assign handlers to
the sub-component events.
Gambit
 
 

Re:Re: Class

Hello all
I have a form
class TfrmMain : public TForm
{
__published: // IDE-managed Components
TPanel *picTickerPanel;
private: // User declarations
public: // User declarations
__fastcall TfrmMain(TComponent* Owner);
};
//-------------------------------------------------
extern PACKAGE TfrmMain *frmMain;
I created a class derived from TShockwaveFlash
//in the header
class TImageFLASH : public TShockwaveFlash
{
private:
String FlashCursor;
public:
__fastcall TImageFLASH(TComponent *Owner);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
VCL_MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
END_MESSAGE_MAP(TShockwaveFlash)
};
//in the Cpp file
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
{
TShockwaveFlash::Dispatch(&Message)
...........//some thing
}
At runtime i am creating a some flash controls in the "picTickerPanel" panel
of frmMain
for(int FLASHImageNumber=0; FLASHImageNumber<=3; FLASHImageNumber++)
{
TImageFLASH *ImageFLASH = new TImageFLASH(picTickerPanel);
ImageFLASH->Parent = picTickerPanel;
ImageFLASH->Tag = FLASHImageNumber;
}
and placing in the panel.
My Problems
----------
When the mouse is over the flash images i want to know the ImageFLASH Tag
number (Sender) of the event.
Thanks
SA
 

Re:Re: Class

Hi SA,
I don't know what TShockwaveFlash descends from, but if your TImageFLASH
has a Tag property, you can access that property directly from within
the TImageFLASH::CMMouseEnter (or CMMouseLeave) method(s). When you
receive the CMMouseEnter/Leave messages, just make sure to check that
the Msg.LParam data member is NULL; if it's not, then the message was
intended for a child of the TImageFLASH (not an issue if TImageFLASH
can't contain other child controls).
I would suggest creating OnMouseEnter and OnMouseLeave events for your
TImageFLASH class; this is similar to what's available to TControl
descendants in newer versions of C++Builder; some similar to...
class TImageFLASH : public TShockwaveFlash
{
__published:
__property TNotifyEvent OnMouseEnter =
{read=OnMouseEnter_, write=OnMouseEnter_};
__property TNotifyEvent OnMouseLeave =
{read=OnMouseLeave_, write=OnMouseLeave_};
public:
__fastcall TImageFLASH(TComponent* AOwner) :
TShockwaveFlash(AOwner) {}
private:
void __fastcall CMMouseEnter(TMessage& Msg);
void __fastcall CMMouseLeave(TMessage& Msg);
private:
TNotifyEvent OnMouseEnter_;
TNotifyEvent OnMouseLeave_;
public:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(CM_MOUSEENTER, TMessage, CMMouseEnter)
VCL_MESSAGE_HANDLER(CM_MOUSELEAVE, TMessage, CMMouseLeave)
END_MESSAGE_MAP(TCustomControl)
};
void __fastcall TMyControl::
CMMouseEnter(TMessage& Msg)
{
TCustomControl::Dispatch(&Msg);
if (Msg.LParam == NULL && OnMouseEnter_ != NULL)
{
OnMouseEnter_(this);
}
}
void __fastcall TMyControl::
CMMouseLeave(TMessage& Msg)
{
TCustomControl::Dispatch(&Msg);
if (Msg.LParam == NULL && OnMouseLeave_ != NULL)
{
OnMouseLeave_(this);
}
}
Cheers,
bar wrote:
Quote
At runtime i am creating a some flash controls in the "picTickerPanel" panel
of frmMain
for(int FLASHImageNumber=0; FLASHImageNumber<=3; FLASHImageNumber++)
{
TImageFLASH *ImageFLASH = new TImageFLASH(picTickerPanel);
ImageFLASH->Parent = picTickerPanel;
ImageFLASH->Tag = FLASHImageNumber;
}
and placing in the panel.

My Problems
----------
When the mouse is over the flash images i want to know the ImageFLASH Tag
number (Sender) of the event.
 

{smallsort}

Re:Re: Class

Quote
I don't know what TShockwaveFlash descends from, but if your TImageFLASH
has a Tag property, you can access that property directly from within the
TImageFLASH::CMMouseEnter (or CMMouseLeave) method(s).
Hi Damon, thanks for reply
It has the tag property. In the TImageFLASH::CMMouseEnter, i can't able to
find from which flash image the event is occuring.
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
{
//some thing working fine.
.....
Now how to find the Sender of this event.
}
 

Re:Re: Class

Quote
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
...
When the mouse is over the flash images i want to know the ImageFLASH Tag
number (Sender) of the event.
If I correctly understand what you have described then in CMMouseEnter
'this' is the sender. You should just be able to access 'Tag' directly.
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
{
TShockwaveFlash::Dispatch(&Message);
switch (Tag)
{ // blah
}
}
- Clayton
 

Re:Re: Class

"bar" < XXXX@XXXXX.COM >wrote:
Quote

[...] It has the tag property. In the
TImageFLASH::CMMouseEnter, i can't able to find from which
flash image the event is occuring.
There is no such native event or method. However, one can
subclass the object and add a message handler and in that case
the implicit 'this' pointer would point to the current object.
Quote
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
{
//some thing working fine.
.....
Now how to find the Sender of this event.
}
While technically incorrect, that looks like a message handler
and would only be valid if part of a subclassed TImage object
and even then it would most likely be at issue because ...
Prior to BDS (and possibly including BDS), CM_MOUSEENTER and
CM_MOUSELEAVE are unreliable. For more see here:
www.stevetrefethen.com/blog/IntroducingOnMouseEnterOnMouseLeaveEventsOnTControlInVCLForDelphi2006.aspx
You need to explain exactly what it is that you want to
accomplish and then explain exactly how the samples fit
into your design.
~ JD
 

Re:Re: Class

Hi Clayton.Thanks
this is what i need
Cheers
SA
 

Re:Re: Class

"bar" < XXXX@XXXXX.COM >wrote in message
Quote
When the mouse is over the flash images i want to know
the ImageFLASH Tag number (Sender) of the event.
The sender is the same object that the 'this' pointer of the method is
pointing to, so just use the Tag property directly, ie:
void __fastcall TImageFLASH::CMMouseEnter(TMessage &Message)
{
TShockwaveFlash::Dispatch(&Message)
if( Tag == whatever )
// do something ...
}
Gambit