• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

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????
0
PeteD
Asked:
PeteD
1 Solution
 
John844Commented:
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
0
 
amebaCommented:
> obj.ERFields.ERPRPOverviewVisited = True

Use this syntax:
     With obj.ERFields
         .ERPRPOverviewVisited = True
     End With
0
 
amebaCommented:
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Aaron_YoungCommented:
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.
0
 
amebaCommented:
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.
0
 
PeteDAuthor Commented:
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 ????????
0
 
amebaCommented:
>i.e. it can only be set, and then read within the same with > end with clause ????????

Yes,  "With MyFrm.a1"  must be used - it will create temporary object.  That internal object has some address and that allows passing address (passing by reference).
The other, "normal" syntax will really pass value (expression).

Well, maybe term "internal object" is not good, since UDTs are not objects.

Anyway, to pass ByRef, the declaration is not enough - you must pass a variable, you cannot pass an "expression", see this PAQ (1 pts)
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20137162
0
 
PeteDAuthor Commented:
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!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now