How to Declare Address Of for a Parameter? 
Author Message
 How to Declare Address Of for a Parameter?

I'm creating a class to help me set up datagrids.

One thing I'd like to be able to do is something like:

MyGridClass.AddColumn "Title", Address Of MyEventHandler

And inside the class, it would do something like:

Public Sub AddColumn(byval sTitle as string, byref lAddress as <what?>)
Dim Col As New DataGridTextBoxColumn()

Col.HeaderText = sTitle

mdgStyle.GridColumnStyles.Add(Col)

AddHandler Col.TextBox.Enter, lAddress

My question is how to declare the second parameter?  I've tried everything

I can think of, but nothing seems to work. If I'm going to pass in Address
Of,

what would I declare it as?

Thanks,  ---Selden McCabe



Sun, 30 Jan 2005 01:51:31 GMT  
 How to Declare Address Of for a Parameter?
You must first create a Delegate then name second parameter as Delegate
Name.

Example...

'// declaration
Delegate Sub Test()

'// Your sub...
Private Sub MySub(ByVal value As Int32, ByVal callBack As Test)
  AddHandler ...., callBack            '// please note no AddressOf
End Sub

'// Example o fuse...
MySub(10, AddressOf MySub)

// Routine you want to use as event handler
Private Sub MySub()
End Sub

HTH

--
Corrado Cavalli
UGIdotNET - http://www.ugidotnet.org



Sun, 30 Jan 2005 03:04:39 GMT  
 How to Declare Address Of for a Parameter?
Hi Selden,

The type of the second parameter should be a delegate with the same shape as
the method whose address is to be passed. For example:

Delegate Sub MyDelegate(ByVal X As Integer)

Sub MyEventHandler(ByVal X As Integer)

    AddColumn("asdf", AddressOf MyEventHandler)

End Sub

Sub AddColumn(ByVal Title As String, ByVal Address As MyDelegate)

End Sub

Also, if you are passing in an AddressOf expression, then assigning through
the parameter would have no effect and so it might as well be declared ByVal
instead of ByRef.

John Hamby, VB.Net
--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I'm creating a class to help me set up datagrids.

> One thing I'd like to be able to do is something like:

> MyGridClass.AddColumn "Title", Address Of MyEventHandler

> And inside the class, it would do something like:

> Public Sub AddColumn(byval sTitle as string, byref lAddress as <what?>)
> Dim Col As New DataGridTextBoxColumn()

> Col.HeaderText = sTitle

> mdgStyle.GridColumnStyles.Add(Col)

> AddHandler Col.TextBox.Enter, lAddress

> My question is how to declare the second parameter?  I've tried everything

> I can think of, but nothing seems to work. If I'm going to pass in Address
> Of,

> what would I declare it as?

> Thanks,  ---Selden McCabe



Sun, 30 Jan 2005 03:24:20 GMT  
 How to Declare Address Of for a Parameter?
What you're looking for is a "delegate"

To take from your example, you'd use syntax like:

MyGridClass.AddColumn "Title", new EventHandler(AddressOf
MyEventHandler)

Public Sub AddColumn(byval sTitle as string, byVal lAddress as
System.Delegate)
  ....
  AddHandler Col.TextBox.Enter, lAddress
End Sub

Note you pass the delegate as byVal not byRef. A Delegate is basically
a function pointer and you want to pass the pointer not a reference to
the pointer.

-Andy
Andy Johns, MCSD
Senior Consultant-Architect
Magenic Technologies

Quote:

> I'm creating a class to help me set up datagrids.

> One thing I'd like to be able to do is something like:

> MyGridClass.AddColumn "Title", Address Of MyEventHandler

> And inside the class, it would do something like:

> Public Sub AddColumn(byval sTitle as string, byref lAddress as <what?>)
> Dim Col As New DataGridTextBoxColumn()

> Col.HeaderText = sTitle

> mdgStyle.GridColumnStyles.Add(Col)

> AddHandler Col.TextBox.Enter, lAddress

> My question is how to declare the second parameter?  I've tried everything

> I can think of, but nothing seems to work. If I'm going to pass in Address
> Of,

> what would I declare it as?

> Thanks,  ---Selden McCabe



Sun, 30 Jan 2005 06:59:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. declares a variable that resides at a specific memory address

2. using a parameter query in a declared recordset

3. how to declare a function with optional parameters

4. Declare for DLL function with void** parameter??

5. HELP ! declare parameters inside an .EXE

6. Declaring a Sub with optional Parameters

7. Declare a pointer to a funcion as parameter.

8. VBScript Control - Declaring Functions with variable parameters

9. How to declare an [out] parameter?

10. How to declare char** as a parameter

11. Declare for DLL function with void** parameter??

12. Proper declare for **argv parameter?

 

 
Powered by phpBB® Forum Software