In C# I know that you can use delegates to assing
multiple addresses of sub and functions to a delegate and
have it fire multiple procedures...
How do I do this in VB? I only know of assigning a
single method to a delegate in VB.NET. I want to use it
as in C#... to fire multiple events.
Thanks in advance! 15 6631
Hello,
"Iced Crow" <ch********@aol .com> schrieb: In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures...
How do I do this in VB? I only know of assigning a single method to a delegate in VB.NET. I want to use it as in C#... to fire multiple events.
Are you sure you read this chapter of the documentation?
Events and Delegates (Visual Basic Language Concepts) http://msdn.microsoft.com/library/en...nheritance.asp
--
Herfried K. Wagner
MVP · VB Classic, VB.NET http://www.mvps.org/dotnet
Those examples only show how to add a single method to a delegate...
what method of a delegate can I call to add multiple methods? Do I have
to create an array of delegates or a collection of delegates? The only
thing close to what I need is "CreateDelegate " but that is asking for a
type...
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
I glanced through it but could not find an instance of
applying multiple methods to a single delegate, only how
to add a single method to a delegate which i already know
how to do...
Iced Crow,
Are you talking actual delegates or are you talking events? As Herfried
pointed you at how to use AddHandler to add multiple subs to an event so
they all get called.
If you are talking actual delegates:
Have you tried the Delegate.Combin e method that concatenates the invocations
lists of two delegates together?
Hope this helps
Jay
"Iced Crow" <ch********@aol .com> wrote in message
news:79******** *************** *****@phx.gbl.. . In C# I know that you can use delegates to assing multiple addresses of sub and functions to a delegate and have it fire multiple procedures...
How do I do this in VB? I only know of assigning a single method to a delegate in VB.NET. I want to use it as in C#... to fire multiple events.
Thanks in advance!
Greetings Jay,
No I am not talking about events, I understand how to add
handlers.
I am talking delegates. A delegate object being assigned
the address of a procedure and then having it's invoke
method called to fire that procedure.
In C# I know of how to take a single delegate and assign
to it calls from multiple procedures, so that I only have
to fire off a single INVOKE method from that single
delegate to fire off the multiple methods.
With VB.NET I only know of how to assign a single method
address to a single delegate.
I understand the combine function, but I'm only working
with one delegate here so there's nothing to combine. Do
I have to create multiple delegate objects that reference
methods and then combine them all? THat seems horribly
ineffecient...
I don't know how familiar you are with the MOCs but in
the 2124 C# course they have an example with a nuclear
power plant and one invoke call to a delegate is able to
fire off multiple calls to pump procedures.
This is what I want to do with Visual Basic.NET. It has
nothing to do with events.
Thanks!
IcedCrow. I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient...
How are you combining them in C#?
Is it the += syntax the same as for events?
(I don't do a lot of C#, but will look it up).
Thanks
Jay
"IcedCrow" <ch********@aol .com> wrote in message
news:00******** *************** *****@phx.gbl.. . Greetings Jay,
No I am not talking about events, I understand how to add handlers.
I am talking delegates. A delegate object being assigned the address of a procedure and then having it's invoke method called to fire that procedure.
In C# I know of how to take a single delegate and assign to it calls from multiple procedures, so that I only have to fire off a single INVOKE method from that single delegate to fire off the multiple methods.
With VB.NET I only know of how to assign a single method address to a single delegate.
I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient...
I don't know how familiar you are with the MOCs but in the 2124 C# course they have an example with a nuclear power plant and one invoke call to a delegate is able to fire off multiple calls to pump procedures.
This is what I want to do with Visual Basic.NET. It has nothing to do with events.
Thanks!
Howdy Iced,
The Help doc that Herfried gave says:
Event delegates are multicast, which means that they can hold references
to more than one event handling method. For details, see Delegate
The AddHandler statement that Jay mentions:
See VB Language/VB Language Tour/OOP in VB/Events and Delegates
The AddHandler statement is similar to the Handles clause in that both allow
you to specify an event handler that will handle an event. However, AddHandler
along with RemoveHandler provide greater flexibility than the Handles clause,
allowing you to dynamically add, remove, and change the error handler
associated with an event. And unlike Handles, AddHandler allows you to
associate multiple event handlers with a single event.
AddHandler takes two arguments: the name of an event from an event sender such
as a control, and an expression that evaluates to a delegate. You do not need
to explicitly specify the delegate class when using AddHandler, since the
AddressOf statement always returns a reference to the delegate.
The following example associates an event handler with an event raised by an
object:
AddHandler MyObject.Event1 , AddressOf Me.MyEventHandl er
RemoveHandler, which disconnects an event from an event handler, uses the same
syntax as AddHandler. For example:
RemoveHandler MyObject.Event1 , AddressOf Me.MyEventHandl er
Regards,
Fergus
MVP [Windows Start button, Shutdown dialogue]
IcedCrow, I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient...
You do realize that the "+=" operator in C# when used with delegate types is
shorthand for the Delegate.Combin e function?
While the "-=" operator when used with delegate types is shorthand for
Delegate.Remove function?
You can use ildasm.exe to verify the above statement.
So as I stated, have you tried the Delegate.Combin e function?
Further you do realize that each time you use the AddressOf operator in
VB.NET that you are given a new Delegate?
Hope this helps
Jay
"IcedCrow" <ch********@aol .com> wrote in message
news:00******** *************** *****@phx.gbl.. . Greetings Jay,
No I am not talking about events, I understand how to add handlers.
I am talking delegates. A delegate object being assigned the address of a procedure and then having it's invoke method called to fire that procedure.
In C# I know of how to take a single delegate and assign to it calls from multiple procedures, so that I only have to fire off a single INVOKE method from that single delegate to fire off the multiple methods.
With VB.NET I only know of how to assign a single method address to a single delegate.
I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient...
I don't know how familiar you are with the MOCs but in the 2124 C# course they have an example with a nuclear power plant and one invoke call to a delegate is able to fire off multiple calls to pump procedures.
This is what I want to do with Visual Basic.NET. It has nothing to do with events.
Thanks!
yes it is +=
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl... IcedCrow. I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient... How are you combining them in C#?
Is it the += syntax the same as for events?
(I don't do a lot of C#, but will look it up).
Thanks Jay
"IcedCrow" <ch********@aol .com> wrote in message news:00******** *************** *****@phx.gbl.. . Greetings Jay,
No I am not talking about events, I understand how to add handlers.
I am talking delegates. A delegate object being assigned the address of a procedure and then having it's invoke method called to fire that procedure.
In C# I know of how to take a single delegate and assign to it calls from multiple procedures, so that I only have to fire off a single INVOKE method from that single delegate to fire off the multiple methods.
With VB.NET I only know of how to assign a single method address to a single delegate.
I understand the combine function, but I'm only working with one delegate here so there's nothing to combine. Do I have to create multiple delegate objects that reference methods and then combine them all? THat seems horribly ineffecient...
I don't know how familiar you are with the MOCs but in the 2124 C# course they have an example with a nuclear power plant and one invoke call to a delegate is able to fire off multiple calls to pump procedures.
This is what I want to do with Visual Basic.NET. It has nothing to do with events.
Thanks!
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michi Henning |
last post by:
Below is a bit of code that creates a delegate.
The delegate invokes a member function of a struct.
The code compiles, but has surprising behavior:
using System;
namespace ConsoleApplication1
{
public struct SimpleStruct
{
|
by: Robert Batt |
last post by:
Hello,
I'm trying to modularize the code in my forms by
putting some procedures and delegates in a seperate class.
However I try to put a delegate with the following header
in a class.
Public Sub DecimalToCurrencyString(ByVal sender As
Object, ByVal cevent As ConvertEventArgs)
However I get a syntax error on ConvertEventArgs, saying
|
by: Jarod_24 |
last post by:
What is the point with Delegates in VB.Net
What can these things do that we can not allready do with the use of Interfaces, Events and Event handlers and so on...
I'd like a discussion on this, and some practical examples where Delegates would be better/worse to use...
|
by: heddy |
last post by:
Using Jesse Liberty's excellent book on C#, I am looking at chapter 12
- Delegates. Now, I was under the impression that a delegate is
essentially a pointer to a member function. However, when I look at
Jesse's code and explanation of it, I just don't get it.
His code looks like this:
#region Using directives
using System;
|
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 I throw an exception I want to call one
method and if I dont, I am just logging some info to eventlog, I will call
the other. Now i'm wondering would it make sense to use delegates, one for
each method to call methods in my window service? How...
| |
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 uses the "WithEvents" and events.
There is another example on page 124 that shows how to use delegates to sort
an array.
I don't understand the difference between events and delegates. Are they
redundant features? How do I decide which to use?
...
|
by: tshad |
last post by:
I have a set up javascript functions that pass function pointers and I am
trying to figure out how to do the same thing in C# using delegates.
// We define some simple functions here
function add(x,y) {return x + y;}
function subtract(x,y) {return x - 1; }
function multiply(x,y) {return x * 1; }
|
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 to store multicast delegates in a hash table,
and then fire the delegates one of two ways (after registering/
creating the delegates, etc).
|
by: BobLewiston |
last post by:
The concept of delegates (references to methods) per se is new to me (although I used function pointers in C years ago), and although the literature acknowledges that there are significant differences between delegates and the use of pointers to objects, I'm nonetheless a little confused by how similar the syntax used for references to methods is to that used for references to objects.
Recently at a few different forums I posted a brief...
|
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,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |