FoxPro,如何在类中定义的过程中访问对象?

时间:2013-10-13 14:49:07

标签: foxpro visual-foxpro

我想通过单击按钮来构建查询到db从texbox中获取参数。 有这样的课程定义:

DEFINE CLASS myForm as Form
Height = 200
Width = 300
visible = .t.
ADD OBJECT insertBut AS COMMANDBUTTON;
WITH Caption = "insert", width = 70, height = 20, top = 165, left = 10

ADD OBJECT lbl1 as label WITH caption = 'Title', left = 10, top = 10
ADD OBJECT text1 AS TEXTBOX WITH left = 10, top = 25
ADD OBJECT lbl2 as label WITH caption = 'Amount', left = 10, top = 45
ADD OBJECT text2 as textbox WITH left = 10, top = 60
ADD OBJECT lbl3 as label WITH caption = 'Price', left = 10, top = 80
ADD OBJECT text3 as textbox WITH left = 10, top = 95
ADD OBJECT lbl4 as label WITH caption = 'Manufacturer id', left = 10, top = 115
ADD OBJECT text4 as textbox WITH left = 10, top = 130

ADD OBJECT lbl5 as label WITH caption = 'Id', left = 120, top = 10
ADD OBJECT text5 as textbox WITH left = 120, top = 25

PROCEDURE insertBut.click
    USE stock
    INSERT INTO stock (title, price, amount, man_id) values(text1.text, text3.text, text2.text, text4.text)
    browse
ENDPROC

ENDDEFINE

和我通过命令行调用的程序

PROCEDURE tform
t = CREATEOBJECT("myform")
t.show
READ events
return
ENDPROC

点击按钮后插入但我收到错误“找不到别名TEXT1”。我做错了什么?

1 个答案:

答案 0 :(得分:3)

insertBut.clickmyForm.insertBut的上下文中运行,而不是myForm,其中text1等。

您需要使用THISFORM为表单的其他对象添加前缀。


更好的解决方案,btw,是将文本框数据绑定到游标或数据对象,以便更好地分离关注点。您可以在类描述中显式添加自定义对象,也可以直接启动或创建游标。

stock的{​​{1}}方法上打开或检查Init光标,然后在创建时设置每个控件的myForm属性。例如:

dataSource