Solved

Creatin Components At Runetime

Posted on 1998-07-01
3
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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