Creating Instances of Classes with the Class Browser

See Also

You can easily create instances of classes displayed in the Class Browser.

To create an instance of a class

  1. Open the class library or form in the Class Browser.

  2. In the Class list, select the class or form you want to create an instance of.

  3. Drag the Class Move icon from beside the Type list and drop it on the main Visual FoxPro window.

If you drop a form or form class on the main Visual FoxPro window, the form is created and displayed. If you drop a control on the main Visual FoxPro window, the control is added to the _SCREEN object. If you hold the SHIFT key down during the drag operation, the object is created but not made visible. To suppress error messages generated when you create instances, hold the CTRL key down during the drag operation.

You can also drop the Class Move icon in the Command window so you can execute the appropriate NEWOBJECT or CREATEOBJECT code to instantiate the class.

Note When you create an instance of a class, the code in the Init event, and possibly other events, runs. You need to know what code is associated with your classes before creating an instance. If the class requires a particular environment that has not been set up, Visual FoxPro will generate errors. The Class Browser does not provide error handling for user-defined classes.

To remove an object from the _SCREEN object

For example, if you drag the VCR class from ...\Samples\Vfp98\classes\buttons.vcx and drop it on the form, the following line of code in the Command window removes it:

_SCREEN.RemoveObject("VCR1")