Delphi - 视觉表单继承 - 组件基类检测
我正在使用 VFI(视觉表单继承),我需要检查实例化表单的组件是否属于表单类或表单超类。
有什么想法吗?
unit1
TFormStatus = class(TForm)
cpPanel: TPanel;
lblStatus: TLabel;
end;
unit 2
TFormCodigo = class(TFormStatus)
lblCodigo: TLabel;
end;
frmCodigo: TFormCodigo:
在 frmCodigo 的任何实例中,我想检测 lblCodigo 是 TFormCodigo 的本地组件,并且 cpPanel / lblStatus 是继承的组件;
for i:=0 to Self.ComponentCount-1 do begin
if "InheritedComponent" (Self.Components[i]) then ...
end;
使用 RTTI 作为对象属性可以实现类似的操作,但我不知道对于组件是否可以。
谢谢。
I'm using VFI (Visual Form Inheritance) and I need to check if a component of an instantiated form belongs to the formclass or to the form superclass.
any ideas ?
unit1
TFormStatus = class(TForm)
cpPanel: TPanel;
lblStatus: TLabel;
end;
unit 2
TFormCodigo = class(TFormStatus)
lblCodigo: TLabel;
end;
frmCodigo: TFormCodigo:
In any instances of frmCodigo I want to detect that lblCodigo is local to TFormCodigo and cpPanel / lblStatus are inherited components;
for i:=0 to Self.ComponentCount-1 do begin
if "InheritedComponent" (Self.Components[i]) then ...
end;
Something like this is possible using RTTI for object properties, but I dont know if it is possible for components.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解正确的话,您需要 TRttiMember.Parent。例如,请参阅 Rob Love 撰写的这篇文章。我认为您需要 Delphi 2010 或更高版本。
事实上,这只是 优秀文章系列 - 这些文章还将告诉您如何获取字段、属性等,而不必知道它们的名称。
If I understand you correctly, you need TRttiMember.Parent. For example see this article by Rob Love. You'll need Delphi 2010 or later I think.
In fact this is just part of an excellent series of articles - these articles will also tell you how to get hold of the fields, properties etc. without having to know their names.
也许像这样“愚蠢”的东西
已经满足了您的需求?
Maybe something "stupid" like
already fulfils your needs?
在 TFormCordigo 中,您可以重写每次读取特定表单的资源时调用的 ReadState 方法。继承后,称为 ComponentCount 包含截至层次结构的当前成员创建的组件数量,因此您毕竟拥有可以保存在其他地方的组件边框列表。
下面的代码说明了这种方法
In your TFormCordigo you can override ReadState method that is called every time a resource is read for a particular form. After inherited called ComponentCount contains the number of components created up to the current member of hierarchy, so after all you have list of borders for components that you can save elsewhere.
The code below illustrates this approach