views:

292

answers:

1

Hello,

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

+2  A: 

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.

Mason Wheeler
Thank you but I have no clue on how to implement this with the JvPlugin framework.I'm still trying to find a way correctly declare this in :- my JVPlugin (how to declare the AddCallback procedure in the declaration section).- my HostApplication (how to call the AddCallback procedure for exemple)
Stephane Wierzbicki
Are you sure OBones meant to implement this within the jvplugin framework?
Marco van de Voort
Just check JVCL newsgroup "What's the best way to send a message from a TJvPlugin to the host?" dated 03 Feb. 2009
Stephane Wierzbicki