[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

James Tyler

3/13/2012 2:51:00 PM

Can someone tell me the best way to make it work ? And why it does not work.

Thanks


======== Module1 =========
Option Explicit
Public Type typeA
s1 As String
End Type

Sub Main()
Dim obj As New Class1
obj.t1.s1 = "NEW" ' ******** Why is this not working
MsgBox obj.t1.s1
End Sub

======== Class 1 =======
Option Explicit
Private m_t1 As typeA

Friend Property Get t1() As typeA
t1 = m_t1
End Property

Friend Property Let t1(v As typeA)
m_t1 = v
End Property

Private Sub Class_Initialize()
m_t1.s1 = "INIT"
End Sub






3 Answers

Bob Butler

3/13/2012 3:02:00 PM

0


"Phil Hunt" <aaa@aaa.com> wrote in message
news:jjnmsp$n39$1@speranza.aioe.org...
> Can someone tell me the best way to make it work ? And why it does not
> work.
>
> Thanks
>
>
> ======== Module1 =========
> Option Explicit
> Public Type typeA
> s1 As String
> End Type
>
> Sub Main()
> Dim obj As New Class1
> obj.t1.s1 = "NEW" ' ******** Why is this not
> working
> MsgBox obj.t1.s1
> End Sub
>
> ======== Class 1 =======
> Option Explicit
> Private m_t1 As typeA
>
> Friend Property Get t1() As typeA
> t1 = m_t1
> End Property
>
> Friend Property Let t1(v As typeA)
> m_t1 = v
> End Property
>
> Private Sub Class_Initialize()
> m_t1.s1 = "INIT"
> End Sub

The line obj.t1.s1="NEW" does this:
evaluate obj.t1 by calling the property Get and getting a copy of the data
in the type
evaluate (copy of data).s1="NEW" by modifying s1 in the local copy
discard the local copy

You have 2 basic choices: (1) change the type to another class so that you
get a reference to the object it represents rather than a local copy of the
data it contains or (2) change your properties to access the type
indirectly:

Friend Property Get s1() As String
s1 = m_t1.s1
End Property

Friend Property Let s1(v As String)
m_t1.s1 = v
End Property

and make the calling code:

obj.s1 = "NEW"
MsgBox obj.s1


James Tyler

3/13/2012 3:37:00 PM

0

yes, bascially the property Get run, but the property Let does not run at
all.



Dee Earley

3/13/2012 4:48:00 PM

0

On 13/03/2012 15:36, Phil Hunt wrote:
> yes, bascially the property Get run, but the property Let does not run at
> all.

Correct, as nothing was actually being assigned to the t1 property.

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)