Delegates(?): Add them at runtime from the outside.

Heiko

Well-known member
Joined
Feb 10, 2003
Messages
430
Location
Holstein, Germany.
Huh. I hope I can make the problem quite clear.


I have defined an extended Textbox class. This class has a builtin public validation routine (know if it is mandatory, for example).

On my forms I have a lot of these extended textboxes.

Now what I want to do is the following:
In some cases there are some additional validations to be made.
Is there a way to pass a
Code:
Function CustomValidatior (byval Origin as Control)  as string
to a single instance of an extendedTextbox?


Would I have to declare a delegate?

Then, in the already coded "Validate" Function I could perhaps simply check if the delegate is not nothing and then execute it.

How can I pass from the "outside" the delegate to handle the custom validation ?

In the form would like to have something like:

Code:
Dim ctlPhone as new ctlExtendedTextbox ()

ctlPhone.CustomValidator = AddressOf Utility.ValidatePhone()


and in the extended textbox:
Code:
Public Sub Validate ()
 
Do stuff

Try
  returnString = mCustomValidator (me)
  Well how do I figure out if there actually *is* a customValidator?
End Try

 End Sub


Does this make sense?
(Sorry if I sound confused. I actually am. Thats why I am leaving the office right now ;) )
 
Delegates can be likened to creating a method in a class whose sole purpose in
life is to call another method. Basically, the name of the procedure is passed to
the delegate, and it executes the procedure on behalf of the calling procedure.
Delegates are called using the Invoke method. A delegate is useful for specifying
the name of a routine to run at runtime.
Delegates are similar to function pointers in C++. Delegates perform the task
of calling methods of objects on your behalf. Delegates are classes that hold references
to other classes:
 You can use a delegate to specify an event handler method to invoke
when an event occurs.This is one of the most common uses for delegates
in Visual Basic .NET. Delegates have signatures and hold references
to methods that match their signatures.
 Delegates act as intermediaries when you are programming events to
link the callers to the object called.
A declaration for a delegate is shown here:
Delegate Function IsZero(ByVal x As Integer) as boolean
The following example form and class demonstrate the use of delegates:The
following code is used to build the form; the form constructor code has been
removed to save space.The form has two buttons on it: One for a command we
 
Back
Top