//cut and paste
//for free use with gfa basic
'Advanced Example 2 test for loaded object in memory
'A Shura
'Discussion: how do you test to see that and object
'is actually in memory at one time or another in
'your programs? You can avoid errors if you know.
'But there may be some confusion around the GFA Basic
'function IsObject(). IsObject() only tests if a
'variant type varible has been initialized with the
'same name as an object, in this example the object
'is a gb32 textbox named tb2. Even if IsObject() is
'true, the object may not actually be in memory at
'the same time.
'A child (or an independent) object, is unloaded
'from memory with Set Object = Nothing
'To test to see if an object is loaded without
'triggering an exception you need a Try Catch
'construct.
OpenW 1
AutoRedraw = True
'note: IsObject() will not test
'for an unloaded object, it only
'tests for the existance of a type
'variant variable.
Ocx TextBox tb2 'create
' Set tb2 = Nothing
'has no effect on IsObject()
Set tb2 = Nothing
Print "TextBox tb2 Is Nothing is it an object?"
Print IsObject(tb2)
Print "TextBox tb2 Is Nothing is it loaded in memory?"
'use the following code instead:
Try 'if no exception interrrupt
tb2.SetFocus 'do something to communicate
Print "tb2 is a loaded object in memory "
Catch
Print "tb2 is not a loaded object in memory "
EndCatch
Ocx TextBox tb2 'reload into memory after Nothing
Print "I've reinitialised TextBox tb2"
Try
tb2.SetFocus 'do something to communicate
Print "tb2 is a loaded object in memory "
Catch
Print "tb2 is not a loaded a object in memory "
EndCatch
Do : Sleep : Until Me Is Nothing
CloseW 1