WeakRef

From Xojo Documentation

Revision as of 18:56, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Description

Allows you to retain a reference to an object without requiring it to stay alive.


Super Class

Object

Properties

Name Type Description
Value Object Returns the target object or Nil if the target no longer exists.


Constructors

Name Parameters Description
WeakRef obj as Object The target object that you want to retain a reference to after it has been destroyed.


Notes

WeakRef is useful when you want to find out when an object (such as a database or TCP/IP connection) is still in use somewhere in the application. The reference returned by WeakRef goes to Nil as soon as there are no longer any references to the object. This is the signal that you can do any necessary cleanup work.

When the object is destroyed, the WeakRef's value will change to Nil after all ordinary references have been released and the object has been destroyed. Otherwise, the Value property returns the target object.


Examples

This example creates a weak reference to a REALSQLdatabase object. The property db as REALSQLdatabase is a property of the App class.

Dim DBRef as WeakRef
  
// Create Database Object
DBRef=New WeakRef(OrdersDB)
  // Set Database File
OrdersDB.databaseFile = GetFolderItem("Orders.rsd")