473,395 Members | 1,496 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,395 software developers and data experts.

Question of Style for Delegate creation

Both of the Dim statements work in the following. Is there a preference
and why? (Of course, you would not use them both but each, by itself,
works and enables the Invoke to function properly)

Dim newDelegate As New UIDelegate(AddressOf StatusAdd)
Dim newDelegate As UIDelegate = AddressOf StatusAdd
lblStatus.Invoke(newDelegate)

And a follow-on topic:

Actually, this brings up the whole subject of "New". It is something
new to me and I would like to know if there is something written up
explaining about why one uses "New", when it should be used and any
other implications of using it. Coming from VB6, this is foreign to me.

If there is something already written up, then that's great but I don't
know how to find something this esoteric and general. The functional
helps tell "what" but rarely "why".

Thanks for any pointers. I have been wondering about "New" for a while
and the example, above, really pointedly makes me want to know about
this syntax element.

Mike

Jun 27 '08 #1
2 834
On Apr 14, 6:00 am, Just_a_...@home.net wrote:
Both of the Dim statements work in the following. Is there a preference
and why? (Of course, you would not use them both but each, by itself,
works and enables the Invoke to function properly)

Dim newDelegate As New UIDelegate(AddressOf StatusAdd)
Dim newDelegate As UIDelegate = AddressOf StatusAdd
lblStatus.Invoke(newDelegate)

And a follow-on topic:

Actually, this brings up the whole subject of "New". It is something
new to me and I would like to know if there is something written up
explaining about why one uses "New", when it should be used and any
other implications of using it. Coming from VB6, this is foreign to me.

If there is something already written up, then that's great but I don't
know how to find something this esoteric and general. The functional
helps tell "what" but rarely "why".

Thanks for any pointers. I have been wondering about "New" for a while
and the example, above, really pointedly makes me want to know about
this syntax element.

Mike
From what I can tell with Reflector, both do exactly the same thing.
The only difference I can see is where the constructor is called. In
the first sample, you call New in the standard way, but in the second
it is called implicitly by the AddressOf keyword.

For your other question, 'New' tells the compiler to create a new
instance of that type and calls its constructor (Public Sub New(...)).
The constructor performs startup tasks such as variable initialization
or property settings that are required for the type to function. For
example, in Window's forms, all the child controls are created and
added to the forms during the form's constructor. Things don't get too
confusing until you see the types such as String that don't require
you to use 'New' to create an instance, all it needs is to have it's
value set as the constructor will be called implicitly. That probably
wasn't the best explanation, so let me know where I can clarify.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #2

<Ju********@home.netwrote in message
news:gg********************************@4ax.com...
Both of the Dim statements work in the following. Is there a preference
and why? (Of course, you would not use them both but each, by itself,
works and enables the Invoke to function properly)

Dim newDelegate As New UIDelegate(AddressOf StatusAdd)
Dim newDelegate As UIDelegate = AddressOf StatusAdd
lblStatus.Invoke(newDelegate)

And a follow-on topic:

Actually, this brings up the whole subject of "New". It is something
new to me and I would like to know if there is something written up
explaining about why one uses "New", when it should be used and any
other implications of using it. Coming from VB6, this is foreign to me.

If there is something already written up, then that's great but I don't
know how to find something this esoteric and general. The functional
helps tell "what" but rarely "why".

Thanks for any pointers. I have been wondering about "New" for a while
and the example, above, really pointedly makes me want to know about
this syntax element.

Mike
Coming from VB6 I understand why the first style would not be used. VB6
would recreate objects that used this style on its own causing reference
problems. It was widely known not to use that style.

LS

Jun 27 '08 #3

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

Similar topics

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...
1
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer...
16
by: bigtexan | last post by:
I would like to do the following and cannot figure it out. public class A<T> { public delegate T GetValueDelegate(A<T> var); public GetValueDelegate GetValue = new GetValueDelegate(B.GetValue);...
2
by: Wavemaker | last post by:
The canonical way of declaring delegates for events is to include a parameter representing the sender as well as an EventArgs derived class (or EventArgs itself) as the second parameter...
3
by: CJ Taylor | last post by:
Hey, I'm working with Dynamic Assemblies right now for a framework I'm building and what I'm trying to understand is how EventHandlerList works. I've read some documentaiton on it, but nothing...
3
by: astro | last post by:
I want to build a Filter form that displays a list of values in a listbox which the user selects from. The values in this listbox are passed to the filterform. When the user closes this filter...
3
by: Jon | last post by:
I am a little problem deciding when to use delegates and when not to. Is the following a good example? I have an order class and a messenger class (this does things like send emails, pages,...
2
by: John B | last post by:
I have a situation where I need to control the creation of a class. I need to be able to create it externally but only by classes that I define. To accomplish this I thought of the following...
7
by: RvGrah | last post by:
I'm using the Activated event of my form to run a database query in a backroundWorker, and want to dismiss the call after the first time the form is activated. Based on some excellent advice in an...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.