Board index » delphi » How add an onclick event??

How add an onclick event??

Hi,

I was wondering if anyone could help me out with this:

I create a couple of Timages at runtime using an array of Timage and then
looping it through to get up to 30 images. How can I, when the user clicks
on one of the images, get the array-index of the image?

Thanks and cheers,

Robert

 

Re:How add an onclick event??


one way(although some people dont like it) is to set the tag property to match
the index of the array.

Re:How add an onclick event??


Hi Robert,

Quote
> I create a couple of Timages at runtime using an array of Timage and then
> looping it through to get up to 30 images. How can I, when the user clicks
> on one of the images, get the array-index of the image?

I'm assuming that your array contains the actual TImage object and that the
onclick event is assigned to one event for all TImages.  Thus, try something
like this:

procedure TMyform.ImageOnClick(Sender: TObject);
var
  x: integer;
  hImageIndex: integer;
begin
  hImageIndex := 0;
  for x := 1 to 30 do begin
    if ImageArray[x] = Sender then begin
      hImageIndex := x;
      break;
    end else
      hImageIndex := 0;
  end; // for x

  // do processing of image
end;

The above simply loops through your array and compares the object in the array
with sender.  If sender and the object in the array are equal then that is the
index of the object in the array.

I hope this helps,

Thanks,
Earl Reddell
Res-cue (Resourceful Components for User Ease!)
Check out our web site: http://www.res-cue.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:How add an onclick event??


Im Artikel <7fa0hr$lh...@black.news.nacamar.net>, "Robert Kimber"
<rjkim...@regio-info.de> schreibt:

Quote
>I create a couple of Timages at runtime using an array of Timage

If you use a TList instead of an array, the IndexOf method returns the index of
the Sender object in the list.

DoDi

Other Threads