如何在运行时注册组件和属性编辑器?

时间:2010-08-25 05:32:58

标签: delphi vcl

经过大量搜索后,看起来我必须分配RegisterComponentsProcRegisterPropertyEditorProc,我已经完成了。

但是,我认为我可以调用我的设计时间寄存器功能,即<myComponentUnit>.Register();

当我这样做时,我得到堆栈溢出,因为,好吧......

procedure myComponentUnit.Regiter;
begin
  RegisterPropertyEditor(TypeInfo(Integer), 
                         TMyComponent, 'myProperty',   TMyProperty);

端;

procedure RegisterPropertyEditor(PropertyType: PTypeInfo;
  ComponentClass: TClass; const PropertyName: string;
  EditorClass: TPropertyEditorClass);
begin
  if Assigned(RegisterPropertyEditorProc) then
    RegisterPropertyEditorProc(PropertyType, ComponentClass, PropertyName,
      EditorClass);
end;

所以,我打电话给.Register();
它调用RegisterPropertyEditor()
其中调用RegisterPropertyEditorProc()
调用RegisterPropertyEditor()&lt; === aaargh !!

那么,我应该在RegisterPropertyEditorProc的主体中拥有什么?

进一步搜索后,看起来我想直接调用DesignEditors.RegisterPropertyEditor(),但它不在界面部分......

2 个答案:

答案 0 :(得分:5)

尝试在运行时注册属性编辑器没有意义,因为它在运行时无法使用。它仅在设计时在IDE中可用。

答案 1 :(得分:4)

Delphi不包含DesignEditors单元的源代码;它的实现仅在DesignIDE包中提供。该包可以访问IDE内部,例如注册的属性编辑器列表。 IDE将值分配给RegisterComponentsProc和RegisterPropertyEditorProc回调函数。正如您所注意到的,RegisterPropertyEditor调用RegisterPropertyEditorProc。 IDE提供了自己的函数来处理该事件。

如果要在运行时注册属性编辑器,则程序将扮演IDE的角色。您需要为这些回调函数提供实现,以使用您自己的属性编辑框架注册属性编辑器类。您可以将所有内容保存在一个简单的列表中。然后,当您想知道要为特定类型的属性显示哪种编辑器时,请查看列表以找到最佳匹配。

你应该打电话给你的单位的注册程序。但这就是启动注册过程的方式,而不是实现的方式。那部分取决于你;德尔福不为您提供任何此类服务。