Thanks, but that did not work. CreateDelegate throws an exception when I try
to get the type of my custom type, using Type.GetType.
Here is what I want to do:
Private OneStep As StepSub
Delegate Sub StepSub()
Private Steps(ALL_STEPS) As StepSub
Eventually, I will use the Combine method on Steps:
OneStep = OneStep.Combine(Steps)
And then call all the subs contained in the original Steps array:
OneStep.DynamicInvoke(Nothing)
Before I do that however, I want to build the original super list (Steps)
based on a database table which contains the method names and their
corresponding sequence (index into the Steps array). At runtime, I will have
a structure to tell me which of the steps to leave in the Steps array and
which ones to remove (by setting the corresponding Steps entry to Nothing).
Everything works just fine except that I want to be able to build the Steps
array at runtime with no prior knowledge of the methods. Which means I want
to use a string representation of the method name and turn it into a method
address compatible with the delegate type of my methods to pass to the
AddressOf operator (or in some way resolve to a compatible value).
So instead of:
Steps(0) = New StepSub(AddressOf FirstMethod)
Steps(1) = New StepSub(AddressOf SecondMethod)
Steps(2) = New StepSub(AddressOf ThirdMethod)
....
Steps(n)= New StepSub(AddressOf LasMethod)
I want to write:
Dim ds as DataSet = GetMyListOfMethodsAndSequences
Dim dr as DataRow
For Each dr in ds.Tables(0).Rows
Steps(dr.Item("MethodStepIndex")) = new StepSub(AddressOf
SomeWayToGetTheAddressOfTheMethodWhoseNameIsInThis DataRow)
Next
Hopefully, this mess makes sense to you.
Thanks again
"Mattias Sjögren" wrote:
I want to look up method names in a database which will be present in the
executing object and use the names to find the method address to pass to the
addressof operator at runtime.
So in other words you want to create a delegate dynamically.
Is that possible? If so, what reflection classes enable me to do that?
System.Delegate.CreateDelegate()
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.