tags:

views:

100

answers:

2

I have a Delphi application which displays an image using a TImage.

The location of the image is stored in a database and retrieved on load and set directly using code similar to below:

Image1.Picture.LoadFromFile(Query1.FieldByName('image').AsString);

I want to be able to display and edit the Filename being loaded during the above, am I right that there is no way to access that directly from the TImage component and that I will need to store the filename separately?

+8  A: 

No, there isn't. You can store it yourself, though.

var
  ImageFileName: string;


begin
  ImageFileName := Query1.FieldByName('image').AsString;
  Image1.Picture.LoadFromFile(ImageFileName);
end;

Declare the ImageFileName variable at a place where it will be visible everywhere you need access to the file name.

Ken White
Ken's right, LoadFromFile is just a method to get a picture data into the component, the filename isn't stored anywhere.
_J_
Thanks, That's what I thought - just wanted to confirm that there was no method to retrieve it without having to maintain an appropriate variable
Dan Kelly
Just to be clear, it's not a question of being able to "retrieve" the filename from anywhere. The TImage component does not store the filename at all. Once the data is loaded, where it comes from is of no interest to the TImage (in fact, it never even really *knows* where it's Picture got it's data - it could have come from a Stream, it might have been Assign()ed ... etc). If you need to know that it came from a file and what the filename was, you have to add that tracking info to your code yourself. If you need this a lot, then you could derive a new TImage class which does what you want.
Deltics
@Deltics: I think everyone got that (even the OP - see the comment just prior to yours <g>).
Ken White
+1  A: 

You can store the filename in the Hint property of Image1.

if you don't already use it. As intended or for another purpouse... I find this property pretty promiscuous :)

PA
Unfortunately I am already using Hint for another property.One of the reasons I asked was I'd not been able to find any mention through Google and although I my assumption was correct, though it would be good to confirm. And also hopefully leave a record for anyone else wondering the same :)
Dan Kelly