>I have a form class I have been using for data input for reports (dates, etc.). It is subclassed from my form base class. I instanciate this class in code using newobject..., set some properties, show the form (modal), grab the info I need from form properties and release the form.
>
>I added some code in the load of the base class that referenced the data environment. Forms that I design using this class run fine. However, the subclassed form won't run (instanciated from code). The error says 'Unknown member dataenvironment'. I'm assuming that it's because the DE doesn't exist yet? When does the DE get created? Do I need to base my subclass on a class that doesn't have the DE code in the load event?
A form class doesn't have a DateEnvironment. If you open your class and then right click you'll see that there isn't the DE option you have in an SCX. You would want to add one during instantiation.
Here is an example.
CREATE TABLE TEMP (c1 C(10))
INSERT INTO TEMP (c1) VALUES ("FOO")
INSERT INTO TEMP (c1) VALUES ("BAR")
GO TOP IN TEMP
LOCAL ox
ox = NEWOBJECT("MyForm")
ox.SHOW(1)
DEFINE CLASS MyDE AS DATAENVIRONMENT
ADD OBJECT TEMP AS CURSOR WITH ;
ALIAS = "TEMP", ;
CURSORSOURCE = "C:\TEMP\TEMP.DBF"
ENDDEFINE
DEFINE CLASS MyForm AS FORM
DATAENVIRONMENT = .NULL.
PROCEDURE LOAD
THIS.DATAENVIRONMENT = NEWOBJECT("DataEnvironment" )
THIS.DATAENVIRONMENT.OPENTABLES()
ENDPROC
PROCEDURE INIT
THIS.ADDOBJECT("Grid1", "Grid")
THIS.Grid1.RECORDSOURCE = "Temp"
THIS.Grid1.VISIBLE = .T.
ENDPROC
PROCEDURE UNLOAD
THIS.DATAENVIRONMENT = .NULL.
ENDPROC
ENDDEFINE