如何在Delphi项目中拥有多个类型库?

发布于 2024-12-29 13:45:23 字数 268 浏览 2 评论 0原文

如果您有一个 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 技术交流群。

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

发布评论

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

评论(2

沉溺在你眼里的海 2025-01-05 13:45:23

你当然可以。在二进制文件的最终编译中,类型库仅被视为另一种资源。

听起来您的 IDE 将您限制为一种类型库。如果您可以编辑原始 .RC 文件,您可以在其中包含对 .tlb 的引用。

EG.. 来自 .RC 文件的 TEXTINCLUDE 部分。

3 TEXTINCLUDE  
BEGIN
    "1 TYPELIB ""junk.tlb""\r\n"
    "\0"
END

4 TEXTINCLUDE  
BEGIN
    "2 TYPELIB ""junk2.tlb""\r\n"
    "\0"
END

资源编译器应将其作为第二个 TYPELIB 资源包含在内。我只是手动完成此操作,没有使用 Visual Studio 提供的支持。

编译完 EXE 后,我打开它并查看资源。有两个类型库。

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.

3 TEXTINCLUDE  
BEGIN
    "1 TYPELIB ""junk.tlb""\r\n"
    "\0"
END

4 TEXTINCLUDE  
BEGIN
    "2 TYPELIB ""junk2.tlb""\r\n"
    "\0"
END

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.

Two Type Libraries in an EXE

I hope this helps.

断念 2025-01-05 13:45:23

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's uses clauses where needed. Do not add the actual .tlb files themselves to your main project.

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