使用 TJvPluginManager 获得返回值的最佳方式

发布于 2024-10-04 00:20:17 字数 303 浏览 0 评论 0原文

我目前正在开发一个简单的程序,该程序实现带有 dll 库的插件(使用 JVCL 框架中的 TJvPluginManager)。

到目前为止,我弄清楚了如何使用此组件来处理命令,但是如果我想从库内的自定义函数获得返回值怎么办?是否可以使用 TJvPluginManager 从主机调用某个函数?我应该如何实施这个?

这个漏洞的想法是在每个 dll 内有一个返回字符串的函数,以便可以使用简单的 cicle 来调用它。我想我可以手动完成此操作(使用动态加载),但我想尽可能多地使用 TJvPluginManager。

谢谢您的宝贵时间。 约翰·马科

im currently working in a simple program that implements plugins whith dll libraries (using the TJvPluginManager from the JVCL Framework).

So far I figure out how to use this component to handle commands but what if i want to have a return value from a custom function inside the library?. It is posible to call a certain function from the host by using the TJvPluginManager? How should I implement this?.

The hole idea is to have a function that returns a string inside each dll so it can be called by using a simple cicle. I think I can do this by hand (using dinamic loading) but I want to work with TJvPluginManager as much as possible.

Thank you for your time.
John Marko

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

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

发布评论

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

评论(1

生生漫 2024-10-11 00:20:17

我这样做的方法是在插件中实现一个接口并从主机调用它,例如

MyApp.Interfaces.pas

uses
  Classes;

type
  IMyPluginInterface = interface
  ['{C0436F76-6824-45E7-8819-414AB8F39E19}']
    function ConvertToUpperCase(const Value: String): String;
  end;

implmentation

end.

插件:

uses
  ..., MyApp.Interfaces;

type
  TMyPluginDemo = class(TJvPlugIn, IMyPluginInterface)
  public
    function ConvertToUpperCase(const Value: String): String;
  ...

implmentation

function TMyPluginDemo.ConvertToUpperCase(const Value: String): String;
begin
  Result := UpperCase(Value);
end;

...

主机:

uses
  ..., MyApp.Interfaces;

...

function TMyHostApp.GetPluginUpperCase(Plugin: TjvPlugin; const Value: String): String;
var
  MyPluginInterface: IMyPluginInterface;
begin
  if Supports(Plugin, IMyPluginInterface, MyPluginInterface) then
    Result := MyPluginInterface.ConvertToUpperCase(Value)
  else
    raise Exception.Create('Plugin does not support IMyPluginInterface');
end;

希望这会有所帮助。

The way I do it is to implement an Interface in the plugin and call it from the host e.g.

MyApp.Interfaces.pas

uses
  Classes;

type
  IMyPluginInterface = interface
  ['{C0436F76-6824-45E7-8819-414AB8F39E19}']
    function ConvertToUpperCase(const Value: String): String;
  end;

implmentation

end.

The plugin:

uses
  ..., MyApp.Interfaces;

type
  TMyPluginDemo = class(TJvPlugIn, IMyPluginInterface)
  public
    function ConvertToUpperCase(const Value: String): String;
  ...

implmentation

function TMyPluginDemo.ConvertToUpperCase(const Value: String): String;
begin
  Result := UpperCase(Value);
end;

...

The host:

uses
  ..., MyApp.Interfaces;

...

function TMyHostApp.GetPluginUpperCase(Plugin: TjvPlugin; const Value: String): String;
var
  MyPluginInterface: IMyPluginInterface;
begin
  if Supports(Plugin, IMyPluginInterface, MyPluginInterface) then
    Result := MyPluginInterface.ConvertToUpperCase(Value)
  else
    raise Exception.Create('Plugin does not support IMyPluginInterface');
end;

Hope this helps.

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