[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Setting event handlers for runtime created controls

Posted on 2001-08-09
8
Medium Priority
?
250 Views
Last Modified: 2010-04-06
Hi, apologies as I've actually asked this one before but completely forgot the answer!  I want to create multiplt controls at runtime (eg Tpanels) and set the OnClick events to a single event handler that can easily distinguish which particular control has been clicked. Please can someone let me know the exact syntax I need please.  many thanks, P.
0
Comment
Question by:Pandora
[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
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 9

Accepted Solution

by:
ITugay earned 600 total points
ID: 6368478
Hi Pandora,

here is it:

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    procedure FormClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormClick(Sender: TObject);
begin
  beep;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  I: Integer;
  P: TPanel;
begin
  for I := 0 to 9 do
  begin
    P := TPanel.Create(Self);
    P.ALign := alTop;
    P.Parent := Self;
    // P.Tag := I;
    P.OnClick := FormClick;
  end;
end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6368503
Igor is right. And "Sender" then contains the panel, that was clicked.

Regards, Madshi.
0
 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6368512
And distinguish which particular control has been clicked, in the event handler (FormClick in the example) use Sender. If you want to work with it as it is TPanel use (Sender as TPanel):
  (Sender as TPanel).Caption := 'blahblah';

To be sure it is TPanel write:
if Sender is TPanel then
  (Sender as TPanel).Caption := 'blahblah';

Rgds,
Frodo

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:FrodoBeggins
ID: 6368525
Hehe. Madshi, collision again? :))

Never mind, it is ITugay who gave the answer

Rgds,
Frodo
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6368551
Yep...   (-:
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6368563
hi all :-)
0
 
LVL 17

Expert Comment

by:inthe
ID: 6368626
hello,
""apologies as I've actually asked this one before but completely forgot the answer""  

just to mention that if you forget your answers you can view it in your history (by clicking on your username and viewing history).

i am guessing this is your old question you meant :

http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20096042

   :-)
0
 
LVL 1

Author Comment

by:Pandora
ID: 6369565
Hee hee - thank you all!!  Fantastic answers all round and all the nicer for the collaboration.  I knew it was somthing like that!

InThe, Your comment really made me giggle, and you put me to shame with your memory and organisational skills!  Its a bit bizarre, but that question has completely disappeared from my question history, although I've reported it as an EE bug, I thought I'd lost it forever - thanks for finding it for me!

Best wishes all, and once again many thanks, P :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

650 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