• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

用户头像
it1352
帮助1

问题说明

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

Delphi object inspector doesn't show TFrame descendants's additional properties by design. People tend to suggest using a known trick which is commonly used for showing TForm descendant's properties on the Object inspector. The trick is: registering custom module for TForm descendants to Delphi IDE via design time package like:

RegisterCustomModule(TMyFrame, TCustomModule);

对象检查器可以以这种方式显示TFrame Descendant的实例的其他属性,但它失去了其帧行为而它以一种形式嵌入。不可重新设计,不可能为其子组件实施事件,它接受子控件(它不会)。但是它在自己的设计领域正常运行。

The object inspector can show additional properties of the TFrame Descendant's instance with this way but it loses its frame behaviours while it is embedded in a form. Not redesignable, not possible to implement events for its subcomponents and it accepts child controls (which it musn't). But it behaves normally in its own design area.

看起来,Delphi IDE特别为TFrame提供的行为。他们的概率不是一般的设施。

Looks like, those behaviours provided by Delphi IDE specially just for TFrame. They problaly are not kind of generic facilities.

有没有其他方法可以完成这个而不失去框架行为?

Is there any other way to accomplish this without losing frame behaviours ?

我使用的是Delphi 2007

I'm using Delphi 2007

@Tondrej,

阅读有关问题的评论,谢谢提前。

Read comments for the problem, thanks in advance.

frameunit.dfm:

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.

正确答案

#1

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

Which custom module class are you registering for your frame? Which version of Delphi are you using?

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

From my experiments with Delphi 2007, the custom module class which seems to work is TFrameModule. This class is contained in delphivclide100.bpl. Since there is no corresponding delphivclide.dcp you have to load it manually:

unit FrameTestReg;

interface

procedure Register;

implementation

uses
  Windows, DesignIntf,
  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的声明后代:

My FrameTest unit is very simple, it has no FrameTest.dfm, only the declaration of the new TFrame descendant:

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的新后代来包含在项目中,并在对象检查器中编辑其已发布的属性,将这个新的后代的实例放在IDE的窗体上,在对象检查器中编辑新的已发布属性,编写事件处理程序他们的子组件等。在.dfm资源中,我可以看到实例的预期inline指令。
我到目前为止还没有遇到任何问题,所以也许这是解决方案。

Using TFrameModule class, everything seems to work fine so far. I can create a new descendant of TTestFrame to include in the project and edit its published properties in the Object Inspector, put instances of this new descendant on a form in the IDE, edit their new published properties in the Object Inspector, write event handlers for their child components etc. In the .dfm resource I can see the expected "inline" directive for the instances. I haven't encountered any problem with it so far so perhaps this is the solution.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfjgih
系列文章
更多 icon
同类精品
更多 icon
继续加载