Setting OnClick methods in Borland C++ Builder

I am using Borland C++ Builder and am created an object (in this specific instance, a TLabel) in runtime:
class PreviewItem
{
private:
  TPanel    *Container;
  TLabel    *SelMask;
   ...more...
public:
   PreviewItem(TPanel *Parent, String ImageSource, String CaptionText)
  {
     ...create Container and other componants...
    SelMask = new TLabel(Container);
    SelMask->Parent = Container;
    ...set proterties for SelMask...
  }
};
I want to set it's OnClick method to a function within the PreviewItem class. How would I do this?
LVL 7
icrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

acarrierCommented:
Hi,

You have to assign the onlick event handler of the label to a function you create. For a TControl (wich tlabel descends from) the OnClick event handler is basically a function pointer you want to assign. You assign your function yo that pointer. The function must be according to the doc :

         void __fastcall (__closure *TNotifyEvent)(System::TObject* Sender);

This means that in your previewitem class, you have to declare a function like this:
// declaration, in your header file.
void __fastcall PreviewItem::MyOnClickFunction(TObject* Sender);
// function definition
void __fastcall MyOnClickFunction(TObject* Sender)
{
           // sender is your Tlabel object so you can access it in this function
           // do your thing here.
      // you can try this to confirm all this works just as a test:
      ShowMessage("YAHOO");
};

LAST STEP:
Now in your previewitem constructor, assign the onclick event handler to your function:
SelMask->OnClick = MyOnClickFunction;

I have tried this code and it works on my side.
Let us know.

Later!
A.Carrier
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
icrAuthor Commented:
Yay, works. Thanks. I did actually have all of that code, except when I was trying to assign the OnClick function I was trying to parse Sender. I suppose I should have mentioned that :) But thanks, great explination too ;)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.