The information in this article applies to:
- Microsoft Visual FoxPro for Windows, version 5.0
SYMPTOMS
A code snippet exported by the Class Browser generates a syntax error if
the code uses the ADD OBJECT command to add an object to a container object
in a class. It appears that the Class Browser exported the code
incorrectly. In fact, Visual FoxPro has a language limitation that does not
allow the ADD OBJECT command to add an object to a container object in a
class definition.
CAUSE
Even though the Class Browser cannot produce actual working code in this
situation, it documents the intent of the class rather than omit the code
altogether.
STATUS
This behavior is by design.
MORE INFORMATION
You can use the Class Browser to export code from within a class. Code
exported may be incorporated in a program or it may just be used for the
purpose of documentation.
The Class Browser designers decided it would be helpful to document code
even though it cannot work because of a language limitation of Visual
FoxPro. While the code does not work, the Class Browser describes in code
what the developer achieved through the visual user interface.
Steps to Reproduce Behavior
- In Visual FoxPro click New on the File menu and click the Form button to
start the form designer.
- Click Create Formset on the Form menu. In the Properties sheet for the
formset, change the name property to "Testfrm1" (without the quotes).
- Click the Command Button tool on the Form Control toolbar, and
click on the middle of the form to place the command button on the form.
- Set the following properties for the command button:
Top = 51
Left = 112
Height = 32
Width = 140
This step is optional, but it establishes the values shown in this
example.
- Click Save as class on the File menu. In the Save As Class dialog box
click the "Entire Form Set" option button, and name the class "Testfrm1"
and the class library "testfrm1.vcx."
- Close the Form Designer. Save the form as Testfrm1.scx.
- Select Class Browser on the Tools menu.
- In the Class Browser Opening dialog box select your class library:
Testfrm1.vcx
- Click the line "testfrm1.vcx."
- Click the "View Code" button (the third button from the left).
- Click "Select All" on the Edit menu, then select "Copy" from the Edit
menu to put the code in the Clipboard.
- Close the Class Browser, and in the Command window type the following:
MODIFY COMMAND Testfrm1
- Paste the code from the Clipboard into Testfrm1.prg.
- At the top of the code insert the following commands:
PUBLIC oformset1
oformset1=CREATEOBJECT("formset1")
oformset1.Show()
RETURN
The entire program should look like the following:
PUBLIC oformset1
oformset1=CREATEOBJECT("testfrm1")
oformset1.Show()
RETURN
**************************************************
*-- Formset: testfrm1 (c:\VFP50\testfrm1.vcx)
*-- ParentClass: formset
*-- BaseClass: formset
*
DEFINE CLASS testfrm1 AS formset
DataSession = 1
AutoRelease = .T.
Name = "Testfrm1"
ADD OBJECT form1 AS form WITH ;
DoCreate = .T., ;
Caption = "Form1", ;
Name = "Form1"
ADD OBJECT testfrm1.form1.command1 AS commandbutton WITH ;
Top = 51, ;
Left = 112, ;
Height = 32, ;
Width = 140, ;
Caption = "Command1", ;
Name = "Command1"
ENDDEFINE
*
*-- EndDefine: testfrm1
**************************************************
- Save and run the program Testfrm1.prg.
The program stops with the following error:
Syntax error
The following line is highlighted:
ADD OBJECT testfrm1.form1.command1 AS commandbutton WITH ;