Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

How to invoke methode name stored in string

瀏覽次數:0 次
跳到第一則未讀訊息

mo...@tek.com

未讀,
2008年2月28日 清晨7:09:392008/2/28
收件者:
Hi all,

I have tried to invoke some method declared in Vb.NET Module. But
Method name is stored in string .


Examples:


Module 1
Sub Method1()
MessageBox.Show("Hi")
End Sub
End Module1


Imports System.Reflection
Imports System.Web
Imports Microsoft.VisualBasic.CallType


Public Class Form1
Public Delegate Sub MakeDelegate()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim SubName As String = "method"


Dim objDelegate As MakeDelegate
objDelegate = AddressOf method
objDelegate.Invoke()
End Sub
End Class
In the above sample, I want to use SubName" instead of "method".
Is there any way to use string instead of method name directly?


Is there any way to access Module Name using Reflection? I want to
call the methodes declared in Module1 through string from Form1
class.


Can anybody help me to reolve this issue?
I have tried CallByName Vb function. But everthing looks for object
reference or method name.


Thanks,
mohan


0 則新訊息