🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.csharpbuilder.language.csharp
10 messages
10 total messages Started by Francois PIETTE [ICS - MidWare] Sat, 29 Jul 2006 15:23
event versus simple delegate
#235
Author: Francois PIETTE [ICS - MidWare]
Date: Sat, 29 Jul 2006 15:23
20 lines
1879 bytes
I'm proting Delphi code to C#.
Delphi use unicast events while C# use multicast events. No problem.
I have a set of Delphi classes which for some operation communicates only 
between them using Delphi events.
Porting to C#, I can create C# events corresponding to Delphi events. But 
those C# events will of course be unicast only.
So I ask myself if it is not better to use a simple delegate instead of an 
event. A simple delegate is much like a Delphi event and is enough for the 
code I'm porting and is probably much faster. I would use C# events only for 
the Delphi events exposed to the outside world which of course may need C# 
multicast events.

Any advice appreciated.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
Re: event versus simple delegate
#236
Author: Joanna Carter [TeamB]
Date: Sat, 29 Jul 2006 15:42
35 lines
1773 bytes
"Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> a �crit dans 
le message de news: 44cb7da5$1@newsgroups.borland.com...

| Porting to C#, I can create C# events corresponding to Delphi events. But
| those C# events will of course be unicast only.

Not necessarily :-) .C# delegates are always multicast, but you can assign 
only one handler if you wish.

  public delegate void TestHandler(int value);

  {
    private void HandleTest(int value)
    {
      // handler code
    }

    private TestHandler test;

    private void CallTest()
    {
      test = HandleTest; singlecast
      test(123);
      test += HandleTest; // now multicast
    }
  }

You can see that both assigning (singlecast) and += (multicast) are both 
available.

Joanna

-- 
Joanna Carter [TeamB]
Consultant Software Engineer 
Re: event versus simple delegate
#237
Author: Marc Rohloff TeamB
Date: Sat, 29 Jul 2006 16:08
15 lines
1678 bytes
On Sat, 29 Jul 2006 17:23:08 +0200, Francois PIETTE [ICS - MidWare]
wrote:
> Delphi use unicast events while C# use multicast events. No problem.
> I have a set of Delphi classes which for some operation communicates only 
> between them using Delphi events.
> Porting to C#, I can create C# events corresponding to Delphi events. But 
> those C# events will of course be unicast only.

Why can't the C# event be multicast?

BTW, Both Delphi and C# can be made to do unicast or multicast.

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Re: event versus simple delegate
#238
Author: Francois PIETTE [ICS - MidWare]
Date: Sat, 29 Jul 2006 18:24
22 lines
1908 bytes
>> Delphi use unicast events while C# use multicast events. No problem.
>> I have a set of Delphi classes which for some operation communicates only
>> between them using Delphi events.
>> Porting to C#, I can create C# events corresponding to Delphi events. But
>> those C# events will of course be unicast only.
>
> Why can't the C# event be multicast?

I probably not expressed it correctly.
C#events are multicast.

> BTW, Both Delphi and C# can be made to do unicast or multicast.

Delphi events are unicast, altough you can write code to make something 
similar to an even multicast.

Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html
--
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
Re: event versus simple delegate
#239
Author: Francois PIETTE [ICS - MidWare]
Date: Sat, 29 Jul 2006 18:27
53 lines
2445 bytes
I was speaking about C# v1 which has a slightly different syntax.

Can you explain what difference there is (C# V1) declaring an event member 
using the event keyword and declaring a member which is simply a delegate ?

-- 
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be


"Joanna Carter [TeamB]" <joanna@not.for.spam> a �crit dans le message de 
news: 44cb81eb@newsgroups.borland.com...
> "Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> a �crit 
> dans
> le message de news: 44cb7da5$1@newsgroups.borland.com...
>
> | Porting to C#, I can create C# events corresponding to Delphi events. 
> But
> | those C# events will of course be unicast only.
>
> Not necessarily :-) .C# delegates are always multicast, but you can assign
> only one handler if you wish.
>
>  public delegate void TestHandler(int value);
>
>  {
>    private void HandleTest(int value)
>    {
>      // handler code
>    }
>
>    private TestHandler test;
>
>    private void CallTest()
>    {
>      test = HandleTest; singlecast
>      test(123);
>      test += HandleTest; // now multicast
>    }
>  }
>
> You can see that both assigning (singlecast) and += (multicast) are both
> available.
>
> Joanna
>
> -- 
> Joanna Carter [TeamB]
> Consultant Software Engineer
>
> 
Re: event versus simple delegate
#240
Author: Joanna Carter [TeamB]
Date: Sat, 29 Jul 2006 20:23
19 lines
1611 bytes
"Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> a �crit dans 
le message de news: 44cba8c5@newsgroups.borland.com...

|I was speaking about C# v1 which has a slightly different syntax.
|
| Can you explain what difference there is (C# V1) declaring an event member
| using the event keyword and declaring a member which is simply a delegate 
?

C# 1.1 uses the longer syntax for multicast use but you can use the shorter 
direct assignment for simple delegation.

AFAICT, using the event keyword restricts use to multicast.

Joanna

-- 
Joanna Carter [TeamB]
Consultant Software Engineer 
Re: event versus simple delegate
#241
Author: Marc Rohloff TeamB
Date: Sat, 29 Jul 2006 23:28
11 lines
1528 bytes
On Sat, 29 Jul 2006 21:23:00 +0100, Joanna Carter [TeamB] wrote:

> AFAICT, using the event keyword restricts use to multicast.

If you write your own setters you can make it unicast. Delphi is the
same by using the 'add' and 'remove' keywords you can get a multicast
event.

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Re: event versus simple delegate
#242
Author: Francois PIETTE [ICS - MidWare]
Date: Sun, 30 Jul 2006 08:23
24 lines
2008 bytes
> |I was speaking about C# v1 which has a slightly different syntax.
> |
> | Can you explain what difference there is (C# V1) declaring an event 
> member
> | using the event keyword and declaring a member which is simply a 
> delegate
> ?
>
> C# 1.1 uses the longer syntax for multicast use but you can use the 
> shorter
> direct assignment for simple delegation.
>
> AFAICT, using the event keyword restricts use to multicast.

Does the event keyword has an impact on the IDE ?
Some of my events (those seen outside of the class set) are intended to be 
used from the IDE. I'm writing a set of non-visual components and would like 
to have it fully integrated within the IDE, any IDE if you see what I mean.

-- 
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
Re: event versus simple delegate
#244
Author: Marc Rohloff TeamB
Date: Mon, 31 Jul 2006 22:03
14 lines
1751 bytes
On Sun, 30 Jul 2006 10:23:12 +0200, Francois PIETTE [ICS - MidWare]
wrote:

> Does the event keyword has an impact on the IDE ?
> Some of my events (those seen outside of the class set) are intended to be 
> used from the IDE. I'm writing a set of non-visual components and would like 
> to have it fully integrated within the IDE, any IDE if you see what I mean.

Events are visible in the property inspector, or did you mean
somewhere else?

-- 
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com
Re: event versus simple delegate
#245
Author: Francois PIETTE [ICS - MidWare]
Date: Tue, 01 Aug 2006 16:33
18 lines
1792 bytes
>> Does the event keyword has an impact on the IDE ?
>> Some of my events (those seen outside of the class set) are intended to 
>> be
>> used from the IDE. I'm writing a set of non-visual components and would 
>> like
>> to have it fully integrated within the IDE, any IDE if you see what I 
>> mean.
>
> Events are visible in the property inspector

For you, the event keyword only affect the object inspector ? Strange. This 
role should be given to attributes. Are you sure ?

-- 
francois.piette@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads