This sample demonstrates how to use the Pool Manager class, which manages a pool or collection of objects from a class and is useful when you need to use objects repeatedly for a short amount of time.
This sample contains the following classes.
Manages a pool, or collection, of objects from a single class.
In this sample, forms are collected in a pool so that you can reuse any form that is available in the pool instead of having to create a new form when you select a customer from the drop-down list.
To use the Pool Manager class in this sample, the following Pool Manager class properties must be set in the Properties window:
cClassВ В В = frmCustomer
cClassLibrary = frmCustomer.vcx
Binding to Pool Manager Events
You can bind to _PoolManager events. In this sample, the form's Init event contains code that binds the form's custom handler methods, PoolManager_ObjectRequested and PoolManager_ObjectReturned, to the _PoolManager ObjectRequested and ObjectReturned events so that status can be reported on the sample form:
To request an object from the pool, call the _PoolManager Get method.
To open a customer form in this sample
Select a customer name from the drop-down list.
Click View Customer.
You can open multiple forms by clicking View Customer repeatedly, which requests a form object from the Pool Manager class each time. The form's custom ViewCustomer method contains the following code:
loForm = ThisForm.PoolManager.Get(m.lcCustID) If Vartype(m.loForm) == "O" loForm.Show() EndIf
In this sample, the Get method returns an unused object that exists in the pool or creates a new object. When a new customer form is created, code in the form's Init event binds to the _PoolManager ObjectRequested and ObjectReturned methods using the private variable
THISPOOLMANAGER created in the Get method:
This event binding makes it possible for the form to call its Hide method instead of the Release method so the form returns to the pool instead of being destroyed.
To return objects to the pool, call the _PoolManager Free method. In this sample, the form's QueryUnload event occurs when the customer form is closed and returns the form to the pool:
If Vartype(This.oPoolManager) == "O" This.oPoolManager.Free(This) NoDefault EndIf