Adding Objects to a Container Class
Visual FoxPro 9.0 SP2 |
Adding Objects to a Container Class |
See Also |
![]() |
You can use the ADD OBJECT clause in the DEFINE CLASS command or the AddObject method to add objects to a container.
For example, the following class definition is based on a form. The ADD OBJECT command adds two command buttons to the form:
![]() | |
---|---|
DEFINE CLASS myform AS FORM ADD OBJECT cmdOK AS COMMANDBUTTON ADD OBJECT PROTECTED cmdCancel AS COMMANDBUTTON ENDDEFINE |
Use the AddObject method to add objects to a container after the container object has been created. For example, the following lines of code create a form object and add two command buttons to it:
![]() | |
---|---|
frmMessage = CREATEOBJECT("FORM") frmMessage.AddObject("txt1", "TEXTBOX") frmMessage.AddObject("txt2", "TEXTBOX") |
You can also use the AddObject method in the method code of a class. For example, the following class definition uses AddObject in the code associated with the Init event to add a control to a grid column.
![]() | |
---|---|
DEFINE CLASS mygrid AS GRID ColumnCount = 3 PROCEDURE Init THIS.Column2.AddObject("cboClient", "COMBOBOX") THIS.Column2.CurrentControl = "cboClient" ENDPROC ENDDEFINE |
Adding and Creating Classes in Method Code
See Also
© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic