如何在Delphi项目中拥有多个类型库?
如果您有一个 Delphi 项目并想向其中添加类型库,那么您可以非常轻松地完成。
但是,我们希望能够添加多个不同的类型库。 Delphi XE IDE 似乎强制您拥有一个且仅有一个名为“
MyProject.tlb
我希望能够在我们的主项目中拥有多个类型库并执行 COM 插件”的类型库,但我不想要一个单一的类型库,而是用于各种不同类型插件的多个类型库。
这可行吗?难道只是 IDE 强制执行“只能有一个 TLB”规则吗?
If you have a Delphi project and want to add a type library to it, you can pretty easily.
However, we want to be able to add multiple different type libraries. The Delphi XE IDE seems to force you to have one and only one type library that is named
MyProject.tlb
I'd like to be able to have multiple type libraries in our main project and do COM Plugins, but I don't want one monolithic type library, but rather multiple type libraries for various different types of plugins.
Is this doable? Is it just the IDE that is enforcing the "There can only be one TLB" rule?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你当然可以。在二进制文件的最终编译中,类型库仅被视为另一种资源。
听起来您的 IDE 将您限制为一种类型库。如果您可以编辑原始 .RC 文件,您可以在其中包含对 .tlb 的引用。
EG.. 来自 .RC 文件的 TEXTINCLUDE 部分。
资源编译器应将其作为第二个 TYPELIB 资源包含在内。我只是手动完成此操作,没有使用 Visual Studio 提供的支持。
编译完 EXE 后,我打开它并查看资源。有两个类型库。
我希望这会有所帮助。
You most certainly can. Type libs are just treated as another resource in the final compilation of the binary.
It sounds like your IDE is limiting you to one type lib. If you can edit the raw .RC file you can include a reference to your .tlb there.
E.G... From the TEXTINCLUDE section of the .RC file.
The resource compiler should include it as a second TYPELIB resource. I just did this by hand, I didn't use the support Visual Studio provided.
Once I compiled my EXE I opened it up and looked at the resources. There were two type libs.
I hope this helps.
AFAIK,IDE 不支持项目中的多个 TypeLibraries。但是,您可以做的是创建单独的外部类型库(文件 > 新建 > 其他 > Delphi 项目 > 活动 > 类型库)来创建独立的 .tlb 文件,将它们注册到操作系统,然后在如果需要,您项目的类型库。
但是,如果您所做的只是创建主项目使用的 COM 插件,则无需在主项目中包含 COM 插件 TypeLibraries。您所需要的只是接口定义。只需在需要时将生成的
_TLB.pas
单元添加到主项目的uses
子句中即可。不要将实际的 .tlb 文件本身添加到您的主项目中。AFAIK, the IDE does not support multiple TypeLibraries in a project. What you can do, however, is create separate external TypeLibraries (File > New > Other > Delphi Projects > Active > Type Library) to create standalone .tlb files, register them with the OS, and then reference them in your project's TypeLibrary if needed.
However, if all you are doing is creating COM plugins that your main project consumes, then there is no need to include the COM plugin TypeLibraries in your main project. All you need is the interface definitions. Simply add the generated
<UnitName>_TLB.pas
units to your main project'suses
clauses where needed. Do not add the actual .tlb files themselves to your main project.