Search code examples
delphidelphi-xe3inherited-resources

Get name of a resource currently loaded in TImage component - Delphi XE3


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


Solution

  • 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.