Solved

Read/Write to activeX dll's UDT

Posted on 2001-07-04
8
294 Views
Last Modified: 2008-03-06
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
Comment
Question by:PeteD
8 Comments
 
LVL 7

Expert Comment

by:John844
ID: 6253540
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
 
LVL 15

Expert Comment

by:ameba
ID: 6254018
> obj.ERFields.ERPRPOverviewVisited = True

Use this syntax:
     With obj.ERFields
         .ERPRPOverviewVisited = True
     End With
0
 
LVL 15

Expert Comment

by:ameba
ID: 6254025
0
 
LVL 1

Expert Comment

by:Aaron_Young
ID: 6254039
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Expert Comment

by:ameba
ID: 6254058
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
 
LVL 2

Author Comment

by:PeteD
ID: 6254787
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
 
LVL 15

Accepted Solution

by:
ameba earned 100 total points
ID: 6255023
>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
 
LVL 2

Author Comment

by:PeteD
ID: 6326906
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now