如何将编程方式创建表单中的表格与数据源关联
*下列代码, 建立一个表单, 并用 g rid1 显示 customer 表中的数据Public FORM1
Form1=CREATEOBJECT('form1') && 实例化表单
Form1.show()
READ EVENTS
DEFINE CLASS form1 AS form
Top = 90
Left = 294
Height = 500
Width = 800
Docreate=.T.
Name='form1'
Caption='添加数据环境'
DataEnvironment =0 && DataEnvironment 是表单的一个属性
Procedure load
thisform.DataEnvironment=CREATEOBJECT('data1') && 实例化DataEnv ironment
Thisform.DataEnvironment.opentables && 打开表
ENDPROC
PROCEDURE Init
this.AddObject("grid1","Mygrid")
this.AddObject("Command1","MyCommand")
ENDPROC
Procedure destroy
Thisform.DataEnvironment.closetables && 关闭表
ENDPROC
Procedure unload
Clear events
ENDPROC
Enddefine
Define CLASS Mygrid AS grid
Name='Mygrid'
Visible=.T.
Top = 60
Left = 150
Width = 500
Height = 300
RecordsourceType= 1
Recordsource='customer'
ENDDEFINE
Define class data1 AS dataenvironment && 数据环境类
Name='dataenvironment'
Add object cursor1 AS mycursor && 为数据环境中添加临时表
Enddefine
Define CLASS mycursor as cursor && 添加cursor 类对象
Alias='curstomer'
Database='d:\testdata.dbc'
Cursorsource='curstomer' && 指向的表
Name='cursor1'
ENDDEFINE
DEFINE CLASS MyCommand AS commandbutton
Visible=.T.
Top = 410
Left = 530
Height = 25
Width = 60
AutoSize = .T.
FontSize = 11
Caption = "返回"
Name = "Command1"
PROCEDURE Click
thisform.release
ENDPROC
ENDDEFINE
运行报错误提示如下:
初始化临时表对象时发生错误,在 curstomer 中找不到 d:\testdata.dbc 但是硬盘里面有 d:\testdata.dbc 文件
,点击“取消”按钮后,“Thisform.DataEnvironment.opentables && 打开表”错误,点击“忽略”按钮后,表单上表格是空白的,请问下该怎么解决?如果不用数据库文件 testdata.dbc 而是用一个自由表 testdata.dbf 又该怎么写啊?