473,788 Members | 2,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1194
No. But, you could create a factory method or class that can create an
instance of the Form for you using something like
Activator.Creat eInstance(...). Then have the delegate point to the factory.

"ThePinkPanther " <Th************ @discussions.mi crosoft.com> wrote in message
news:45******** *************** ***********@mic rosoft.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
25289
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 user control to invoke a method in the parent form. This code doesn't seem to work for me, I've tried it a number of times with very simple test cases (A user control with a single button and a parent form with a single text box) and it always...
15
5753
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 remote publisher, so I used delegate that the user will be able to set on it his own function for that purpuse. The trouble is that this delegate must not be static because there may be many subscribers, and each subscriber may have different...
3
1476
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 decrease count. Now I want some functionality like when this counter become zero(0) a delegate will be fired of derived class. This is working fine. Now, on my UI side this instance of Tester and Developer are a node of a TreeView. There are lots...
5
3631
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 pointer when the first object is not 0, but I can't find its equivalent type in .NET. I would like to save an object of that type and use that object to construct a delegate ? As an example: public __delegate void ADelegate(); __gc public class X
9
1970
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 String) txtChat.AppendText(msg) End Sub I've never used a delegate or invoke before and I'm rather confused on the topic. Hope someone can help.
2
7317
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 in System::Timers::Timer. My understanding of the next part is not very good, as my code may reveal, but as I understand it, my application is "unmanaged C++", whereas the timer extension from the system DLL is managed. Therefore I needed to use...
1
1824
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 code, as there's simply too much, but here's the general gist: I have a connection object which connects to a custom back-end server of one type or another. Clients of this connection object send requests via a method (e.g....
6
1713
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 repeat the code within that class. But then that class, calls another class and needs that same function back in the parent. How do I keep passing that delegate up the chain? I am getting errors that says: Cannot convert type...
6
6871
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 ThreadStart(open)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10112
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7518
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.