Best way to get return value with TJvPluginManager

im is currently working in a simple program that implements plugins with DLLs (using the TJvPluginManager from the JVCL Framework).

So far I have figured out how to use this component to process commands, but what if I want to get the return value from a user-defined function inside the library ?. Is it possible to call a specific function from the host using TJvPluginManager? How do I implement this?

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

Thank you for your time. John Marco

+3
source share
1 answer

How I do this is to implement the interface in the plugin and call it from the host, for example.

MyApp.Interfaces.pas

uses
  Classes;

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

implmentation

end.

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;

...

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.

+6
source

Source: https://habr.com/ru/post/1776862/


All Articles