Re: Adding events to Run time created controls

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 11/23/04


Date: Tue, 23 Nov 2004 17:31:12 -0500


"Jim P" <Jim_P@mad.scientist.com> wrote in message
news:jKqdncuSQOZOLz7cRVn-ug@comcast.com...

> Got to be a simply solution to this. You just helped with one major
> issue. Now to get back the tag or other information so that I know
> which one of the labels in the array was clicked upon.

The Sender parameter of a tNotifyEvent is conventionally the object that
fired the event. IOW it will be the label that was clicked on. (This is one
of the reasons why control arrays are rarely needed in Delphi.) So code your
event something like

procedure tSomeForm.LabelClick (Sender : tObject);

var theLabel : tLabel;

begin
Assert (Sender is tLabel, 'Programmer error :) Only tLabel descendants can
use this event.');
theLabel := tLabel (Sender);
// now you can use theLabel to reference the clicked label
// e.g.
theLabel.Font.Color := clRed;
theLabel.Font.Style := [fsBold, fsItalic];
. . .
end;

If you really need to index the array you could either search the array for
Sender or put the appropriate array index in the Tag of each label.



Relevant Pages

  • Re: Button click handler for array of forms
    ... I wrote this utility because the application's autosave sometimes did not ... its timer and reenabled when OK'd). ... by using the Sender parameter in the handler. ... The Timer array holds TTimer instances, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Button click handler for array of forms
    ... I solved this by assigning an array of forms, and I created a new form for each instance of the running program, and put the document name in the caption. ... but I had to identify the source of the button click by using the Sender parameter in the handler. ... The Timer array holds TTimer instances, ... procedure TPADS2.Button2Click(Sender: TObject); ...
    (comp.lang.pascal.delphi.misc)
  • Re: How to pass more than two parameters in the event handler
    ... // Create EventArgs subclass to pass in 2D array parameter ... public intcurveArray; ... public delegate void getCurveButtonHandler(object sender, int ... my event handler getCurveButtonHandler but seems like this is not the best ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: converting program variables to arrays
    ... to the program variables. ... variable to an array type such that I can store the value of the ... For starters it gets round the obvious problem that a simple array won't hold an int as and a string label as. ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)
  • Re: Adding events to Run time created controls
    ... I added this to some test code and it worked ... label to see which matchs with the mouse position. ... >>which one of the labels in the array was clicked upon. ... > Sender or put the appropriate array index in the Tag of each label. ...
    (alt.comp.lang.borland-delphi)