Link to home
Start Free TrialLog in
Avatar of PeteD
PeteD

asked on

Read/Write to activeX dll's UDT

I have a UDT declared in my dll project's class:-

Public Type TFields
    ArrangingMortgageOrDiscussER 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.ERPRPOverviewVisited

but I cant write the data back to the class using:

obj.ERFields.ERPRPOverviewVisited = 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????
Avatar of John844
John844

do you ever define the module variable mERFields?
like
Public Type TFields
   ArrangingMortgageOrDiscussER As EArrMortDiscER
   ERPRPOverviewVisited As Boolean
   DiscussLTH As EBroadDetailCombo
   DiscussER As EYesNoCombo
   DiscussIHT As EYesNoCombo
'etc
End Type

private mERFields as TFields
> obj.ERFields.ERPRPOverviewVisited = True

Use this syntax:
     With obj.ERFields
         .ERPRPOverviewVisited = True
     End With
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.
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.
Avatar of PeteD

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 ????????
ASKER CERTIFIED SOLUTION
Avatar of ameba
ameba
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PeteD

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!