Structure-Properties?

Fazzyer

Member
Joined
Jul 29, 2005
Messages
16
Programming Experience
5-10
Hi all!

I'm writing a class-DLL at the moment and have a big problem: I have a structure in the DLL and two properties with the structure as type.

VB.NET:
Public Class MyDLLClass
 
Public Structure STest
    Dim Text As String
End Structure
 
...
 
Private FSingle, FMulti() As STest
 
...
 
Public Property Single() As STest
    Get
        Return FSingle
    End Get
    Set ...
End Property
 
Public Property Multi() As STest()
    Get
        Return FMulti
    End Get
    Set ...
End Property
 
End Class

All is fine until here.
Now - in another program - I create an instance from the DLL-class an want to set the ".Text"-Part from the structure-properties. But this works only for the Array-Property ("Multi").

VB.NET:
Private DllClass As New MyDLLClass()
 
DllClass.Multi(0).Text = "This works fine"
 
DllClass.Single.Text = "This doesn't work [Expression is a value and therefore cannot be the target of an assignment]"

Do you know, where the problem is? I'm trying for hours and hours now, am I to stupid? :) If you can, please help me!

- Fazzyer
 
The problem is the fact that you are trying to treat a value-type object as though it was a reference type object. When you refer to DllClass.Single, because the object you are referring to is a value-type, what you are actually given is a temporary copy, so you cannot alter properties of that copy and have the change reflected in the original. What you would need to do is either get the existing object or create a new object, set its Text property and then assign that object to the Single property.
VB.NET:
Dim mySTest As STest = DllClass.Single

mySTest.Text = "This will work now."
DllClass.Single = mySTest
or
VB.NET:
Dim mySTest As STest

mySTest.Text = "This will work now."
DllClass.Single = mySTest
 
Back
Top