tags:

views:

80

answers:

1

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.
A: 

See if this works:

  [...]

  procedure Tmy_Image.PictureChange(Sender: TObject);
  begin
    ShowMessage('Should work');
  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();
    FPicture.OnChange := PictureChange; /// <<<<
    self.Picture.Bitmap.LoadFromResourceName(hInstance, 'picture_poperty_bmp');
  end;

  [...]

God bless you!

Trinidad
Please describe what you think will "work" upon using this code. How will this code alter the default behavior of the Object Inspector's ellipsis button?
Rob Kennedy
+1 You are correct, Rob. Of course, that works, but it only tells me that the picture was changed. What I need to do is to get the name of the file from which the picture was loaded. In order to do that, I think that I need to override the handling of the ellipsis click in order to provide my own TSavePictureDialog. And I am stumped as to how to do that.
Mawg
Rob, he's not trying to override Delphi's property editor (which works in design time). He's trying to override TMS's component run-time behavior.
Trinidad