热门发布的Aplogies。这已经让我困惑多年了,现在我真的需要知道答案。我拿出150点赏金以吸引兴趣,但可能会增加正确的答案。
这就是我需要的:
我使用来自TMS Scripter Pro的TMS obejct inpsctor来允许用户在运行时设计表单。您可以假设它派生自标准的Delphi Object Inspector并添加了一些功能,但其中90%只是调用继承的方法。
当我点击TImage的Picture属性旁边的省略号时,它调用一个继承的方法 - 我不知道哪个 - 允许我加载图片。当我这样做时,我不知道图像是从哪个文件加载的,我想在同一目录中将它保存在不同的目录中。
提前感谢您的帮助。这个让我很烦恼。
除my previous question之外,尽管有赏金,但我没有得到有用的答案,我会尝试重述这个问题。
基本上,当用户单击对象检查器中的省略号时,Delphi会打开一个文件/打开对话框。我想用自己的处理替换这个处理,这样我就可以保存图像的路径。
我原本以为我需要做的就是从TImage派生一个类并覆盖Assign()函数,如下面的代码所示。但是,当我这样做时,从不调用assign函数。所以,看起来我需要覆盖别的东西,但是什么?
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.
答案 0 :(得分:0)
看看是否有效:
[...]
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;
[...]
上帝保佑你!
答案 1 :(得分:0)
好的,我攻击了TMS代码。这似乎是唯一的方法。