How to Find Out If an Object Is in a Container or NotLast reviewed: August 10, 1995Article ID: Q134621 |
The information in this article applies to:
SUMMARYThis article describes how to use the TYPE() function to find out whether or not an object is contained in another object.
MORE INFORMATIONIt is sometimes necessary to know if an object is in a container, and perform an action according to the way an instance of the object is created. For example, a form can be placed on the desktop or in a formset, and the program can perform different tasks depending on the container. The Parent property of an object references the container object of a control. Use the TYPE() function to determine if an object has a parent. For example:
IF TYPE ('This.Parent')= "0" && The object has a container ? This.Parent.Name ENDIFThe following example illustrates this method using a command button. If the control is placed in a toolbar, the Visible property of the toolbar is set to false (.F.) when the button is released. To run this example, copy and paste the code into a program (.PRG) file. When the toolbar is displayed, click the Close button. The toolbar is hidden before it is released.
Sample CodePUBLIC oTB1,oFrm1 && Define public variables oTb1=CREATE('tbmytool') && Create an instance of the toolbar object oTb1.SHOW oFrm1=CREATE('Frmmyform') && Create an instance of the form object oFrm1.SHOW DEFINE CLASS cmdQuit AS COMMANDBUTTON PROCEDURE CLICK RELEASE THISFORM && Release either the form or the toolbar ENDPROC PROCEDURE DESTROY && Called when the object is released IF TYPE('This.parent')="O" IF THIS.PARENT.BASECLASS="Toolbar" THIS.PARENT.VISIBLE = .F. && Hides the toolbar =MESSAGEBOX('Toolbar is hidden') ENDIF ENDIF ENDPROCENDDEFINE DEFINE CLASS tbMyTool AS TOOLBAR ADD OBJECT cmdNew AS COMMANDBUTTON ADD OBJECT cmdClose AS cmdQuitENDDEFINE DEFINE CLASS frmmyform AS FORM ADD OBJECT cmdForm AS cmdQuitENDDEFINE
|
Additional reference words: VFoxWin 3.00 form set
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |