在对象检查器上显示TFrame后代的其他属性

Ser*_*est 11 delphi tframe

Delphi对象检查器不会按设计显示TFrame后代的其他属性.人们倾向于建议使用一种已知的技巧,这种技巧通常用于在对象检查器上显示TForm后代的属性.诀窍是:通过设计时包将注册TForm后代的自定义模块注册到Delphi IDE:

RegisterCustomModule(TMyFrame, TCustomModule);
Run Code Online (Sandbox Code Playgroud)

对象检查器可以通过这种方式显示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
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)

Oli*_*sen 0

不,我认为这完全不可能。

当我有类似的需求时,我通常所做的就是简单地将框架后代作为其本身的组件安装。但是,是的,这样你就失去了很多典型的框架行为(特别是在设计时),例如,你不能再直接操作子组件,并且对框架的​​更改不再自动传播到在设计时使用它的表单 - 你有首先重新编译包含该框架的运行时包。

话又说回来,从 OOP 的角度来看,这还不算太糟糕。它实际上强化了实现隐藏的概念。您仍然可以通过框架本身的新属性和方法公开子组件的各个属性和功能。