Bill,
If you have an alias or object variable which
may or may not contain a valid object, you can use a test as below before
assigning it to an object variable and using it. The trick is to defer the
object assignment until you are safely in a function with an error
handler.
I also use NULL objects where an object variable
must be returned. In this case, create it as a small
object, outside the bounds of your working tables to ensure no intersects
etc.
I sometimes find alias variables dont behave as I
would expect (see note at function IsObjectT), but its probably because I dont
fully understand the scope of their use.
Dim reci as smallint, aobj,atab,arid as
alias, oLegit as object, lExists as logical
if not istableopen("testobjects") then open table "f:\temp\testobjects" as testobjects end if reci = 1 fetch first from testobjects 'testobjects has row1 record ok, deleted object; row 2 deleted; row 3 rec, obj ok atab = "testobjects"
aobj = atab + ".obj"
while not eot(testobjects)
fetch next from testobjects
arid = atab + ".rowid" reci = arid wend '------------------------------------------------------------------------------ Function IsObject (ochk as object) as
logical
Dim o1 as object
onerror goto errhandler o1 = ochk
IsObject = true Exit Function
ErrHandler:
IsObject = False End Function
'------------------------------------------------------------------------------
'If this function were to accept the
table alias variable
'instead of a string, it fails on the
line aobj = atabnm + ".obj"
' in an unexpected manner ("could not
convert data")!!!
Function IsObjectT (byval tabnm as String) as
logical
Dim o1 as object, aObj as alias, sobj as
string
onerror goto errhandler aObj = tabnm + ".obj"
o1 = aObj sobj = str$(o1) 'use obj var in _expression_ tests validity! IsObjectT = true 'obj is ok at this point Exit Function
ErrHandler:
IsObjectT = False ' print "IsObjectT error: " + error$() dont really want to know End Function
Phil Waight.
_______________________________________
|
_______________________________________________ MapInfo-L mailing list MapInfo-L@lists.directionsmag.com http://www.directionsmag.com/mailman/listinfo/mapinfo-l