Results 1 to 2 of 2

Thread: 'Loose' declaration 're-discovery'

  1. #1

    Thread Starter
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    'Loose' declaration 're-discovery'

    I just want to share what I have 're-discovered'... Its a disadvantage of 'loose' declaration of objects...

    Case 1:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim x As New ADODB.Recordset
    3.     Set x = Nothing
    4.     'Will return false
    5.     MsgBox x Is Nothing
    6. End Sub
    7.  
    8. Private Sub Command2_Click()
    9.     Dim x As ADODB.Recordset
    10.     Set x = New ADODB.Recordset
    11.     Set x = Nothing
    12.     'Will return true
    13.     MsgBox x Is Nothing
    14. End Sub

    Case 2:
    VB Code:
    1. 'In Form1
    2. Option Explicit
    3.  
    4. Private Sub Command1_Click()
    5.     Form2.ObjectsAreLoaded
    6. End Sub
    7.  
    8. 'In Form2
    9. Option Explicit
    10. Private adoRecordset1 As New ADODB.Recordset
    11. Private adoRecordset2 As ADODB.Recordset
    12.  
    13. Public Sub ObjectsAreLoaded()
    14.     'Will return false = means object is instantiated
    15.     MsgBox adoRecordset1 Is Nothing
    16.     'Will return true = means object is not yet instantiated
    17.     MsgBox adoRecordset2 Is Nothing
    18. End Sub
    Last edited by dee-u; Jul 19th, 2005 at 09:55 PM.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: 'Loose' declaration 're-discovery'

    In case anyone is wondering. That is because when you use loose binding, as soon as you reference the object, VB checks to see if it exists. If not then it creates it, which is why, as dee-u has shown above, you cannot test to see if it is Nothing, because even if you have explicitly destroyed it when the test is executed the object is created.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width