I created C# DLL with simple class for testing event:
B4X:
using System;
using System.Collections.Generic;
using System.Text;
namespace EventHandlersTest
{
public delegate void MyEventHandler();
public class MyEvent
{
public event MyEventHandler SomeEvent;
public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
public void Test(int X)
{
if (X == 10)
OnSomeEvent();
}
}
}
B4PPC code:
(ME - MyEvent.dll)
B4X:
Sub App_Start
Form1.Show
ME.New1
End Sub
Sub Button1_Click
ME.Test(10)
End Sub
Sub ME_OnSomeEvent
Msgbox("SomeEvent!")
End Sub
But, if I clicked on Button1, event OnSomeEvent doesn't work.
How to correct?
:sign0085:
Erel, unfortunately, still it is not clear... In an example, event is anchored to already available event of ScrollBar, but in my case, event is required for the self class. I tried various variants, but I receive either an error, or event doesn't work in B4PPC...
I will be grateful, if somebody helps with example on a C #.
Like this I think. Compare it to the ScrollBar code.
B4X:
namespace EventHandlersTest
{
// at runtime tells Basic4ppc what event has occurred
private object[] SomeEventEventObject;
// at compile times identifies the event to Basic4ppc
// at runtime Basic4ppc sets this to its event handler
public event EventHandler SomeEvent;
public class MyEvent
{
SomeEventEventObject = new object[] { this, "SomeEvent" };
}
public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
public void Test(int X)
{
if (X == 10)
OnSomeEvent();
}
}
}