0

I've been looking around but haven't found anything specific...

I built a resoruce file containing about 100 small png images, and I load them randomly all over the app. I then have OnClick event on every TImage component, where I do get the Sender's name (Image1, Image2 etc..) but don't know how could I get the name of an indentifier, which is currently loaded in the sender (TImage) from the resource...

Is this even possible, or would I need to store kind of a stringlist or a database containing info about which resource is used for every picture...?

The GetNamePath retrieves nothing...

Thanks

That Marc
  • 1,134
  • 3
  • 19
  • 42

2 Answers2

4

The TImage component (or the Picture and Bitmap properties) doesn't store any reference to the resources loaded. So you must do this manually. Try using a dictionary (TDictionary<TImage, Integer>) with the references to the resource id and the TImage or you can create new component which descends from the TImage adding a new property to store the loaded resource id.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • I ended up adding used image id to image tag instead, as currently I don't need it for anything else. Just wanted to know if there's any way of doing this directly... Thanks. – That Marc Mar 06 '14 at 19:48
2

You could load the images into a TImageList first, then retrieve individual images from that list into each TImage as needed, and then use the TImage.Tag property to keep track of which index was retrieved. If you use a TPNGImageList, you can store extra data with each image in the list, just as the original resource identifier name.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I ended up adding used image id to image tag instead, just as you suggested,, as currently I don't need it for anything else. Just wanted to know if there's any way of doing this directly... Thanks. – That Marc Mar 06 '14 at 19:49