Saving Programmatically-Created Form & Data Environment to SCX

Last reviewed: January 9, 1996
Article ID: Q139912
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

When creating a form programmatically, you may want to add a data environment to the form. This article illustrates one method you can use to create a form and add a data environment to that form programmatically.

MORE INFORMATION

When you create a form programmatically, the DataEnvironment property cannot be used to pass a table to the form because it is a read-only property. Therefore, to add a data environment to a form programmatically, you must create the data environment object separately during the creation of the form. Then, you must use the SaveAs method to save both the form and the data environment in the new form (.scx) file. The following code illustrates this technique.

Code Sample

*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

     BEGIN CODE SEGMENT
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

SET DEFAULT TO C:\VFP\SAMPLES\DATA

oMyForm1=CREATEOBJECT('Form') oMyDE1 =CREATEOBJECT('DataEnvironment')

oMyDE1.ADDOBJECT('Curs1', 'Cursor') oMyDE1.Curs1.DataBase='TESTDATA.DBC' oMyDE1.Curs1.CursorSource='Customer'

oMyForm1.ADDOBJECT('Txt1', 'TextBox') oMyForm1.Txt1.ControlSource='Customer_ID' oMyForm1.Txt1.Visible=.T.

*-- You can add as many objects as you want. *-- Use the form's SaveAs method to save everything *-- to an .scx File. This is actually how the DE *-- is associated to the form.

oMyForm1.SaveAs('MyForm2', oMyDE1)

*-- Note that the second parameter specifies the *-- associated Data Environment

RELEASE oMyForm1

DO FORM MyForm2

*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

     END CODE SEGMENT
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

You can also use the following command to open the form in design mode:

   MODIFY FORM MyForm2


Additional reference words: 3.00 VFoxWin
KBCategory: kbprg kbhowto kbcode
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.