如何在Delphi窗体上创建新的IOTAComponent

问题描述:

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

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

您需要获得IOTAFormEditor接口要更新表格/ 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;