Delphi对象检查器不会按设计显示TFrame后代的其他属性.
@H_403_2@人们倾向于建议使用一种已知的技巧,该技巧通常用于在对象检查器上显示TForm后代的属性.诀窍是:通过设计时包将注册TForm后代的自定义模块注册到Delphi IDE:
RegisterCustomModule(TMyFrame,TCustomModule);@H_301_5@对象检查器可以用这种方式显示TFrame Descendant实例的其他属性,但是当它嵌入到表单中时会丢失其框架行为.不可重新设计,不可能为其子组件实现事件,并且它接受子控件(它没有).但它在自己的设计领域表现正常. @H_301_5@看起来,这些行为是由Delphi IDE专门为TFrame提供的.他们可能不是一般的设施. @H_301_5@有没有其他方法可以实现这一点而不会丢失框架行为? @H_301_5@我正在使用Delphi 2007 @H_301_5@@Tondrej, @H_301_5@请提前阅读此问题的评论. @H_301_5@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.
解决方法
您为框架注册了哪个自定义模块类?
@H_403_2@您使用的是哪个版本的Delphi?
@H_301_5@从我使用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.@H_301_5@我的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.@H_301_5@使用TFrameModule类,到目前为止一切似乎都正常.我可以创建TTestFrame的新后代以包含在项目中并在Object Inspector中编辑其已发布的属性,将此新后代的实例放在IDE中的表单上,在Object Inspector中编辑它们的新发布属性,编写事件处理程序他们的子组件等.在.dfm资源中,我可以看到实例的预期“内联”指令.到目前为止我没有遇到任何问题,所以也许这就是解决方案.