Solved

Creatin Components At Runetime

Posted on 1998-07-01
3
163 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 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