Re: Events
Jim <[email protected]> Tue, 20 Sep 2016 16:48:51 -0600
| Newsgroups | gmane.comp.java.ikvm.devel |
|---|---|
| Message-ID | <[email protected]> |
Jeroen,
Thanks for the input, it pointed me in the direction of delegates. What
I really need is the callback, and that seems to work with delegates.
This:
http://weblog.ikvm.net/2009/03/11/DefiningDelegatesInJava.aspx
seems to be the goto page.
My one remaining issue is not particularly IKVM related, but I'm hoping
there's a VB expert on the list who can tell me what this:
|java.lang.Threadthread =newjava.lang.Thread(
ikvm.runtime.Delegates.toRunnable(delegate{
Console.WriteLine("Hello World");
}));
thread.start();
|
|would look like in VB. Actually, I have this:
|
publicdelegatevoidMessageDelegate(MessageNotifierEventArgsargs);
messageNotifier.addDelegate(delegate(MessageNotifierEventArgse){
Console.WriteLine("TheHostCommandMessage{1}wasreceivedwithStatus{0}.",e.Status,e.Message);
});
but the general information delegates in VB would probably be enough.
Thanks,
Jim
On 09/17/2016 02:12 AM, Jeroen Frijters wrote:
> Hi Jim,
>
> There's no support for defining events from the Java side.
>
> Regards,
> Jeroen
>
>> -----Original Message-----
>> From: Jim [mailto:[email protected]]
>> Sent: Friday, September 16, 2016 23:15
>> To: [email protected]
>> Subject: [Ikvm-developers] Events
>>
>> Given this C# snippet:
>>
>> class MainClass
>> {
>> public static void Main (string[] args)
>> {
>> [...]
>> MessageReceiveNotifier messageNotifier = [...]
>> messageNotifier.MessageReceived +=
>> c_HostCommandMessageReceived;
>> [...]
>> }
>>
>> static void c_HostCommandMessageReceived (object sender,
>> MessageNotifierEventArgs e)
>> {
>> // the status will be -1 to indicate an unsolicited message.
>> Console.WriteLine ("The Host Command Message {1} was
>> received with Status {0}.", e.Status, e.Message);
>> [...]
>> }
>> }
>>
>> I would expect that this in Java:
>>
>> import cli.System.EventHandler;
>>
>>
>> public class MessageReceiveNotifier {
>>
>> [...]
>>
>> public static void add_MessageReceived(EventHandler
>> messageReceivedEventHandler) {
>> }
>>
>> public static void remove_MessageReceived(EventHandler
>> messageReceivedEventHandler) {
>>
>> }
>>
>> }
>>
>> Would meet the requirements of the line:
>>
>>
>> messageNotifier.MessageReceived += c_HostCommandMessageReceived;
>>
>> However MonoDevelop gives me the error:
>>
>> Type 'MessageReceiveNotifier' does not contain a definition for
>> 'MessageReceived' and no extension method 'MessageReceived' of type
>> 'MessageReceiveNotifier' can be found. Are you missing an assembly
>> reference?
>>
>> The Java class are in the same assembly and there is no complaint about
>> MessageReceiveNotifier (and the MessageNotifierEventArgs class) so I
>> think that the assemblies are all correct.
>>
>> I have tried static and non-static for the add_ remove_ methods.
>>
>> Help and ideas would be much appreciated?
>>
>> Thanks,
>>
>> Jim
>>
>>
>> --
>> Jim Redman
>> (505) 662 5156 x85
>> http://www.ergotech.com
--
Jim Redman
(505) 662 5156 x85
http://www.ergotech.com
------------------------------------------------------------------------------
_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers