The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:




Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

thorwathModerator
Veteran


Reged: 07/22/99
Posts: 3840
Loc: Grand Rapids, MI
Re: Set Object = Nothing within UserRegisteredFunc
      10/01/07 07:09 AM

Yaron,

Thanks for this info.

Also, now that this has caught my interest here is QTP script that can be executed (if you don't have the Print utility then change the Print statements to Reporter.ReportEvent statements) that shows it makes no difference how a called function's input parm is declared, when that function invalidates a passed object reference, i.e. the passed reference is always by value because a new reference is created when the function is call.

I know what I just said above is confusing (a more skilled writer could probably do better) but the bottom line is: "you can't invalidate an object reference by calling a function that performs a Set blah=Nothing" statement". Run the code below twice to convince yourself:

1. on first pass comment out "Function objToNothing (byRef refB)" and uncomment "Function objToNothing (byVal refB)".

2. On the second pass reverse the above.

In both runs the output will be the same:

interation #0, refA references a fooClass Object
interation #1, refA references a fooClass Object
interation #2, refA == Nothing

Code:

Option Explicit
'
Class fooClass
End Class
Dim refA
Set refA=new fooClass 'create a single fooClass object; also init refA to reference this object
'
'Function objToNothing (byVal refB)
Function objToNothing (byRef refB) 'NOTE: no matter how refB parm is declared a 2nd reference
set refB=Nothing ' is always passed to this function
End Function
'
Function main()
'
Dim i
'
For i=0 to 2
'
If typeName(refA)="Nothing" Then
Print "interation #"&i&", refA == Nothing"
else
Print "interation #"&i&", refA references a "&typeName(refA)&" Object"
End If
'
If i=0 Then
objToNothing(refA)
else
Set refA=Nothing
End If
Next
'
End Function
main



-Terry

Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* Set Object = Nothing within UserRegisteredFunc robbiewinston 10/01/07 01:22 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 01:58 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc thorwathModerator   10/01/07 04:13 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 04:26 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc thorwathModerator   10/01/07 06:12 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 06:25 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc thorwathModerator   10/01/07 07:09 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 09:40 PM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 10:24 PM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/03/07 10:18 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc thorwathModerator   10/03/07 10:37 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/03/07 10:58 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Yaron Assa   10/01/07 02:06 AM
. * * Re: Set Object = Nothing within UserRegisteredFunc Vengat   10/01/07 02:36 AM

Extra information
0 registered and 68 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Thread views: 8358

Rate this thread

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5