PeteD
asked on
Read/Write to activeX dll's UDT
I have a UDT declared in my dll project's class:-
Public Type TFields
ArrangingMortgageOrDiscuss ER As EArrMortDiscER
ERPRPOverviewVisited As Boolean
DiscussLTH As EBroadDetailCombo
DiscussER As EYesNoCombo
DiscussIHT As EYesNoCombo
'etc
End Type
and I am instancing the dll from my form in the exe project. During the initialisation, the TFields gets its data from the database and is made available to the form using:
Public Property Get ERFields() As TFields
ERFields = mERFields
End Property
Public Property Let ERFields(NewFields As TFields)
mERFields = NewFields
End Property
The problem is that I can't use:
Public Property Let ERFields(byVal NewFields As TFields)
as this creates an error, and hence I can read the data using e.g.
Command1.Visible = obj.ERFields.ERPRPOverview Visited
but I cant write the data back to the class using:
obj.ERFields.ERPRPOverview Visited = True
... the value is lost. I do not want to have separate lets and gets for every single property. How else can I make a UDT in an activeX dll class read/write???? Any ideas????
Public Type TFields
ArrangingMortgageOrDiscuss
ERPRPOverviewVisited As Boolean
DiscussLTH As EBroadDetailCombo
DiscussER As EYesNoCombo
DiscussIHT As EYesNoCombo
'etc
End Type
and I am instancing the dll from my form in the exe project. During the initialisation, the TFields gets its data from the database and is made available to the form using:
Public Property Get ERFields() As TFields
ERFields = mERFields
End Property
Public Property Let ERFields(NewFields As TFields)
mERFields = NewFields
End Property
The problem is that I can't use:
Public Property Let ERFields(byVal NewFields As TFields)
as this creates an error, and hence I can read the data using e.g.
Command1.Visible = obj.ERFields.ERPRPOverview
but I cant write the data back to the class using:
obj.ERFields.ERPRPOverview
... the value is lost. I do not want to have separate lets and gets for every single property. How else can I make a UDT in an activeX dll class read/write???? Any ideas????
> obj.ERFields.ERPRPOverview Visited = True
Use this syntax:
With obj.ERFields
.ERPRPOverviewVisited = True
End With
Use this syntax:
With obj.ERFields
.ERPRPOverviewVisited = True
End With
See also PAQ for sample
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20117807
or
HOWTO: Remote User-Defined Types
http://support.microsoft.com/support/kb/articles/Q185/7/00.asp
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20117807
or
HOWTO: Remote User-Defined Types
http://support.microsoft.com/support/kb/articles/Q185/7/00.asp
In your example you're passing the structure to the property by value, you should be passing it by reference, i.e.
Public Property Let ERFields(ByRef NewFields As TFields)
Regards,
- Aaron.
Public Property Let ERFields(ByRef NewFields As TFields)
Regards,
- Aaron.
Hehe, welcome Aaron
Good to see you here!
ameba (Bruno on Codeguru)
Yes, it should be ByRef, I forgot to mention that part of the problem.
Good to see you here!
ameba (Bruno on Codeguru)
Yes, it should be ByRef, I forgot to mention that part of the problem.
ASKER
ameba,
from your previous EE accepted answer:
caraf_g,
Yes, 'Friend' works only in the same project.
If UDT must be Public, so it can be passed between components, then it must be defined in public class
module.
Project should be ActiveX EXE (or any other ActiveX project type)
Change project to ActiveX EXE.
Set it's Startup mode to Standalone (project properties, components tab)
' Class2, set Instancing=6 'GlobalMultiUse -----
Option Explicit
Public Type a
X As Integer
Y As Integer
End Type
' module1 -------------
Option Explicit
Sub main()
Form1.Show
End Sub
' Class1 ------------
Option Explicit
Private m_a1 As a
Public Function a1() As a
a1 = m_a1
End Function
' form1 ------------
Option Explicit
Dim MyFrm As Class1
Private Sub Form_Click()
Set MyFrm = New Class1
With MyFrm.a1
.X = 10
MsgBox .X 'WORKS, but
End With
Msgbox MyFrm.a1.x 'DOESN'T work
End Sub
i.e. it can only be set, and then read within the same with > end with clause ????????
from your previous EE accepted answer:
caraf_g,
Yes, 'Friend' works only in the same project.
If UDT must be Public, so it can be passed between components, then it must be defined in public class
module.
Project should be ActiveX EXE (or any other ActiveX project type)
Change project to ActiveX EXE.
Set it's Startup mode to Standalone (project properties, components tab)
' Class2, set Instancing=6 'GlobalMultiUse -----
Option Explicit
Public Type a
X As Integer
Y As Integer
End Type
' module1 -------------
Option Explicit
Sub main()
Form1.Show
End Sub
' Class1 ------------
Option Explicit
Private m_a1 As a
Public Function a1() As a
a1 = m_a1
End Function
' form1 ------------
Option Explicit
Dim MyFrm As Class1
Private Sub Form_Click()
Set MyFrm = New Class1
With MyFrm.a1
.X = 10
MsgBox .X 'WORKS, but
End With
Msgbox MyFrm.a1.x 'DOESN'T work
End Sub
i.e. it can only be set, and then read within the same with > end with clause ????????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks all for your input! I got round this by declaring my UDT locally, and then passing it back to the class before saving to the database. It's a shame that you have to do this in VB :-( but there we go!
like
Public Type TFields
ArrangingMortgageOrDiscuss
ERPRPOverviewVisited As Boolean
DiscussLTH As EBroadDetailCombo
DiscussER As EYesNoCombo
DiscussIHT As EYesNoCombo
'etc
End Type
private mERFields as TFields