Delphi 应用程序的插件系统 - bpl 与 dll?

发布于 2024-07-29 12:57:42 字数 410 浏览 4 评论 0原文

我正在编写delphi应用程序,它应该具有加载插件的能力。 我使用 JvPluginManager 作为插件系统/管理器;)现在,在新的插件向导中,他们说最好使用 .bpl 类型插件而不是 .dll 插件......这个解决方案与 dll 类型插件相比有什么优点? 到目前为止,我只发现了这个解决方案的缺点:

  1. 我必须将所有通用接口单元放在单独的包中,以便在加载插件时不会抛出有关包含通用单元的其他包的任何错误

  2. 如果,比方说,一个插件开发人员决定使用一些众所周知的单元(如突触),默认情况下没有运行时包,第二个插件开发人员也这样做,比bump...它在这里崩溃...

那么,使用 bpls 而不是使用运行时包编译的 dll 实际上有什么优点呢?

提前致谢

I'm writing delphi app which should have capability of loading plugins. I'm using JvPluginManager as plugin system/manager ;) Now, in the new plugin wizard they say it's better to use .bpl type plugins instead of .dll plugins ... What are the pros of this solution versus dll type plugins?
So far I've found only cons of this solution:

  1. I have to put all the common interface units in separate package so that while loading plugins it won't throw any error about the other package containing common unit

  2. if, let's say, one of plugin developers decides to uses some well-known unit (like synapse), which doesn't have runtime package by default, and the second plugin developer does the same, than bump... it's crash here ...

So, what are actually the pros of using bpls instead of dlls compiled with runtime packages?

Thanks in advance

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

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

发布评论

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

评论(5

吻泪 2024-08-05 12:57:42

BPL 的另一个缺点。 当您切换 Delphi 版本时,您将必须重新分发新插件。 经过多次尝试寻找完美的插件系统,我最终选择了 COM,并且我从未后悔过这个决定。 在一个已经有插件需求超过 8 年的商业应用程序中,该应用程序不断向前发展,但第一次迭代发布的一些插件仍然以其原始形式存在。

如果您选择此方法,请帮自己一个忙,从一个简单的界面开始,然后在其上添加新的界面。 您不想更改您的基本界面,因此请保持简单而可爱。

Another disadvantage to BPL's. When you switch Delphi versions you will have to re-distribute new plugins. After many attempts at attempting to find the perfect plugin system, I ended up with COM and I have never regretted that decision. In a commercial application which has had the plugin requirement for over 8 years, the application has continued to move forward and yet some of the plugins that were released with the first iteration still exist in their ORIGINAL form.

If you choose this method, do yourself a favor and start with a simple interface and then add new interfaces upon it. You don't want to ever change your base interface, so keep it simple and sweet.

浅忆 2024-08-05 12:57:42

正如 Alexander 所说,BPL 基本上是一个 DLL。 但有一些条件(来自我所做的一个不太简短的总结:http://wiki.freepascal.org/包):

  • 一个单元只能在 BPL 的 +Exe 中存在一次。 这避免了状态重复(堆管理器和系统等其他全局变量、VMT 表等的两倍)
  • 。BPL 只能使用其他 .BPL。
  • 这意味着像 ansistring 和 IS/AS 这样的动态类型可以在 BPL 接口上正常工作。
  • 初始化/终止是单独的过程,并且它们的初始化顺序受到严格控制。 对于静态动态加载,这更简单,对于动态加载(类似插件),会检查对单元的所有依赖性。
  • 一切本质上都是一个大程序,这意味着 BPL 必须使用相同的编译器版本和 RTL 进行编译,并且取决于版本的其他依赖项。 将 .BPL 插入现有 EXE 可能会更困难,因为 Delphi 版本必须匹配。
  • 这也意味着您必须为插件 .BPL 所依赖的(非 Delphi).BPL 提供 .dcp。

简而言之:如果插件架构是开放的,则将其设为 DLL。 否则人们必须拥有完全相同的 Delphi 版本才能编写插件。

混合动力也是可能的。 一个更高级别的 .BPL 接口,用于您自己分解到 .BPL 和选定的开发中的功能,以及用于其余部分的底层程序 DLL 接口。

第三种选择是使用 DLL,但指定 Sharemem。 字符串可以工作,多个 Delphi 版本都可以工作。 对象可以工作,但不安全(例如,我猜早期版本的 D2009 无法工作)。 即使其他语言的用户也可以通过 COM 进行分配,但并不完全排除非 Delphi。

As Alexander said, a BPL is basically a DLL. But there are some conditions (from a not-so-short summary I made: http://wiki.freepascal.org/packages ):

  • A unit can only exist once in BPL's +Exe. This avoids duplication of state (twice the heapmanager and other global vars of system etc, VMT tables etc)
  • .BPL's can only USE other .BPLs.
  • This means that dynamic types like ansistring and IS/AS work properly over BPL interfaces.
  • Initialization/finalization are separate procedure and their initialization order is strictly controlled. For static dynamic loading this is simpler, for dynamic loading (plugin-like) all dependancies on units are checked .
  • Everything is essentially one big program, which means that the BPL's must be compiled with the same compiler version and RTL and depends on the versions other dependancies. It might be harder to make .BPL's to plugin to an existing EXE, since the Delphi version must match.
  • This also means that you must deliver .dcp's for (non Delphi) .BPLs the plugin .BPLs depend on

In short: if the plugin architecture is open, make it a DLL. Otherwise people have to have the exact same Delphi version to write plugins.

Hybrid is also possible. An higher level .BPL interface for functionality you factor out into .BPL yourself and selected devels, and a rock bottom procedure DLL interface for the rest.

A third option is using DLLs, but ordain Sharemem. Strings will work, multiple Delphi versions will work. Objects can work but are unsafe (e.g. I guess e.g. D2009 with an earlier version wouldn't work). Even other language users might be able to allocate over COM, not entirely excluding non Delphi.

失去的东西太少 2024-08-05 12:57:42

你的第一个骗子也是一个专家。 如果在每个 dll 中复制共享代码,则 dll 会变得越来越大。 即使使用 dll,您也可以通过将共享代码移动到单独的 dll 中来防止这种情况。

优点:

  1. 类型是共享的。 没有 TFont 不是 TFont 问题
  2. 内存管理器是共享的。 字符串和类可以毫无问题地用作插件之间的参数。

缺点:

  1. 插件只能使用 Delphi 或 BCB 构建。
  2. 插件应使用相同的 Delphi 或 BCB 版本。

您考虑过使用COM吗? COM 使得共享类型、字符串和类成为可能,并且插件可以用多种编程语言编写。

Your first con is also a pro. If you replicate shared code in each dll the dlls get bigger and bigger. Even when using dlls you can prevent this by moving shared code in a separate dll.

Pros:

  1. Types are shared. No TFont is not a TFont problem
  2. Memory manager is shared. Strings and classes can be used as parameter between plugins without problems.

Cons:

  1. Plugins can be built using Delphi or BCB only.
  2. Plugins should use the same Delphi or BCB version.

Have you considerd using COM? COM makes it possible to share types, strings and classes and the plugins can be written in many programming languages.

甜宝宝 2024-08-05 12:57:42

我不熟悉 JvPluginManager,但这取决于您将如何使用 BPL。

基本上,BPL - 只是一个普通的 DLL,但它的初始化/最终化工作从 DllMain 中剥离出来,以单独的函数:“Initialize”/“Finalize”。

因此,如果您要像通常的 DLL 一样使用 BPL,据我所知,没有缺点,只有优点:DllMain 不会再出现麻烦。 就这样。 唯一的区别。

但Delphi中的BPL也提供了一种便捷的代码共享方式。 这意味着巨大的优势(通用内存管理器,没有重复的代码等)。 所以通常的 BPL 所做的不仅仅是“只是一个 DLL”。
但这也意味着,现在您的插件系统仅限于 Delphi(好吧,也可能是 C++ Builder)。 即插件和exe必须在同一个编译器中编译才能顺利运行。

如果这对您来说是可以接受的(即没有 MS Visual Studio,不,先生,永远不会) - 那么继续吧,您可以使用 BPL 的所有功能。

PS 但是,如果您不仔细设计界面,那么升级此类 BPL 插件也可能是一场噩梦。 在某些最坏的情况下,您可能需要重新编译所有内容。
PPS 就像我说的:我不知道它如何应用于由 JvPluginManager 创建的插件。

I'm not familiar of JvPluginManager, but it depends on how you're going to use BPLs.

Basically, BPL - is just a usual DLL, but its initialization/finalization work is stripped from DllMain to separate functions: 'Initialize'/'Finalize'.

So, if you're going to use BPL like usual DLL, there are no cons that I'm aware of, only pros: there will be no more troubles with DllMain. That's all. The only difference.

But BPL in Delphi also provide a convient way to share code. This means great advantages (common memory manager, no duplicated code, etc, etc). So usual BPL does a lot more than "being just a DLL".
But this also means, that now your plugin system is limited to Delphi only (well, may be C++ Builder too). I.e. both plugins and exe MUST be compiled in the very same compiler to run smoothly.

If this is acceptable for you (i.e. no MS Visual Studio, no, sir, never) - then go ahead, you can use all power of BPLs.

P.S. But upgrading such BPLs plugins can be also a nightmare, if you do not design interface side carefully. In certain worst cases, you may need to recompile everything.
P.P.S. Like I said: I have no idea, how it is applied to plugins, created by JvPluginManager.

佞臣 2024-08-05 12:57:42

避免 blp 方法,因为您将不得不随软件一起运送一大袋 bpl,因此分发将变得庞大。

为什么我们使用 Delphi 来编译小型独立程序,这些程序可以在任何地方运行而无需任何运行时依赖。 使用 bpls 就意味着违背了这个目的。

我不知道您对 DLL 是否满意,但我建议您使用 DLL。

  • 这将为其他开发人员(谁
    可能会对您的软件感兴趣)
    有机会使用任何开发
    语言(只要该语言
    可以吐出dll)自己写
    可以在您的应用程序中使用的插件
    开发的软件。
  • 另一件事是你将会
    从Delphi的vcl版本保存
    依赖性暴政。 主要弱点
    迄今为止德尔福的点。

Avoid blp approach as you will have to ship a big bag of bpl with you software and thus, distribution will become bulky.

why do we use Delphi to compile small stand alone programs that just RUN anywhere without any runtime dependency. Using bpls means defeating this very purpose.

I don't know as to how comfortable you are with DLLs, but I would suggest you to use DLLs.

  • This will give other developers (who
    may get interested in your software)
    a chance to use any development
    language (as long as that language
    can spit out dll) to write their own
    plugins that can be used in your
    developed software.
  • Another thing is that you will be
    saved from Delphi's vcl version
    dependency tyranny. A major weak
    point of Delphi till date.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文