Board index » delphi » Referencing dynamically created TImage

Referencing dynamically created TImage

Hi All

I am dynamically creating a number of TImage thumbs.  I am assigning them
all the same On Click handler so how do I know which image was clicked?

I know there must be a simple answer but I've wasted hours getting nowhere
on this so any help would be appreciated

Kevin

 

Re:Referencing dynamically created TImage


Hi All

I am dynamically creating a number of TImage thumbs.  I am assigning them
all the same On Click handler so how do I know which image was clicked?

I know there must be a simple answer but I've wasted hours getting nowhere
on this so any help would be appreciated

Kevin

Re:Referencing dynamically created TImage


On ?? 17 ?e 2002 12:29:50p , "Kev" <kevin.par...@clear.net.nz> wrote in
news:3d86f71c$3@newsgroups.borland.com

Quote
> Hi All

> I am dynamically creating a number of TImage thumbs.  I am assigning them
> all the same On Click handler so how do I know which image was clicked?

> I know there must be a simple answer but I've wasted hours getting
nowhere
> on this so any help would be appreciated

> Kevin

It might be simplier to tell us what you try to do
In any event in order to get a complete answer please
supply the following answers

1) how you keep the images in memory
2) how you distinguise between them

regards
johnnie.

Re:Referencing dynamically created TImage


there is the sender parameter being passed back.

procedure ImageMousedown(...sender..)

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net

Quote
Kev wrote:

> Hi All

> I am dynamically creating a number of TImage thumbs.  I am assigning them
> all the same On Click handler so how do I know which image was clicked?

> I know there must be a simple answer but I've wasted hours getting nowhere
> on this so any help would be appreciated

> Kevin

Re:Referencing dynamically created TImage


I most likely will get stepped on by a moderator for answering, but look at
the functionality of Sender..
Quote
Kev wrote:
> Hi All

> I am dynamically creating a number of TImage thumbs.  I am assigning them
> all the same On Click handler so how do I know which image was clicked?

> I know there must be a simple answer but I've wasted hours getting nowhere
> on this so any help would be appreciated

> Kevin

Re:Referencing dynamically created TImage


I most likely will get stepped on by a moderator for answering, but look at
the functionality of Sender..
Quote
Kev wrote:
> Hi All

> I am dynamically creating a number of TImage thumbs.  I am assigning them
> all the same On Click handler so how do I know which image was clicked?

> I know there must be a simple answer but I've wasted hours getting nowhere
> on this so any help would be appreciated

> Kevin

Re:Referencing dynamically created TImage


Also, one could use the Tag item of each dynamicly created image..
 and on the entry of the calls you simple check the Tag of the sender.
 for example in the Event code..
if  Sender is Timage then
 Case Timage(Sender).Tag of
  0:
  1:
etc..
 when you dynamicly create the images you could simple set the Tag property of
the new image to its new possition in the list.
Quote
Kev wrote:
> Hi All

> I am dynamically creating a number of TImage thumbs.  I am assigning them
> all the same On Click handler so how do I know which image was clicked?

> I know there must be a simple answer but I've wasted hours getting nowhere
> on this so any help would be appreciated

> Kevin

Re:Referencing dynamically created TImage


Thanks for the advice.  I tried iterating through with Sender and Tag fields
but after I found the right TImage I still had the problem of referencing
it.  I could build it a Name with

'String' + IntToString(i);

But how to use it from there is beyond me (yes I am a bit of a newbe) and
Sender didn't seem amenable to assignment;

Anyway crisis over I've come up with

ImagePointer := @Sender;

Which works fine.

Cheers

Kev

Quote
"Maynard Philbrook" <jami...@mindspring.com> wrote in message

news:3D877F80.54835BE9@mindspring.com...
Quote
> Also, one could use the Tag item of each dynamicly created image..
>  and on the entry of the calls you simple check the Tag of the sender.
>  for example in the Event code..
> if  Sender is Timage then
>  Case Timage(Sender).Tag of
>   0:
>   1:
> etc..
>  when you dynamicly create the images you could simple set the Tag
property of
> the new image to its new possition in the list.

> Kev wrote:

> > Hi All

> > I am dynamically creating a number of TImage thumbs.  I am assigning
them
> > all the same On Click handler so how do I know which image was clicked?

> > I know there must be a simple answer but I've wasted hours getting
nowhere
> > on this so any help would be appreciated

> > Kevin

Re:Referencing dynamically created TImage


Thanks for the advice.  I tried iterating through with Sender and Tag fields
but after I found the right TImage I still had the problem of referencing
it.  I could build it a Name with

'String' + IntToString(i);

But how to use it from there is beyond me (yes I am a bit of a newbe) and
Sender didn't seem amenable to assignment;

Anyway crisis over I've come up with

ImagePointer := @Sender;

Which works fine.

Cheers

Kev

Quote
"Maynard Philbrook" <jami...@mindspring.com> wrote in message

news:3D877F80.54835BE9@mindspring.com...
Quote
> Also, one could use the Tag item of each dynamicly created image..
>  and on the entry of the calls you simple check the Tag of the sender.
>  for example in the Event code..
> if  Sender is Timage then
>  Case Timage(Sender).Tag of
>   0:
>   1:
> etc..
>  when you dynamicly create the images you could simple set the Tag
property of
> the new image to its new possition in the list.

> Kev wrote:

> > Hi All

> > I am dynamically creating a number of TImage thumbs.  I am assigning
them
> > all the same On Click handler so how do I know which image was clicked?

> > I know there must be a simple answer but I've wasted hours getting
nowhere
> > on this so any help would be appreciated

> > Kevin

Re:Referencing dynamically created TImage


Kev,

Quote
> Thanks for the advice.  I tried iterating through with Sender and Tag
fields
> but after I found the right TImage I still had the problem of referencing
> it.  I could build it a Name with

> 'String' + IntToString(i);

You're trying much too hard. <g> Simply do one of two
things:

1) Typecast Sender each time you need to use it.

  if Sender is TImage then
  begin
    TImage(Sender).Left := 100;
    TImage(Sender).Top := 100;
  end;

2) Declare a local variable of type TImage, and assign Sender to it.

var
  Img: TImage;
begin
  Img := TImage(Sender);
  Img.Left := 100;
  Img.Top := 100;
end;

See? :-) There *is* a simple answer.

Ken
---
Ken White
kwh...@adpsi.com

Clipper Functions for Delphi and C++ Builder
http://www.adpsi.com

Other Threads