Hi, Michael -
Your alternative code only works the same as the original when the app manager object (gnv_app) and the Debug service object (inv_debug) are instantiated. In a service-based architecture like the PFC, the objects implementing the various services and features/sub-services will only exist when they are enabled, so the original code snippet you posted is not only quite common within the PFC, it is more importantly, correct.
In a PFC application, it is generally assumed that the gnv_app object will exist, but it only has to exist if the application is utilizing PFC services and objects... it is not a requirement. The Debug service object (the inv_debug object reference instance variable of gnv_app) exists only when that service is enabled, and the SQL Spy sub-service of the Debug service (the inv_sqlspy object reference instance variable of inv_debug) likewise.
The alternative code you've supplied executes successfully only when gnv_app and inv_debug are both valid. If executed, resolving the reference to the inv_sqlspy object will produce a runtime error when either or both of the gnv_app or inv_debug objects are not valid. The original code works under all conditions.
As a test, I placed the following code in a command button in a window of a PFC application where gnv_app is valid and the Debug service is not enabled (i.e., is not valid):
String ls_msg
If IsValid(gnv_app.inv_debug.inv_sqlspy) Then
ls_msg = "IsValid results: True"
Else
ls_msg = "IsValid results: False"
End If
MessageBox("Test Results",ls_msg)
When executing, a Null Object Reference error occurs at line 3 (the IF-statement) because inv_debug is not valid.
HTH
John