如何覆盖从对象检查器加载TImage(在运行时)? [英] How to override loading a TImage from the object inspector (at run-time)?

查看:45
本文介绍了如何覆盖从对象检查器加载TImage(在运行时)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉的道歉.这困扰了我很多年,现在我真的需要知道答案了.我悬赏150点来吸引兴趣,但为正确答案可以增加点数.

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.

这是我需要的:

我使用来自 TMS Scripter Pro 的TMS对象指示器来允许用户设计运行时的表单.您可以假定它派生自标准的Delphi对象检查器,并添加了一些功能,但其中90%只是调用继承的方法.

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.

当我单击TImage的Picture属性旁边的省略号时,它将调用一个继承的方法-我不知道该方法-允许我加载图片.完成此操作后,我不知道从哪个文件加载了图像,我想将其以相同的名称保存在另一个目录中.

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.

  • 我可以提示用户输入文件名,但这看上去让他感到困惑,而且太草率了.
  • 我可以找到一个TImage/TPicture后代,该后代存储文件名并允许我查询它.任何可以指出这样的FOSS组件的人都会得到赏金.
  • 我可以从TPicture和/或TImage派生自己编写代码,但不确定要更改什么.任何可以告诉我确切如何编码的人都会得到赏金.确切地说,我的意思是命名类和方法.

在此先感谢您的帮助.这真的让我很烦.

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.

基本上,当用户单击对象检查器中的省略号时,Delphi将打开一个文件/打开对话框.我想用我自己的方法来代替这种处理,以便我可以保存图像的路径.

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.

我本来希望做的就是从TImage派生一个类并重写Assign()函数,如以下代码所示.但是,当我这样做时,永远不会调用assign函数.因此,看来我需要重写其他内容,但是呢?

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.

推荐答案

好,我入侵了TMS代码.这似乎是唯一的方法.

Ok, I hacked the TMS code. It seemed to be the only way.

这篇关于如何覆盖从对象检查器加载TImage(在运行时)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆