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

发布于 2024-09-15 20:54:49 字数 1054 浏览 2 评论 0原文

经过多次搜索,看起来我必须分配 RegisterComponentsProcRegisterPropertyEditorProc,我已经完成了。

但是,我认为我可以调用我的设计时 Register 函数,即 .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() <=== aaargh!!

那么,我的 RegisterPropertyEditorProc 正文中应该有什么?

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

After much searching, it looks like I have to assign RegisterComponentsProc and RegisterPropertyEditorProc, which I have done.

However, I thought that I could call my design time Register function, i.e. <myComponentUnit>.Register();.

When I do I get stack overflow, because, well ...

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

end;

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

So, I call .Register();
which calls RegisterPropertyEditor()
which call RegisterPropertyEditorProc()
which calls RegisterPropertyEditor() <=== aaargh!!

So, what should I have in the body of my RegisterPropertyEditorProc ?

After further searching, it looks like I want to call DesignEditors.RegisterPropertyEditor() directly, but it is not in the interface section ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千と千尋 2024-09-22 20:54:49

尝试在运行时注册属性编辑器是没有意义的,因为它一开始在运行时不可用。它只能在设计时在 IDE 中使用。

There is no point in trying to register a property editor at run-time, as it is not usable at run-time to begin with. It is only usable within the IDE during design-time.

渡你暖光 2024-09-22 20:54:49

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

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

你是对的,你应该调用你单位的注册程序。但这是您启动注册过程的方式,而不是实现注册过程的方式。这部分取决于你; Delphi 不为您提供任何这些。

Delphi does not include the source for the DesignEditors unit; its implementation is provided solely in the DesignIDE package. That package has access to IDE internals, such as the list of registered property editors. The IDE assigns values to the RegisterComponentsProc and RegisterPropertyEditorProc callback functions. As you noticed, RegisterPropertyEditor calls RegisterPropertyEditorProc. The IDE provides its own function to handle that event.

If you want to register a property editor at run time, then your program plays the role of the IDE. You need to provide implementations for those callback functions to register the property-editor classes with your own property-editing framework. You could probably just keep everything in a simple list. Then, when you want to know what kind of editor to display for a certain type of property, consult the list to find the best match.

You're correct that you should call your units' Register procedures. But that's how you initiate the registration process, not how you implement it. That part's up to you; Delphi doesn't provide any of this for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文