Armin Zingler said:
Can't reproduce the problem:
Structure mystruct
Public x As Integer
End Structure
'....
Dim tt As mystruct
Dim al As New ArrayList
al.Add(New mystruct)
al.Add(New mystruct)
al.Add(New mystruct)
al.Add(New mystruct)
tt = CType(al(3), mystruct) 'or Directcast instead of CType
--
Armin
How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Okay, in my DLL, I have this:
Friend Class CommandList
Public Structure Simenz
Dim FunctionName As String
Dim NamespaceClass As String
Dim ParentMenu As String
Dim Discription As String
Dim MenuIndex As Integer
Dim Library As String
Sub New(ByVal Function_Name As String, _
ByVal Namespace_Class As String, _
ByVal Parent_Menu As String, _
ByVal Disc As String, _
ByVal Menu_Index As Integer, _
ByVal oLib As String)
FunctionName = Function_Name
NamespaceClass = Namespace_Class
ParentMenu = Parent_Menu
Discription = Disc
MenuIndex = Menu_Index
Library = oLib
End Sub
End Structure
Public ContainedFunction As ArrayList = New ArrayList()
Public Function List() As ArrayList
ContainedFunction.Add(New Simenz("TrackHeader",
"Forms.Tracking", "Processes", "Tracking Header Form", 0, "Mallorca.dll"))
ContainedFunction.Add(New Simenz("DEHeader", "Forms.DEHeader",
"Processes", "Data Entry Batch Header", 1, "Mallorca.dll"))
ContainedFunction.Add(New Simenz("Datez", "Math.Datez", Nothing,
"Date incriment command", 0, "Mallorca.dll"))
ContainedFunction.Add(New Simenz("LuhnMod", "Math.LuhnMod",
Nothing, "LuhnMod10 CheckDigit System", 0, "Mallorca.dll"))
ContainedFunction.Add(New Simenz("Numbahs", "Math.Numbahs",
Nothing, "Batch increment command", 0, "Mallorca.dll"))
Return ContainedFunction
End Function
End Class
And in my Application I have this:
Dim MyObj As Object
dim Libraries as String() = Directory.GetFiles(Application.StartupPath,
"*.dll")
dim Libb as String
For Each Libb in Libraries
MyObj = ClassByName(Libb,"CommandList")
If Not MyObj Is Nothing Then
Dim Cmdz as ArrayList = MyObj.List
Dim I as Integer
Dim Cmd as Simenz
For I = 0 To Cmdz.Count - 1
Cmd = DirectCast(Cmdz(I), Simenz) '***
Next
End If
Next
The 3 Astrisks is as far as I get, I get "Specified Cast is not valid."
exception. The DLL is a non-referenced Assembly that I'm doing Late-Binding
with using the following function:
Public Function ClassByName(ByVal strAssemblyFileName As String, ByVal
strClassName As String) As Object
Dim objAssembly As [Assembly] =
[Assembly].LoadFrom(strAssemblyFileName)
Dim objTemp As Object = objAssembly.CreateInstance( _
strClassName, _
False, _
BindingFlags.CreateInstance, _
Nothing, _
Nothing, _
Nothing, _
Nothing)
If objTemp Is Nothing Then
Throw New Exception("Plugin " & strAssemblyFileName & " could
not be loaded")
Else
Return objTemp
End If
End Function
I know, using Interfaces would be better, but couldn't get it to quite work
the way I need it to. When the Main App starts, it updates all these DLL's,
and the Interface kept binding immediatly and locking the file. But anyhew,
I'm not understanding this, the ArrayList is being passed just fine as far
as I can tell...
Thanks
Sueffel