Delphi 对象检查器没有按设计显示 TFrame 后代的附加属性。人们倾向于建议使用通常用于在对象检查器上显示 TForm 后代属性的已知技巧。诀窍是:通过设计时包将 TForm 后代的自定义模块注册到 Delphi IDE,例如:
RegisterCustomModule(TMyFrame, TCustomModule);
对象检查器可以通过这种方式显示 TFrame 后代实例的其他属性,但它在嵌入表单时会丢失其帧行为。不可重新设计,无法为其子组件实现事件,并且它接受子控件(它不能)。但它在自己的设计区域中表现正常。
看起来,Delphi IDE 专门为 TFrame 提供的那些行为。它们可能不是一种通用设施。
有没有其他方法可以在不丢失帧行为的情况下做到这一点?
我正在使用德尔福 2007
@Tondrej,
阅读问题的评论,在此先感谢。
框架单元.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.