结构和ArrayList [英] Structures and ArrayList
问题描述
我遇到这个问题:
我有一个结构被添加到一个arraylist,所以我可能有15个
这些结构对象在一个arraylist。现在,我想要做的是:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
我甚至试过这个:
TT = CType(MyArrayList.Item(3),MyStruct)
每个案例都给我一个指定演员阵容无效例外。
谢谢
Ssueffel
---
外发邮件已通过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft .com)。
版本:6.0.580 /病毒库:367 - 发布日期:2004年2月6日
" Sueffel" <所以***** @ somewhere.com> schrieb我遇到了这个问题:
我有一个结构被添加到一个arraylist,所以我可能有一个这样的结构对象中的15个数组列表。现在,我想要做的是:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
<我甚至试过这个:
TT = CType(MyArrayList.Item(3),MyStruct)
每个案例都给我一个指定的演员阵容无效。例外。
无法重现问题:
结构mystruct
Public x As Integer
结束结构
''....
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)''或Directcast而不是CType
-
Armin
如何报价以及原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
" Armin Zingler" < AZ ******* @ freenet.de>在消息中写道
news:Oa ************** @ tk2msftngp13.phx.gbl ..." Sueffel" <所以***** @ somewhere.com> schrieb我遇到了这个问题:
我有一个结构被添加到一个arraylist,所以我可能有一个这样的结构对象中的15个数组列表。现在,我想要做的是:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
<我甚至试过这个:
TT = CType(MyArrayList.Item(3),MyStruct)
每个案例都给我一个指定的演员阵容无效。例外。
无法重现问题:
结构mystruct
公共x作为整数
结束结构
''....
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)''或Directcast而不是CType
- < Armin
如何报价和原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
好的,在我的DLL中,我有这个:
朋友类CommandList
公共结构Simenz
Dim FunctionName As String
Dim NamespaceClass As String
Dim ParentMenu As String
Dim作为字符串的描述
Dim MenuIndex作为整数
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&q) uot;,
" 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))
返回ContainedFunction
结束功能
结束班级
在我的申请表中我有这个:
Dim MyObj As Object
dim Libraries as String()= Directory.GetFiles(Application.StartupPath,
" * .dll")
dim Libb as String
For Libb in Libraries
MyObj = ClassByName(Libb," CommandList")
如果不是MyObj什么都没有那么
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)''***
下一页
结束如果
下一页
3 Astrisks是我得到的,我得到Specified Cast无效。
例外。 DLL是一个未引用的程序集,我正在使用以下函数进行后期绑定
:
公共函数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, _
没什么,_
没什么,_
没什么,_
什么都没有)
如果objTemp什么都没有那么
抛出新的例外(插件& strAssemblyFileName&"可以
没有加载')
Else
返回objTemp
结束如果
结束功能
我知道,使用接口会更好,但是不能让它按照我需要的方式工作
。当主应用程序启动时,它会更新所有这些DLL,
并且界面立即保持绑定并锁定文件。但是,不管怎样,
我不明白这一点,ArrayList正好被传递到目前为止
,因为我可以告诉......
>
谢谢
Sueffel
---
邮件已通过无病毒验证。
已检查AVG反病毒系统( http://www.grisoft.com)。
版本:6.0.580 /病毒库:367 - 发布日期:2004年2月6日
" ; Armin Zingler < AZ ******* @ freenet.de>在消息中写道
news:Oa ************** @ tk2msftngp13.phx.gbl ..." Sueffel" <所以***** @ somewhere.com> schrieb我遇到了这个问题:
我有一个结构被添加到一个arraylist,所以我可能有一个这样的结构对象中的15个数组列表。现在,我想要做的是:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
<我甚至试过这个:
TT = CType(MyArrayList.Item(3),MyStruct)
每个案例都给我一个指定的演员阵容无效。例外。
无法重现问题:
结构mystruct
公共x作为整数
结束结构
''....
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)''或Directcast而不是CType
- < Armin
如何报价和原因:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
忘了提到结构也在主应用程序中定义了一个
模块。要尝试把它放在表单类中,看看会发生什么,我是
也会试着让DLL中的那个共享。
Sueffel
---
外发邮件经过无病毒认证。
由AVG反病毒系统检查( http://www.grisoft.com)。
版本:6.0.580 /病毒数据库:367 - 发布日期:2004年2月6日
I''m having problems with this one:
I have a tructure that is being added to an arraylist, so I may have 15 of
these structure objects in an arraylist. now, what I want to do is this:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
I have even tried this:
TT = CType(MyArrayList.Item(3), MyStruct)
Each case gives me a "Specified cast is invalid" exception.
Thanks
Ssueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
"Sueffel" <so*****@somewhere.com> schriebI''m having problems with this one:
I have a tructure that is being added to an arraylist, so I may have
15 of these structure objects in an arraylist. now, what I want to
do is this:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
I have even tried this:
TT = CType(MyArrayList.Item(3), MyStruct)
Each case gives me a "Specified cast is invalid" exception.
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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl..."Sueffel" <so*****@somewhere.com> schriebI''m having problems with this one:
I have a tructure that is being added to an arraylist, so I may have
15 of these structure objects in an arraylist. now, what I want to
do is this:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
I have even tried this:
TT = CType(MyArrayList.Item(3), MyStruct)
Each case gives me a "Specified cast is invalid" exception.
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
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Oa**************@tk2msftngp13.phx.gbl..."Sueffel" <so*****@somewhere.com> schriebI''m having problems with this one:
I have a tructure that is being added to an arraylist, so I may have
15 of these structure objects in an arraylist. now, what I want to
do is this:
dim TT as MyStruct = New MyStruct
TT = MyArraylist.Item(3)
I have even tried this:
TT = CType(MyArrayList.Item(3), MyStruct)
Each case gives me a "Specified cast is invalid" exception.
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
Forgot to mention that the structure is also defined in the Main App in a
module. Gonna try and put that in the form class and see what happens, I''m
also going to try and make the one in the DLL Shared.
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
这篇关于结构和ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!