WeakObjectExists (open)

Checks if a weak object reference exists

Syntax

// Core function, no LOADLIB necessary

BOOLEAN FUNCTION WeakObjectExists(WEAKOBJECT obj)

Parameters

WEAKOBJECT obj

Weak object reference to check

Return value

BOOLEAN

Returns TRUE if the weak object reference exists

Description

This function is useful to check if the weak reference still references an existing object. However, the reference can disappear at any time, so a positive result is no proof that the object still appears immediately after the test. Use this function only to see if the object instance has disappeared.

Examples

OBJECT o := NEW Exception;
WEAKOBJECT w := WEAKOBJECT(o);

IF (WeakObjectExists(w))
{
  Print('Yes, it exists' );

  // This might fail, even if WeakObjectExists(w) returned TRUE before
  OBJECT strongref := OBJECT(w);
}

// Safer way to use the reference from a WEAKOBJECT
OBJECT strongref2 := OBJECT(w);
IF (ObjectExists(strongref2))
  Print('Yes, it exists' );