-
Feb 1st, 2024, 06:58 PM
#1
Thread Starter
PowerPoster
how to clear class by self in vb6?
Is there any way to reclaim variables in class1?
Set Me = Nothing 'err here
Code:
form1.frm:
dim a as new class1
a.DelObject
Sub DelObject()
Set Me = Nothing 'err here
End Sub
Sub DoRelease()
dim class1Objptr as long
class1Objptr=ObjPtr(Me)
clear by api with class1Objptr??
End Sub
Private Sub Class_Terminate()
MsgBox "Class_Terminate"
End Sub
Last edited by xiaoyao; Feb 1st, 2024 at 07:02 PM.
-
Feb 1st, 2024, 07:10 PM
#2
Thread Starter
PowerPoster
Re: how to clear class by self in vb6?
why Set C = Nothing,
C.TEST
why Set C = Nothing,
C.TEST
Why can I use the methods in the object when the variables are empty? (Will automatically reinitialize the class object)
Code:
Dim C As New Class1
Private Sub Command1_Click()
C.TEST
End Sub
Private Sub Command3_Click()
Set C = Nothing
End Sub
-
Feb 1st, 2024, 07:30 PM
#3
Re: how to clear class by self in vb6?
Yeah, this is a quirk of VB6 thast confuses a lot of people the first time.... so, when you do this::
Code:
Dim C As New Class1
causes this:
To be proccessed like this by th compiler:
Code:
If C is Nothing Then
set C = new Class1
End If
C.TEST
So even though you set C to Nothing, the next time you click Command1, it'll get re-crreated. Now.... if you this:
Code:
Dim C As Class1
private sub Form_Load()
set C = New Class1
End Sub
Private Sub Command1_Click()
C.TEST
End Sub
Private Sub Command3_Click()
Set C = Nothing
End Sub
Now it'll operate as you'd expect.
-tg
-
Feb 1st, 2024, 09:42 PM
#4
Thread Starter
PowerPoster
Re: how to clear class by self in vb6?
yes,Dim C As Class1
thank you
-
Feb 2nd, 2024, 07:09 AM
#5
Re: how to clear class by self in vb6?
Here's a "compromise" that gets you as close to VB.Net syntax as VB "proper" will allow:
Code:
Dim C as Class1 : Set C = New Class1
Regards, Phill W.
-
Feb 2nd, 2024, 09:41 AM
#6
Re: how to clear class by self in vb6?
I use the pre-declared form names all the time, with no problem.
However, to get the COM object uninstantiated when the form unloads, you have to explicitly use that form's pre-declared variable name. Let's say you have a Form1. To get its COM object uninstantiated, you'd do the following:
Code:
Private Sub Form_Unload(Cancel As Integer)
Set Form1 = Nothing
End Sub
And you can't use the "Me" object because that's another reference to this Form1 object. You need to explicitly set that Form1 object variable to Nothing to get the last reference destroyed. And obviously, you need to make sure there aren't any other references that will re-load that COM object.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Feb 2nd, 2024, 07:53 PM
#7
Thread Starter
PowerPoster
Re: how to clear class by self in vb6?
how to set class1=nothing by api or asm code
some times i need do like this:
form1:
Code:
dim classA as new class1
SUB TIEMR1
SET classA =NOTHING
TIMER1.ENABLE=FALSE
END SUB
class1:
sub doCloseMe()
form1.timer1.enable=true
end sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|