开发者

How can I get the file path of the TPicture of a TImage? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicates:

Can I retrieve Filename for TPicture direc开发者_如何学Gotly?

Need help with deriving from TImage (to store the path to image's file)

This one has bothered me for years.

I have my own Object Inspector (well, TMS' actually) which is visible at run-time. When the user adds a TImage he can click the ellipsis (...) next to "image" and a standard "file open" dialog pops up. However, after clicks "Load" there is no way to get the file path of the image on disk (I would like to make a copy, with the same file name, to a different directory).

Does anyone know of a FOSS component which would let me do this? Or know what I would have to sub-class to roll my own?


You'd have to create a descendant of the TMS Object Inspector, and hook into where it presents the dialog for selecting a file. You can then store the filename in a new property the descendant provides for that information.

Not having the TMS component you're using, I can't tell you if this would be feasible or not.

You could also write a replacement property editor for TGraphic; this would affect every TImage, however. The JEDI JVCL has several examples of custom property editors (like the multiline string property editor used for things like TLabel.Caption). That property editor would provide it's own TOpenPictureDialog, and could do what it wanted with the filename.


Using standard VCL TPicture descendants, You can't.

A TPicture descendant stores the graphic data itself and it is not required this picture to be stored in a file once.

For example, you can have instances of TPicture descendants that comes from other sources, without any file involved, for example:

  • picture is created on the fly
  • picture is obtained online or from device streams (like a video camera, scanner, webcam, etc.),
  • picture is pasted from the clipboard

If you must know, for any reason, the source of the file, you have to write your own TPicture descendants and track that information by yourself. You'll find problems if your own descendants interact with libraries (including the VCL) or the IDE itself, because those will not use nor set your custom properties, or will be using methods like LoadFromStream instead of LoadFromfile. In such case you, for instance, have no reference of the origin of that stream.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜