如何在Delphi表单上创建新的IOTAComponent

Tom*_*omR 0 delphi form-designer opentools

我正在尝试编写Delphi Open Tools API工具,用于自动生成和更新放置在数据模块或表单上的组件.我已经可以列出所有组件(每个组件由(IOTAComponent的类)实例表示)并修改它们的属性(setPropByName(...),getPropValueByName(...)).问题是 - 如何创建新组件 - 在Open Tools API代码中,以便将此组件添加到datamodule的形式?

我正在使用IOTAModuleServices API的一部分,我猜这是手头任务的正确部分,不是吗?

Rem*_*eau 6

您需要获取IOTAFormEditor要更新的Form/DataModule 的接口,然后调用其CreateComponent()方法:

type
  IOTAFormEditor = interface(IOTAEditor)
    ['{F17A7BD2-E07D-11D1-AB0B-00C04FB16FB3}']
    ...
    function CreateComponent(const Container: IOTAComponent;
      const TypeName: string; X, Y, W, H: Integer): IOTAComponent;
    ...
  end;
Run Code Online (Sandbox Code Playgroud)