Solved

Creatin Components At Runetime

Posted on 1998-07-01
3
156 Views
Last Modified: 2010-08-05
How can I declare the onclick procedure of a self created component ?

Greetings!
Thomas
0
Comment
Question by:dx15ti
3 Comments
 

Author Comment

by:dx15ti
ID: 1356780
Edited text of question
0
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
ID: 1356781
Yo,
you have to provide a TNotifyEvent typed method.

procedure Form1.RuntimeButtonClick(Sender : TObject);
begin
  // ...stuff
end;

procedure Form1.CreateRuntimeButton;
var RuntimeButton : TButton;
begin
  RuntimeButton := TButton.Create(Self);
  RuntimeButton.Parent := Self;
  RuntimeButton.OnClick := RuntimeButtonClick;
end;

Slash/d003303
0
 
LVL 10

Expert Comment

by:Jacco
ID: 1356782
This is the way you can declare it. It doesn't work themn yet, it is just for the storage.

type
  TMyComp = class(TGraphicControl)
  private
    FOnClick : TNotifyEvent;
    ..
  published
    property OnClick : TNotifyEvent
      read FNotifyEvent
      write FNotifyEvent;
  end;

To make it work on an OnClick add the following:

You have to call the notifyevent the following way from one of the protected procedures of the base class:

if Assigned(FOnClick) then FOnClick(Self);

This code can be inside

MouseDown or MouseUp (don't forget to add the override directive and caslling the inherited procedures.

Regards Jacco

Oops just too late. I understood your question differently.
d003303 answered the runtime part of the question. I thought you wanted to declare an OnClick property in a custom component...

Good luck

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now