How to override loading a TImage from the object inspector (at run-time)?

技术标签: 德尔福

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.

这是我需要的:

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.

提前感谢任何帮助。 This one really annoys me.


进一步 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.

看答案

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


智能推荐

python报错:fails to pass a sanity check due to a bug in the windows runtime

Python报错(Anaconda或者PyCharm): RuntimeError: The current Numpy installation (‘D:\Develop\anaconda\lib\site-packages\numpy\init.py’) fails to pass a sanity check due to a bug in the windows r...

How to Deploy and Implement a Cloud ERP from Scratch(1) — Choose a Proper ERP Application

Enterprise resource planning (ERP) is the integrated management of main business processes, often in real time and mediated by software and technology. Recently, I got a request to deploy an ERP syste...

How to get runtime LOV query script

How to get runtime LOV query script Get SID in your form In the form, Help > About, to check this form Session SID. NOTE: In different form, Session SID is different. Then open LOV to trigger sql q...

opc使用教程

新新opc使用教程 如上图所示,以图片的序号为下面的说明序号对应: 1.用于获取本机的账号。 2.选择本机获取到的账号。 3.选择获取到的本机的一个opc server。 4.点击建立连接,最下面的运行日志,会有显示,连接成功与否。 5.开始浏览标签,即可获取到opc server中的所有标签,选择一些标签。 6.这一列和右侧类似的列会显示,你所选择的标签。 7.读取标签,读取间隔为2s. 8.这...

构建Xamarin.Forms NuGet

探索Xamarin.Forms(并在代码中变得更加舒适)的一个很好的方法是克隆存储库并运行它,特别是任何ControlGallery项目。 我们知道您中有许多人已经做到了这一点,所以您可以采取的下一步是为XAMarin.Forms进行自己的定制,以便在组织内构建和分发您自己的NuGet软件包。 在这篇文章中,让我们在本地进行一下,然后讨论如何在Visual Studio Team Services...

猜你喜欢

tomcat项目上线

目前我用的eclipse,myeclipse同样也是一样的操作 右击项目 选中在您要导出的项目上点击鼠标右键,选择Export 然后选择路经 起名字 然后finish。 接下来就是把war包放入tomcat服务器中, 首先启用远程连接命令连接服务器  远程连接的就是你购买的服务器的公网IP地址。  用户名一般都是Adminnistrator 密码是在阿里云控制台中设置 连接完毕...

session的实例

3、将要获取的name放在一个类对象中 将1中的name修改为 将2中的String改为Person 然后输出 4、设置失效时间 5、 session和cookie的区别 cookie是把用户的数据写给用户的浏览器,浏览器保存(可以保存多个) session把用户的数据写到用户独占session中,在服务器端保存(保存重要信息,减少服务器的资源浪费) session对象由服务器创建; 6、使用场景...

安装jdk 缺少jvm.dll 问题

下载JDK: https://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量: 一般装完jdk配置好环境变量就没问题了,第一次碰到不存在jvm.dll的情况。 安装1.7就不会,所以把1.7里JDK\bin 和 jre\bin 里面的jvm.dll所在的client、server目录拷贝到1.8对应的目...

Linux中的无人值守安装脚本kickstart(kickstart脚本的作用,制作kickstart脚本,搭建dhcp服务器,利用网桥在虚拟机中新建虚拟机)

一.kickstart自动安装脚本的作用 当安装Linux操作系统时,安装过程需要回答许多关于设定的问题,这些问题必须手动选择, 否则无法进行安装,当安装一台Linux系统时,手动选择工作量比较轻松,当安装多台linux', 这些设定需重复多次,这些重复动作是效率低下的操作 如何解决以上问题? 用文件来记录所有安装过程中问题的答案,避让所有需要安装的主机自动读取 kickstart作用 以上解决方...

mac xcode工程报错:Use of undeclared identifier 'CV_LOAD_IMAGE_COLOR'

mac xcode工程报错: 解决方法: 在网上看到一个办法:更新opencv版本。但后来发现,我安装的opencv版本为:4.0.1,是很高版本。 在另外一个帖子找到解决方法: https://blog.csdn.net/edwards_june/article/details/71235475 使用 IMREAD_COLOR 代替'CV_LOAD_IMAGE_COLOR'  ...

问答精选

joining table with itself using mysql

When I write this line on mysql on phpmyadmin using mariadb server getting unexpected error near a.cpid = b.cid MySQL said: #1064 - You have an error in your SQL syntax; check the manual that correspo...

Pointers: c++ requires a type specifier for all declarations

I am currently learning c programming, and I've encountered a problem in one of the exercises I'm doing. Whilst trying to decode how pointers work, i receive the following error: c++ requires a type s...

Using Tensorflow in C++ application: How to release GPU memory

I am trying to use Tensorflow for inference within my C++ application. Other parts of the application need access to large amounts of GPU memory (not at exactly the same time as Tensorflow). However, ...

VBA: Download a picture via HTTPS

I'm trying to download a picture from a website (Grafana monitoring tool, API) using VBA (MS Access 2016). It's a HTTPS address using a self signed ceritificat and requires username and password for a...

Selectively retrieving an object from a list within a Grails Domain object

I'm 2 months into Grails development and have stumbled across this challenge which i can't find a answer to having used books, the grails website and forum searches. I'm hoping someone can help me. I ...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答