Can I retrieve Filename for TPicture directly?

删除回忆录丶 提交于 2019-11-27 08:42:19

问题


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?


回答1:


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.




回答2:


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 :)




回答3:


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

if you don't already use it.

(in Firemonkey, not VCL)



来源:https://stackoverflow.com/questions/1874639/can-i-retrieve-filename-for-tpicture-directly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!