How to export a UDT from a Class
- From: "Tony Proctor" <tony_proctor@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 2 Jun 2005 18:06:50 +0100
I have a problem with exporting a UDT from a Public class and have it being
modifiable. It may be related to something I thought was a bug a couple of
years ago
(http://groups.google.ie/group/microsoft.public.vb.bugs/msg/4f99d5da34f04162
?hl=en)
Note that isn't the usual problem of not being able to export UDTs unless
the Type is Public and in a Public class. Everyone knows that one. No, in
this case, changes to the UDT just disappear. It's almost as though all
attempts to modify it are actually modifying a copy. This sounds likely
knowing that UDTs are assigned by value, not by reference. Obviously, trying
to export the UDT via a Property of the same UDT type will fail because a
copy would be exported. However, I get the same results when using a Variant
type too.
Here's a simplistic example of what is currently failing. Create a small
project group containing Form1 in a standard EXE, and Class1 in an ActiveX
DLL.
======= Form1 ==========
Dim o As Class1
Private Sub Command1_Click()
With o.Var
Debug.Print .s
End With
End Sub
Private Sub Form_Load()
Set o = New Class1
With o.Var
.s = "Hello"
Debug.Print .s
End With
End Sub
======================
======= Class1 ==========
Public Type t
s As String
End Type
Private tVar As t
Public Property Get Var() As Variant
Var = tVar
End Property
======================
The Form_Load sets the 's' member in the UDT, and a Debug.Print confirms it.
However, the Command1_Click shows it's no longer there. Hence, it seems
assigning a UDT to a Variant also seems to take a copy.
Anyone have any suggestions. I know someone will recommend switching from
UDTs to Objects but some of the members must be arrays, and you can't export
them directly from a Public class -- certainly not in a way that will allow
UBound and ReDim to work on them.
....arggg!
Tony Proctor
Tony Proctor
.
- Follow-Ups:
- Re: How to export a UDT from a Class
- From: Tony Proctor
- Re: How to export a UDT from a Class
- From: Ken Halter
- Re: How to export a UDT from a Class
- From: Ken Halter
- Re: How to export a UDT from a Class
- Prev by Date: Re: Veiwing Datasets in Debug Mode
- Next by Date: Re: How to export a UDT from a Class
- Previous by thread: listbox repainting anomoly with XP
- Next by thread: Re: How to export a UDT from a Class
- Index(es):
Relevant Pages
|