Microsoft KB Archive/156506

= PRB: ADD OBJECT Syntax Error from Browser Code Snippet =

Article ID: 156506

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q156506



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 . 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.</li> Select Class Browser on the Tools menu.</li> In the Class Browser Opening dialog box select your class library: Testfrm1.vcx</li> Select "testfrm1.vcx."</li> Click the "View Code" button (the third button from the left).</li> Click "Select All" on the Edit menu, then select "Copy" from the Edit menu to put the code in the Clipboard.</li>  Close the Class Browser, and in the Command window type the following: MODIFY COMMAND Testfrm1 </li> Paste the code from the Clipboard into Testfrm1.prg.</li>  At the top of the code insert the following commands: PUBLIC oformset1 oformset1=CREATEOBJECT("testfrm1") 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 **************************************************                       </li> Save and run the program Testfrm1.prg.</li></ol>

The program stops with the following error:

Syntax error

The following line is highlighted: ADD OBJECT testfrm1.form1.command1 AS commandbutton WITH ;

Keywords: KB156506

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.