Aplogies for top posting. This has buggged me for years and now I really need to know the answer. I put 150 points bounty to attract interest, but could increase for the right answer.
Here is what I need:
I use the TMS obejct inpsctor from TMS Scripter Pro to allow users to design a form at run-time. You can assume that it derives from the standard Delphi Object Inspector and adds a little functionality but 90% of it just calls inherited methods.
When I click the ellipsis next to the Picture property of a TImage it calls an inherited method - I don't know which - to allow me to load a picture. When I have done so, I do not know which file the image was loaded from and I want to save it with the same name in a different directory.
- I could prompt the user for a file name, but that looks confusing to him and is just plain sloppy.
- I could find a TImage / TPicture descendant which stores the file name and allows me to query it. Anyone who can point out such a FOSS component gets the bounty.
- I could derive from TPicture and or TImage and code it myself, but am not certain what to change. Anyone who can tell me exactly how to code it gets the the bounty. By exactly, I mean naming classes and methods.
Thanks in advance for any help. This one really annoys me.
Further to my previous question, which did not get a useful answer despite a bounty, I will try rephrasing the question.
Basically, when the user clicks the ellipsis in the object inspector, Delphi opens a file/open dialog. I want to replace this handling with my own, so that I can save the image's path.
I would have expected that all I need to do is to derive a class from TImage and override the Assign() function, as in the following code. However, when I do the assign function is never called. So, it looks like I need to override something else, but what?
unit my_Image;
interface
uses
Classes, ExtCtrls, Jpeg, Graphics;
type
Tmy_Image = class(Timage)
private
FPicture : TPicture;
protected
procedure OnChange(Sender: TObject);
public { Public declarations }
Constructor Create(AOwner: TComponent); override;
procedure SetPicture(picture : TPicture);
procedure Assign(Source: TPersistent); override;
published { Published declarations - available in the Object Inspector at design-time }
property Picture : TPicture read FPicture write SetPicture;
end; // of class Tmy_Image()
procedure Register;
implementation
uses Controls, Dialogs;
procedure Register;
begin
RegisterComponents('Standard', [Tmy_Image]);
end;
Constructor Tmy_Image.Create(AOwner: TComponent);
begin
inherited; // Call the parent Create method
Hint := 'Add an image from a file|Add an image from a file'; // Tooltip | status bar text
AutoSize := True; // Control resizes when contents change (new image is loaded)
Height := 104;
Width := 104;
FPicture := TPicture.Create();
self.Picture.Bitmap.LoadFromResourceName(hInstance, 'picture_poperty_bmp');
end;
procedure Tmy_Image.OnChange(Sender: TObject);
begin
Constraints.MaxHeight := Picture.Height;
Constraints.MaxWidth := Picture.Width;
Self.Height := Picture.Height;
Self.Width := Picture.Width;
end;
procedure Tmy_Image.SetPicture(picture : TPicture);
begin
MessageDlg('Tmy_Image.SetPicture', mtWarning, [mbOK], 0); // never called
end;
procedure Tmy_Image.Assign(Source: TPersistent);
begin
MessageDlg('Tmy_Image.Assign', mtWarning, [mbOK], 0); // never called
end;
end.