如何在DLL中实现一个回调方法(Delphi / TJVPluginManager + TJvPlugin) [英] How to implement a callback method within DLL (Delphi / TJVPluginManager + TJvPlugin)

查看:142
本文介绍了如何在DLL中实现一个回调方法(Delphi / TJVPluginManager + TJvPlugin)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用插件的应用程序。我使用优秀的JVCL插件框架。我首先开始使用包插件。它的工作方式像一个魅力,但有一个很大的缺点:需要给运行时bpl(23Mo)。所以我切换到DLL插件。



我需要从hostapplication调用一个方法(过程有3个参数),但我不知道该怎么做。在Jedi新组中解释的OBone使用回调函数,但我没有如何实现这一点的线索。



有人可以解释我或更好,给我一个例子吗?



预先感谢



BR

您可以使用JVCL 1SimplePlugin演示并更新它。

Stephane Wierzbicki

解决方案

基本概念很简单。回调方法是一个指向一个方法的指针,您传递给某些代码,以便它可以在特定时间调用它,以允许您自定义其行为。如果你对Delphi有任何经验,你已经熟悉不同名称的回调方法:事件处理程序。



在你的插件中尝试这样:

  type 
TMyEvent = procedure(param1,param2,param3:integer)

procedure AddCallback(callback:TMyEvent);

此过程将传递TMyEvent方法指针并将其存储在某处。让我们说在一个名为FCallback的变量。当它调用你的应用程序的时候,代码如下:

 如果分配(FCallback)然后
FCallback(param1,param2,param3);

在设置插件时, p>

  MyPlugin.AddCallback(self.callbackProc);有时你需要在它前面放一个@(@ self.callbackProc),所以编译器可以告诉它是一个方法指针,而不是一个方法调用,但这并不总是必要的。


I'm building an application working with plugins. I'm using the excellent JVCL plugin framework. I first started to use package plugin. It worked like a charm but had a big drawback : the needs to give runtimes bpl (23Mo). So I switch to DLL plugin.

I need to call a method (procedure having 3 parametes) from hostapplication but I don't know how to do it. OBones explained in the Jedi newgroup to use callback functions but I have no clue on how to achieve this.

Can someone kindly explain me or better, send me an example? You can take the JVCL 1SimplePlugin demo and update it.

Thank in in advance

BR

Stephane Wierzbicki

解决方案

The basic concept is pretty simple. A callback method is a pointer to a method that you pass to some code so that it can call it at a specific time to allow you to customize its behavior. If you have any experience at all with Delphi, you're already familiar with callback methods under a different name: "event handlers".

Try something like this in your plugin:

type
   TMyEvent = procedure(param1, param2, param3: integer) of object;

procedure AddCallback(callback: TMyEvent);

This procedure would take the TMyEvent method pointer passed in and store it somewhere. Let's say in a variable called FCallback. When the time comes for it to call your app, the code would look like this:

if assigned(FCallback) then
   FCallback(param1, param2, param3);

You would call it from your app like this, when you're setting up the plugin:

MyPlugin.AddCallback(self.callbackProc);

Sometimes you'll need to put an @ in front of it (@self.callbackProc) so the compiler can tell that it's a method pointer and not a method call, but this is not always necessary.

这篇关于如何在DLL中实现一个回调方法(Delphi / TJVPluginManager + TJvPlugin)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆