出于设计考虑,Delphi对象检查器不显示TFrame的子类的附加属性。人们倾向于建议使用一种已知的技巧来显示Object Inspector上TForm子类的属性。这个技巧是:通过设计时包将TForm子类的自定义模块注册到Delphi IDE中。
RegisterCustomModule(TMyFrame, TCustomModule);
对象检查器可以通过这种方式显示TFrame派生类实例的其他属性,但是当它嵌入到一个窗体中时,它会失去它的框架特性。不可重新设计,不可能为其子组件实现事件,并且它接受子控件(这是不应该的)。但是,在其自己的设计区域中,它的行为正常。
看起来,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.