How to pass a late binding parameter

In VB6, I am trying to pass a related object to another form.

frmMain.vb

Dim x
Set x = CreateObject("MyOwn.Object")
Dim f as frmDialog
Set f = New frmDialog
f.SetMyOwnObject x

frmDialog

Dim y
Public Sub SetMyOwnObject(ByVal paramX As Variant)
  Set y = paramX
End Sub

The contents of y are a string containing the type name of the previously linked MyOwn.Object. ByVal and ByRef don't matter. Any clues? You have trouble remembering.

+3
source share
4 answers

I used VarType (y). The result is 8, for vbString. This should be 9 for the object. - ssorrrell 1 hour ago

Use Print y in the Immediate window to find the contents of y. - ssorrrell 55 minutes ago

This seems to confirm my suspicions. The class MyOwn.Objectmust have a default property or method that returns a string.

, Debug.Print / . IDE, VB6 / . VarType y, .

, Variant, Object, , .

, MyOwn.Object , MyOwn.Object . , , , . , , , .

, Variant Object S, . , y As Object, Debug.Print y - , VarType(y) - 8 ().

, VB6 , . , y Object, TypeName(y) MyOwn.Class, VarType(y) 8 (). , y Variant, TypeName(y) String.

, , Object Variant.

0

VB6, , , , Object, Variant . , , , , Object , VB - .

+2

, Set, .

Dim y
Public Sub SetMyOwnObject(ByVal paramX As Variant)
  ' Set y = paramX  ' thought you had this...
  y = paramX        ' ...actually have this
End Sub

, y . MyOwn.Object , ( ​​ VB)?

0

frmMain.vb

Dim x As Object
Set x = CreateObject("MyOwn.Object")
Dim f as frmDialog
Set f = New frmDialog
f.SetMyOwnObject x

frmDialog

Dim y As Object
Public Sub SetMyOwnObject(ByRef paramX As Object)
  Set y = paramX
End Sub

CreateObject, , . ByRef.

0
source

Source: https://habr.com/ru/post/1713282/


All Articles