How to upgrade Objptr function from VB6 to VB2005

  • Thread starter Thread starter t
  • Start date Start date
T

t

In VB6, I usually use objptr function and API copymemory to identify and
obtain an object, how can I convert them into VB2005? Your kindly help would
be much appreciated.
 
t said:
In VB6, I usually use objptr function and API copymemory to identify and
obtain an object, how can I convert them into VB2005? Your kindly help
would
be much appreciated.

I suggest to describe the scenario in more detail. There are maybe plenty
of alternative solutions which are preferrable over the 'CopyMemory'
solution.
 
Hi,
I would like to describe my application here, pls kindly read through
it.
In my app, I have 2 classes QRecord and QRecords, and class QRecords is
a collection of class QRecord. Codes are listed below.

1.Code of QRecord
Private mvarParentPointer As Variant
Public Function GetParent() As QRecords
Dim oTemp As Object

'********************************************
CopyMemory oTemp, mvarParentPointer, 4
'*********************************************

Set GetParent = oTemp
CopyMemory oTemp, 0&, 4
End Function

Friend Property Let ParentPointer(ByVal vData As Variant)
mvarParentPointer = vData
End Property


Friend Property Set ParentPointer(ByVal vData As Variant)
Set mvarParentPointer = vData
End Property



2.Code of QRecords
Private mCol As Collection

Public Function Add(Optional sKey As String) As QRecord
Dim objNewMember As QRecord
Set objNewMember = New QRecord

'***********************************************************
objNewMember.ParentPointer= ObjPtr(Me)
'***********************************************************

If Len(sKey) = 0 Then
mCol.Add objNewMember
Else
mCol.Add objNewMember, sKey
End If

Set Add = objNewMember
Set objNewMember = Nothing

End Function

Public Property Get Item(vntIndexKey As Variant) As QRecord
Set Item = mCol(vntIndexKey)
End Property



Public Property Get Count() As Long
Count = mCol.Count
End Property


Public Sub Remove(vntIndexKey As Variant)
mCol.Remove vntIndexKey
End Sub

Public Property Get NewEnum() As IUnknown
Set NewEnum = mCol.[_NewEnum]
End Property


Private Sub Class_Initialize()
Set mCol = New Collection
End Sub


Private Sub Class_Terminate()
Set mCol = Nothing
End Sub


QRecord have a pointer to it parent without counting reference to
QRecords, so that instance of QRecords can be destroyed when it is set to
nothing, no need to enumerate all QRecord items and set them to nothing one
by one in case QRecord has an attribute of QRecords referencing it parent
dirrectly.

Hope I am understood and able to get your help. Thanks in advanced.
 
t said:
QRecord have a pointer to it parent without counting reference to
QRecords, so that instance of QRecords can be destroyed when it is
set to nothing, no need to enumerate all QRecord items and set them
to nothing one
by one in case QRecord has an attribute of QRecords referencing it
parent dirrectly.


In .Net, we don't have reference counts anymore like in VB6/COM. We can now
make circular references without worrying about "lost" objects referencing
each other. Have the QRecord point to the QRecords collection and everything
is fine. When you delete the last reference to the collection, the GC
(garbage collector) will clean the collection and it's items (when it's time
to) even if they reference each other.


Armin
 
sanitha said:
How to get a pointer to the form???

In VB 6, It is like objPtr(formname)...This wil return memory address of d
form.
In VB.net how it acn be done?

You still should describe what you want to archieve with the pointer.
 
Back
Top