Raising cross-patform events (.NET plugin vs Delphi host)

antonk,
I’m sorry for posting on an old thread, but I’ve been searching for hours and this is the only hit I could find that was even close to the issue I’m having. I’m easily able to define the events in the interface, but I’m missing the step where that interface is consumed on the delphi side. I’ve created a Visual Plugin with two events:

event EventHandler LeftValueChanged;
event EventHandler RightValueChanged;

And imported that interface via the Hydra menu to generate the following code.

procedure add_LeftValueChanged(const value: EventHandler); safecall;
procedure remove_LeftValueChanged(const value: EventHandler); safecall;
procedure add_RightValueChanged(const value: EventHandler); safecall;
procedure remove_RightValueChanged(const value: EventHandler); safecall;

The problem I’m having is the Delphi compiler is giving me an error - Undeclared identifier ‘EventHandler’. What am I missing?

Hello

I’ve moved your post to a separate topic because the original thread you posted to was related to .NET host + .NET plugins pair.

This won’t work AS IS because Delphi knows notihng about the way .NET events are defined and managed:

event EventHandler LeftValueChanged;
event EventHandler RightValueChanged;

Instead you need to define method pair like

void AddListener(IListener value, Int32 eventKind);
void RemoveListener(IListener value, Int32 eventKind);

where eventKink is a code of the event you want to subscribe to/unsubscribe from.

IListener could be defined as

[Guid("EEE74183-854D-4A5F-AF2A-6A00AB10FB95")]
public interface IMessageProcessor: IHYCrossPlatformInterface
{
    void Execute();
}

So you just store reference to events executer in the AddListener method and remove it in the RemoveListener method.

Instead of raising an event you’ll need to call the Execute method of the listener instance.

Also please read this: https://docs.hydra4.com/HowTos/PassingInterfacesBetweenHostAndPlugins/

Regards

If I had a very simple .net plugin. Say, it only has a button on it.

How, using this process, would I set up a Delphi host to respond to the button click.

When the button is pressed in the c# plug in, I want the Delphi host to ShowMessage(‘Clicked’)

I’ve been playing with the steps defined in this thread, but cannot figure it out. I’m every experienced with .Net, not so much with Delphi so that is where I need the assistance.

Hello

Sorry for the belated answer. Take a look at this thread: Need simple sample

This is exactly the sample you need.