PC Review


Reply
Thread Tools Rate Thread

Control delegate in an Interface

 
 
pigeonrandle
Guest
Posts: n/a
 
      3rd Aug 2006
Hi,
I have a couple of forms on my client application that use an
asyncronous tcp client to send and recieve data from a server
application.
On each of these forms, i have a Listbox which i would like to add
status information to, like,

"Connected to server"
"Details Sent"
"Details Received"

Is it possible to have my forms implement an interface that includes a
generic delegate such as

"void AddStatusString(String s)"

where i pass the message s from the tcp client to my form's listbox?

This is sending me a bit screwy because i cant get my head around
exactly what needs to be in the interface. I know it can't be "void
AddStatusString(String s)" because this is the function in my form that
is Invoked BY a delegate, if you get my meaning.

Many thanks in advance,
James Randle.

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd Aug 2006
pigeonrandle <(E-Mail Removed)> wrote:
> Hi,
> I have a couple of forms on my client application that use an
> asyncronous tcp client to send and recieve data from a server
> application.
> On each of these forms, i have a Listbox which i would like to add
> status information to, like,
>
> "Connected to server"
> "Details Sent"
> "Details Received"
>
> Is it possible to have my forms implement an interface that includes a
> generic delegate such as
>
> "void AddStatusString(String s)"
>
> where i pass the message s from the tcp client to my form's listbox?
>
> This is sending me a bit screwy because i cant get my head around
> exactly what needs to be in the interface. I know it can't be "void
> AddStatusString(String s)" because this is the function in my form that
> is Invoked BY a delegate, if you get my meaning.


I'm not sure I see why a delegate is needed. If you implement the
interface, you just write a method AddStatusString which is implemented
by adding the given string to the listbox - why do you need delegates?

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Thomas T. Veldhouse
Guest
Posts: n/a
 
      3rd Aug 2006
pigeonrandle <(E-Mail Removed)> wrote:
> Hi,
> I have a couple of forms on my client application that use an
> asyncronous tcp client to send and recieve data from a server
> application.
> On each of these forms, i have a Listbox which i would like to add
> status information to, like,
>
> "Connected to server"
> "Details Sent"
> "Details Received"
>
> Is it possible to have my forms implement an interface that includes a
> generic delegate such as
>
> "void AddStatusString(String s)"
>


No interface needed.


public delegate void AddStatusStringHandler(String s);

public class TcpServer
{
public event AddStatusStringHandler AddStatusStringEvent;
}

public class ClientForm : Form
{
public ClientForm(TcpServer tcpServer)
{
// form initialization code skipped

tcpServer += new AddStatusStringHandler(AddStatusString);
}

private AddStatusString(String s)
{
// add string to list box
}
}
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1


 
Reply With Quote
 
Thomas T. Veldhouse
Guest
Posts: n/a
 
      3rd Aug 2006
Thomas T. Veldhouse <(E-Mail Removed)> wrote:
>
>
> public delegate void AddStatusStringHandler(String s);
>
> public class TcpServer
> {
> public event AddStatusStringHandler AddStatusStringEvent;
> }
>


Granted ... the name of the delegate and event are horrendous in my example
:-)

--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1 day view calendar of delegate won't print - message interface e =?Utf-8?B?U2hpcmxleSBBLiBTbWl0aA==?= Microsoft Outlook Calendar 0 3rd Oct 2006 07:30 PM
Cannot put delegate in interface - why not? atwomey@yahoo.com Microsoft C# .NET 5 29th Jun 2006 01:55 PM
Accessing a C# delegate used in a C# interface.... Steven Cummings Microsoft VB .NET 4 6th Jun 2005 10:05 PM
Help: Declare Delegate type in an Interface ???? =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= Microsoft Dot NET 1 4th Nov 2004 05:47 PM
Interface VS Delegate Phill Microsoft C# .NET 3 25th Aug 2004 08:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 AM.