加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 在对象检查器上显示TFrame后代的附加属性

发布时间:2020-12-15 10:07:27 所属栏目:大数据 来源:网络整理
导读:Delphi对象检查器不会按设计显示TFrame后代的其他属性. 人们倾向于建议使用一种已知的技巧,该技巧通常用于在对象检查器上显示TForm后代的属性.诀窍是:通过设计时包将注册TForm后代的自定义模块注册到Delphi IDE: RegisterCustomModule(TMyFrame,TCustomMod
Delphi对象检查器不会按设计显示TFrame后代的其他属性.
人们倾向于建议使用一种已知的技巧,该技巧通常用于在对象检查器上显示TForm后代的属性.诀窍是:通过设计时包将注册TForm后代的自定义模块注册到Delphi IDE:
RegisterCustomModule(TMyFrame,TCustomModule);

对象检查器可以用这种方式显示TFrame Descendant实例的其他属性,但是当它嵌入到表单中时会丢失其框架行为.不可重新设计,不可能为其子组件实现事件,并且它接受子控件(它没有).但它在自己的设计领域表现正常.

看起来,这些行为是由Delphi IDE专门为TFrame提供的.他们可能不是一般的设施.

有没有其他方法可以实现这一点而不会丢失框架行为?

我正在使用Delphi 2007

@Tondrej,

请提前阅读此问题的评论.

frameunit.dfm:

object MyFrame: TMyFrame
  Left = 0
  Top = 0
  Width = 303
  Height = 172
  TabOrder = 0
  object Edit1: TEdit
    Left = 66
    Top = 60
    Width = 151
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
  end
end
unit frameunit;

interface

uses
  Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;

type
  TBaseFrame = Class(TFrame)
  protected
    Fstr: string;
    procedure Setstr(const Value: string);virtual;
  published
    Property str:string read Fstr write Setstr;
  End;

  TMyFrame = class(TBaseFrame)
    Edit1: TEdit;
  private
    // This won't be called in designtime. But i need this to be called in designtime
    Procedure Setstr(const Value: string);override;
  end;

implementation

{$R *.dfm}

{ TBaseFrame }

procedure TBaseFrame.Setstr(const Value: string);
begin
  Fstr := Value;
end;

{ TMyFrame }

procedure TMyFrame.Setstr(const Value: string);
begin
  inherited;
  Edit1.Text := Fstr;
  // Sadly this code won't work and Edit1 won't be updated in designtime.
end;

end.
unit RegisterUnit;

interface

procedure Register;

implementation

uses
  Windows,DesignIntf,frameunit;

procedure Register;
var
  delphivclide: THandle;
  TFrameModule: TCustomModuleClass;
begin
  delphivclide := GetModuleHandle('delphivclide100.bpl');
  if delphivclide <> 0 then
  begin
    TFrameModule := GetProcAddress(delphivclide,'@Vclformcontainer@TFrameModule@');
    if Assigned(TFrameModule) then
    begin
      RegisterCustomModule(frameunit.TBaseFrame,TFrameModule);
      // Just registering that won't cause Tmyframe to loose its frame behaviours
      // but additional properties won't work well.

      //RegisterCustomModule(frameunit.TMyFrame,TFrameModule);  
      // That would cause Tmyframe to lose its frame behaviours
      // But additional properties would work well.

    end;
  end;
end;


end.

解决方法

您为框架注册了哪个自定义模块类?
您使用的是哪个版本的Delphi?

从我使用Delphi 2007的实验中,似乎有效的自定义模块类是TFrameModule.该类包含在delphivclide100.bpl中.由于没有相应的delphivclide.dcp,您必须手动加载它:

unit FrameTestReg;

interface

procedure Register;

implementation

uses
  Windows,FrameTest;

procedure Register;
var
  delphivclide: THandle;
  TFrameModule: TCustomModuleClass;
begin
  delphivclide := GetModuleHandle('delphivclide100.bpl');
  if delphivclide <> 0 then
  begin
    TFrameModule := GetProcAddress(delphivclide,'@Vclformcontainer@TFrameModule@');
    if Assigned(TFrameModule) then
      RegisterCustomModule(TTestFrame,TFrameModule);
  end;
end;

end.

我的FrameTest单元非常简单,它没有FrameTest.dfm,只有新TFrame后代的声明:

unit FrameTest;

interface

uses
  Forms;

type
  TTestFrame = class(TFrame)
  private
    FHello: string;
  published
    property Hello: string read FHello write FHello;
  end;

implementation

end.

使用TFrameModule类,到目前为止一切似乎都正常.我可以创建TTestFrame的新后代以包含在项目中并在Object Inspector中编辑其已发布的属性,将此新后代的实例放在IDE中的表单上,在Object Inspector中编辑它们的新发布属性,编写事件处理程序他们的子组件等.在.dfm资源中,我可以看到实例的预期“内联”指令.到目前为止我没有遇到任何问题,所以也许这就是解决方案.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读