Microsoft KB Archive/142885

= How to Add the Data Environment to a Form Programmatically =

Article ID: 142885

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q142885



SUMMARY
When a form is created using the Form Designer, a DataEnvironment object is automatically added to the form. To simulate this behavior in a programmatically created form, a DataEnvironment property must be declared for the form. Then a pointer to a DataEnvironment object may be stored in the form's DataEnvironment property.



MORE INFORMATION
  Create a new program and type the following code: oform1=CREATEOBJECT("Myform") && Instantiate the form oform1.SHOW(0) oform1.refresh READ EVENTS RETURN

DEFINE CLASS Data1 AS dataenvironment  && DataEnvironment Class Name = "Dataenvironment" ADD OBJECT "Cursor1" AS MyCursor     && ADD OBJECT for each ENDDEFINE                              && cursor in dataenvironment

DEFINE CLASS MyCursor AS cursor        && Cursor Class Alias = "customer" Database = "C:\vfp\samples\data\testdata.dbc" CursorSource = "customer" Name = "Cursor1" ENDDEFINE

DEFINE CLASS Myform AS form Top = 0 Left = 0 Height = 386 Width = 587 DoCreate = .T.    Caption = "Form1" Name = "FORM1" DataEnvironment=""               && DataEnvironment is a property && of the form. PROCEDURE Destroy WAIT WINDOW PROGRAM TIMEOUT 2 THISFORM.DATAENVIRONMENT.CLOSETABLES && Close tables at the end ENDPROC                                && of destroy procedure.

PROCEDURE Unload CLEAR EVENTS ENDPROC

PROCEDURE Load * The DataEnvironment is instantiated and the form property * DataEnvironment references the object. The DataEnvironment * is never actually added to the form. THISFORM.DATAENVIRONMENT * is just a pointer to the DataEnvironment object.

THISFORM.DATAENVIRONMENT=CREATEOBJECT("Data1")

* Open the tables at the beginning of the LOAD. THISFORM.DATAENVIRONMENT.OPENTABLES

WAIT WINDOW PROGRAM TIMEOUT 2 ENDPROC ENDDEFINE  Open the Debug window.  Type the following on the left side of the debug window _SCREEN.ACTIVEFORM.DATAENVIRONMENT.NAME  Run the program created in step 1. Note that the debug window correctly displays Dataenvironment as the value of _SCREEN.ACTIVEFORM.DATAENVIRONMENT.NAME

Additional query words: VFoxWin

Keywords: kbcode KB142885

-

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

© Microsoft Corporation. All rights reserved.