main logo
Subject: Re: Single instance forms?
Author: Ed Leafe
Posted: 2002/10/08 07:27:05
 
View Entire Thread
New Search


<i><font color="#663300">CB seems to very nicely handle multiple instances of a form, but what if I *don't* want to allow a form to have multiple instances? How do I stop it please?</font></i>

Add code to the Init() that will check for existing instances of that form class. Something like:

<code> LOCAL laInst[1]
IF AINSTANCES(laInst, This.Class) > 0
RETURN .F.
ENDIF
</code>
Since this is a function that is probably needed for many form classes, it would probably be best to add it to your a superclass for your form (such as iBaseForm). I'd then add a property named <b>lSingleton</b>, defaulting to .F., Then, any class you want to exhibit this Singleton pattern can be set by switching that property to .T. The code would then look like:

<code> LOCAL laInst[1]
IF This.lSingleton
IF AINSTANCES(laInst, This.Class) > 0
RETURN .F.
ENDIF
ENDIF
</code>
<font color="#cc0000"> ___/
/
__/
/
____/</font>
Ed Leafe
 
©2002 Ed Leafe
<-- Prior Message New Search Next Message -->