tags:

views:

215

answers:

3

I have an Object Inspector, just like Delphi's, which I show at run-time to allow the user to change properties of components displayed in my app.

I would like to create a component derived from TImage with one extra property where I can store the path from which the image was loaded. To do so, I presume that I can subclass TImage, have an event to select the image by using something like ...

   var OpenPictureDialog: TPictureEditorDlg;
    if OpenPictureDialog1.Execute then
       OpenPictureDialog1.FileName  <-- contains what I want 

But, if I wrap that in a proc/fn, what's the signature and how do I get it to be called when the user clicks on the ellipsis next to the Picture property in the Object Inspector?


Or perhaps my question ought to have been whether there is an existing 3rd party component which already does this ...


50 point bounty for a free component which can be used in commercial applications (I will increase the bounty for an very good component)


If anyone can give the URL of a component that does this then I will start another bounty, 100 this time, and award it to them

+4  A: 

That depends on how your Object Inspector works. It would help if we knew where you got it from.

The way it works in Delphi's Object Inspector is that BPL packages can register property designers with the IDE, so when it sees a certain type, such as your custom TImage, it opens that designer instead of whatever it would normally open. See if your Object Inspector supports this, or if not, if you can add the functionality.

Mason Wheeler
+1 thanks for the quick reply. The object inspector is a TMS component from TMS scripter studio pro. I have added other properties, but with those I just had to code read/write routines. This one is more tricky.
Mawg
+1  A: 

TImage does not know the file name of the loaded picture. Because it receives only the image content, not the file name. So in order to get this information you must replace that default open picture select dialog with your own, and in it you pass the filename and the image content. Then your custom TImage can store this information.

DonnVall
+1  A: 

MiTeC's ImageEx is a small, simple and free component that extends Delphi's TImage. It doesn't have a "path" property, but it has an "about" property that you could use as the path property, or as a template to add your own path property.

For something more comprehensive and not too expensive, you might try the Envision Image library by Interval Software, It is integrated with Delphi's TImage. It costs $69 US.

lkessler
ImageEx sounds good, but there is no documentation or example of how to use it
Mawg
It's small and simple enough that it should be easy enough for you to modify so that you'll can add a path property to it. Doing so will give you what you want - a TImage with a path property. Learning how to extend components is a useful thing to know and do in Delphi, although I have to admit I haven't done much of it myself.
lkessler
+1 I do agree, and I thought I knew enough about extending components, adding property editors, etc. What puts me off this is that when someone can't be bother to produce *any* documentation, either online or in a readme, and doesn't have a single comment in their code, I usually have a bad experience.
Mawg