自定义属性中怎么实现动态数组

jsstb 2009-03-14 04:24:23
在自定义DLL中定义属性InData代码如下:
Public Structure typDt
Dim userdt1 As Long
Dim userdt2 As Long
End Structure

Public Structure typData
Dim lngTCode As Long
Dim lngAll As Long
Dim UserData() As typdt
End Structure

Public Property InData() As typData
Get
Return InDt
End Get
Set(ByVal value As typData)
InDt = value
End Set
End Property
其中属性InData为一结构变量,其中成员UserData()是一个动态数组,即在使用DLL时才能决定数组长度,由DLL的另外一个属性来设置。应该怎么写代码?
我用ReDim重新分配数组,应该写在哪里?是写在DLL里,还是使用DLL时,写在工程里?
...全文
211 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jsstb 2009-03-15
  • 打赏
  • 举报
回复
我的意思是想定义一个Indata属性,该属性包括三个成员lngTCode、lngAll和动态数组UserData(),行吗?
pjagz 2009-03-15
  • 打赏
  • 举报
回复
动态数组不小于上一次的设定数组是可保存的(只保存新数组部份)。ReDim [Preserve]关键字的作用
Public Structure typData
Dim lngTCode As Long '不保存
Dim lngAll As Long '不保存
Dim UserData() As typdt '可保存 动态数组
End Structure
jsstb 2009-03-15
  • 打赏
  • 举报
回复
谢谢楼上的指点,但是我想保留Indata属性,该属性的数据类型为typData,能行吗?
问题的关键是Indata属性里的一个成员是动态数组,行吗?
pjagz 2009-03-14
  • 打赏
  • 举报
回复
'也可这样
Public Structure typDt
Dim userdt1 As Long
Dim userdt2 As Long
End Structure

Public Structure typData
Dim lngTCode As Long
Dim lngAll As Long
Dim UserData() As typdt
End Structure

Dim Mydat As typData

Public ReadOnly Property GetUse(ByVal sR As Integer) As typData
Get
ReDim Preserve Mydat.UserData(sR)
Return Mydat
End Get

End Property
pjagz 2009-03-14
  • 打赏
  • 举报
回复
Public Structure typDt
Dim userdt1 As Long
Dim userdt2 As Long
End Structure

Public Structure typData
Dim lngTCode As Long
Dim lngAll As Long
End Structure

Dim UserData As typDt()

Public Property SetUser() As Integer

Get
Return UserData.Length
End Get

Set(ByVal value As Integer)
ReDim Preserve UserData(value)
End Set

End Property

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧