473,404 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Could a delegate point to a constructor?

Hi.
I'm looking for a way to make a delegate point to a constructor.
I'm not too sure i'm explaining it right,so here's a sample code to
demonstrate.

-----
using System.Windows.Forms;
class xyz
{
public delegate Form MyDelegate (string input);
public static void func (MyDelegate x)
{
Form y = x("p");
}
}
class abc : Form
{
public abc (string title) {...}
....
}
-----

Now i would want to make the xyz.func() create a new "abc".
both the "MyDelegate" and the "abc" constructor have the same return value
and the same parameters,so theoretically there should be a way.

Hopefully i'm clear enough for someone...
Thank you
Feb 9 '06 #1
2 1179
No. But, you could create a factory method or class that can create an
instance of the Form for you using something like
Activator.CreateInstance(...). Then have the delegate point to the factory.

"ThePinkPanther" <Th************@discussions.microsoft.com> wrote in message
news:45**********************************@microsof t.com...
Hi.
I'm looking for a way to make a delegate point to a constructor.
I'm not too sure i'm explaining it right,so here's a sample code to
demonstrate.

-----
using System.Windows.Forms;
class xyz
{
public delegate Form MyDelegate (string input);
public static void func (MyDelegate x)
{
Form y = x("p");
}
}
class abc : Form
{
public abc (string title) {...}
...
}
-----

Now i would want to make the xyz.func() create a new "abc".
both the "MyDelegate" and the "abc" constructor have the same return value
and the same parameters,so theoretically there should be a way.

Hopefully i'm clear enough for someone...
Thank you

Feb 9 '06 #2
>Now i would want to make the xyz.func() create a new "abc".

In addition to what the others said, it's worth pointing out that a
constructor doesn't have a return value so
both the "MyDelegate" and the "abc" constructor have the same return value
and the same parameters,so theoretically there should be a way.


is incorrect. A constructor doesn't return a new object, it
initializes a newly allocated one.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Todd Schinell | last post by:
Back in July, Jeffery Tan posted this: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OWOTdf0VDHA.2296%40cpmsftngxa06.phx.gbl In response as to how to get click events from a...
15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
3
by: IMS.Rushikesh | last post by:
Hi All, There is a scenario, in which there is a counter in my base class. There is some initial value of this counter (check below code). Now there is a function "DecreaseCount", which will...
5
by: Edward Diener | last post by:
The first type to a delegate constructor is obvious. It is a System::Object * . What is the MC++ type of the second argument to the delegate constructor ? In C++ it would be a member function...
9
by: Terry Olsen | last post by:
I'm running an asynchronous Socket. In the ReceiveCallback method, I need to append what is received to a textbox on the main form. I have this code: Private Sub ToChatWindow(ByVal msg As...
2
by: zamir.khan | last post by:
Hello all, New to the groups, sorry if this the wrong forum/etiquette. I am coding a c++ application that requires the use of a timer-triggered event handler. I decided to use the timer provided...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
6
by: RobKinney1 | last post by:
Hello, This may be an easy question, but I cannot stumle upon the correct way of doing this. I have a function in a base class. I then pass it to a class as a delegate so I don't have to...
6
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.