Solved

How to override sub component events

Posted on 2000-04-17
2
337 Views
Last Modified: 2010-04-04
Delphi Problem:
I have a component consisting of a panel with a button on it. I want to be able to override the click event of the button.
PS
So far I can surface the button's  click event so so the user can insert code via the object inspector, and I can overide the panel's click event so I can put in my own code. But how to overide the sub components code myself?
 
0
Comment
Question by:robert_m78
2 Comments
 
LVL 2

Accepted Solution

by:
mullet_attack earned 50 total points
ID: 2725176
declare a private procedure in you component :

procedure ButtonClick(Sender:TObject);

in your obects constructor (or wherever you create the button, add the line :

MyButton.OnClick := Buttonclick;

You can do whatever you want in the implementation of the ButtonClick procedure

This doesn't override the buttons's click event, it merely specifies the proc to run when the event happens. ie using this code you can't still call the inherited Click to allow the user's code to run also.

To still be able to run the user's code, define an event (sounds like you already have), and in the ButtonClick proc do "if Assigned(MyButtonEvent) then DoButtonEvent(Self)"
0
 

Author Comment

by:robert_m78
ID: 2725199
Many thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question