Hi,
I'm trying to convert a VB.NET sample app I found to C# but the delegates
part has caught me out, I have a form which has the following delegates
defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently has
private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor which is
declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do the
following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee);
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method
'EmployeeExample.Form1.OnAddNewEmployee(EmployeeEx ample.Employee)'
referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I does
this in C#?
Many thanks, TIA
Colin B 3 1124
"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:um**************@TK2MSFTNGP09.phx.gbl... Hi,
I'm trying to convert a VB.NET sample app I found to C# but the delegates part has caught me out, I have a form which has the following delegates defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently has
private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor which
is declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do the following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee);
change the above line to:
frmProgrammer frmProg = new frmProgrammer(new
AddNewEmployee(OnAddNewEmployee));
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method 'EmployeeExample.Form1.OnAddNewEmployee(EmployeeEx ample.Employee)' referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I does this in C#?
Many thanks, TIA
Colin B
Hi Daniel,
That of course works, many thanks...
Colin B
"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl... "Colin Basterfield" <co**************@hotmail.com> wrote in message news:um**************@TK2MSFTNGP09.phx.gbl... Hi,
I'm trying to convert a VB.NET sample app I found to C# but the
delegates part has caught me out, I have a form which has the following delegates defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently has
private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor
which is declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do
the following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee); change the above line to: frmProgrammer frmProg = new frmProgrammer(new AddNewEmployee(OnAddNewEmployee));
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method 'EmployeeExample.Form1.OnAddNewEmployee(EmployeeEx ample.Employee)' referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I
does this in C#?
Many thanks, TIA
Colin B
"Colin Basterfield" <co**************@hotmail.com> wrote in message
news:OM**************@TK2MSFTNGP11.phx.gbl... Hi Daniel,
That of course works, many thanks...
Its a tricky one...I know it confused me at first. If memory serves, C# 2
will provide automatic resolution of delegate types in situations like this,
easing things on the developer, however I am not certain. Colin B
"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message news:eE**************@TK2MSFTNGP12.phx.gbl... "Colin Basterfield" <co**************@hotmail.com> wrote in message news:um**************@TK2MSFTNGP09.phx.gbl... Hi,
I'm trying to convert a VB.NET sample app I found to C# but the delegates part has caught me out, I have a form which has the following
delegates defined:
public delegate void AddNewEmployee(Employee employee);
There is a method defined that uses this
private void OnAddNewEmployee(Employee employee)
{
lbEmployees.Items.Add(employee);
}
This method can to be passed into a number of forms and consequently
has private AddNewEmployee addNewEmp;
declared within the form class. There is an overloaded constructor which is declared as:
public frmProgrammer(AddNewEmployee dele) : base()
{
InitializeComponent();
addNewEmp = dele;
}
Now the form that calls this does the following, or rather needs to do the following:
private void btnAddProgrammer_Click(object sender, System.EventArgs e)
{
frmProgrammer frmProg = new frmProgrammer(OnAddNewEmployee); change the above line to: frmProgrammer frmProg = new frmProgrammer(new AddNewEmployee(OnAddNewEmployee));
frmProg.ShowDialog();
}
Unfortunately the compiler does not like this saying
C:\VSNet Dev\ClientWinApp\frmMain.cs(251): Method 'EmployeeExample.Form1.OnAddNewEmployee(EmployeeEx ample.Employee)' referenced without parentheses
The VB.NET sample uses AddressOf, so can someone please tell me how I does this in C#?
Many thanks, TIA
Colin B
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jeffrey T. Smith |
last post by:
Back when the new J2SE1.5 features were announced, there was a
JavaLive community chat
(http://java.sun.com/developer/community/chat/JavaLive/2003/jl0729.html)
in which Neal Gafter explains the...
|
by: Sam |
last post by:
I’m just starting to learn delegates. I’m at the very beginning. If I understand correctly, delegates are for when you want to pass a function as a parameter. For example the client provides a...
|
by: LP |
last post by:
Hello!
I am still transitioning from VB.NET to C#. I undertand the basic concepts
of Delegates, more so of Events and somewhat understand AsyncCallback
methods. But I need some clarification on...
|
by: AMDRIT |
last post by:
I am trying to understand Delegates and where/when to use them.
I can see one potential use of a delegate (on form closing, set the cancel
property in the event arguments.)
Does anyone have a...
|
by: =?Utf-8?B?Sko=?= |
last post by:
I have a logger component that logs to multiple sources, ie textfile,
eventlog etc.
and I have two methods that depending on where I call up my logger comp. one
of them will be called. For ex. if...
|
by: bharathreddy |
last post by:
Delegates
Here in this article I will explain about delegates in brief. Some important points about delegates. This article is meant to only those who already know delegates, it will be a quick...
|
by: =?Utf-8?B?T2xkQ2FEb2c=?= |
last post by:
My question is regarding the use of delegates in C#. I see how .Net uses
delegates to wire event handlers to events. It’s an object created by a
single line of code by the system and that makes...
|
by: Siegfried Heintze |
last post by:
I'm studying the book "Microsoft Visual Basic.NET Language Reference" and I
would like some clarify the difference between events and delegates. On page
156 I see a WinForms example of timer that...
|
by: raylopez99 |
last post by:
They usually don't teach you in most textbooks I've seen that
delegates can be used to call class methods from classes that are
'unaware' of the delegate, so long as the class has the same...
|
by: raylopez99 |
last post by:
Hello all—
I’m trying to get the below to work and cannot get the format right.
It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx
What it is: I’m trying...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |