以下是引用tjdeming在2023-8-29 20:53:30的发言:
文件已上传,现在变量能引用过来了。我取消了this.parent.click,也能成功引用,不懂其中的道理。请你指点一下,label4的赋值没有成功的原因。谢谢你!
说实话不知道你要完成什么任务,只是要传递那3个值给page的caption?
**************************************************
*-- Form: form1 (d:\documents\visual foxpro 项目\表单变量\表单1.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 08/29/23 08:38:00 PM
*
DEFINE CLASS form1 AS form
Top = 88
Left = 85
Height = 329
Width = 509
DoCreate = .T.
Caption = "Form1"
Name = "Form1"
ADD OBJECT pageframe1 AS pageframe WITH ;
ErasePage = .T., ;
PageCount = 4, ;
Top = 108, ;
Left = 36, ;
Width = 444, ;
Height = 204, ;
Name = "Pageframe1", ;
Page1.Caption = "Page1", ;
Page1.Name = "Page1", ;
Page2.Caption = "Page2", ;
Page2.Name = "Page2", ;
Page3.Caption = "Page3", ;
Page3.Name = "Page3", ;
Page4.Caption = "Page4", ;
Page4.Name = "Page4"
ADD OBJECT text1 AS textbox WITH ;
Alignment = 3, ;
Value = 0, ;
Height = 25, ;
InputMask = "", ;
Left = 97, ;
Top = 12, ;
Width = 96, ;
Name = "Text1"
ADD OBJECT label1 AS label WITH ;
AutoSize = .T., ;
Caption = "输入编号", ;
Height = 16, ;
Left = 24, ;
Top = 20, ;
Width = 50, ;
Name = "Label1"
ADD OBJECT combo1 AS combobox WITH ;
RowSourceType = 1, ;
RowSource = "202301,202302,202303,202304,202305,202306,202307,202308,202309,202310,202311,202312", ;
Height = 25, ;
Left = 96, ;
Top = 60, ;
Width = 97, ;
Name = "Combo1"
ADD OBJECT combo2 AS combobox WITH ;
RowSourceType = 1, ;
RowSource = "202301,202302,202303,202304,202305,202306,202307,202308,202309,202310,202311,202312", ;
Height = 25, ;
Left = 276, ;
Top = 60, ;
Width = 97, ;
Name = "Combo2"
ADD OBJECT grid1 AS grid WITH ;
ColumnCount = 3, ;
Height = 144, ;
Left = 72, ;
RecordSource = "表1", ;
RecordSourceType = 1, ;
Top = 144, ;
Width = 336, ;
Name = "Grid1", ;
Column1.ControlSource = "表1.num", ;
Column1.Width = 62, ;
Column1.Name = "Column1", ;
Column2.ControlSource = "表1.ny", ;
Column2.Width = 62, ;
Column2.Name = "Column2", ;
Column3.ControlSource = "表1.hj", ;
Column3.Width = 62, ;
Column3.Name = "Column3"
ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
Caption = "Num", ;
Name = "Header1"
ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
BorderStyle = 0, ;
Margin = 0, ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT form1.grid1.column2.header1 AS header WITH ;
Caption = "Ny", ;
Name = "Header1"
ADD OBJECT form1.grid1.column2.text1 AS textbox WITH ;
BorderStyle = 0, ;
Margin = 0, ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT form1.grid1.column3.header1 AS header WITH ;
Caption = "Hj", ;
Name = "Header1"
ADD OBJECT form1.grid1.column3.text1 AS textbox WITH ;
BorderStyle = 0, ;
Margin = 0, ;
ForeColor = RGB(0,0,0), ;
BackColor = RGB(255,255,255), ;
Name = "Text1"
ADD OBJECT label2 AS label WITH ;
Caption = "起始时间", ;
Height = 13, ;
Left = 24, ;
Top = 65, ;
Width = 61, ;
Name = "Label2"
ADD OBJECT label3 AS label WITH ;
Caption = "终止时间", ;
Height = 13, ;
Left = 204, ;
Top = 65, ;
Width = 61, ;
Name = "Label3"
ADD OBJECT command1 AS commandbutton WITH ;
Top = 36, ;
Left = 432, ;
Height = 25, ;
Width = 61, ;
Caption = "关闭", ;
Name = "Command1"
ADD OBJECT label4 AS label WITH ;
Caption = "Label4", ;
Height = 25, ;
Left = 240, ;
Top = 12, ;
Width = 157, ;
Name = "Label4"
PROCEDURE Activate
PUBLIC nText,ST,ET
*!* public 声明的变量要释放,不然表单关闭了,它们依然存在。
nText=0
nText= thisform.TEXT1.value
&&此值本来就是0,跟上一句是重复的
st =
&&此时值为空
et =
&&此时值为空
*!* 注意到你对3个变量赋值
ENDPROC
PROCEDURE pageframe1.Click
*!* 不明白为什么又要再赋值一次,如果要赋值,那么上面activate事件就是多余的。
nText = thisform.text1.value
st =
et =
ENDPROC
PROCEDURE pageframe1.Page1.Click
*this.parent.click
thisform.pageframe1.page1.caption=STR(NTEXT)
ThisForm.Refresh
ENDPROC
PROCEDURE pageframe1.Page2.Click
*this.parent.click
thisform.pageframe1.page2.caption=st
ENDPROC
PROCEDURE pageframe1.Page3.Click
*this.parent.click
thisform.pageframe1.page3.caption=ET
ENDPROC
PROCEDURE pageframe1.Page4.Click
*this.parent.click
thisform.pageframe1.page4.caption=ET+ST
ENDPROC
PROCEDURE text1.LostFocus
thisform.label4.caption=str(ntext)
ThisForm.Refresh
ENDPROC
PROCEDURE command1.Click
*!*退出前释放public申明过的变量
quit
ENDPROC
ENDDEFINE
*
*-- EndDefine: form1
**************************************************
猜想你是想用这3个变量作为每个page的caption,
那么你可以直接这样写:
pageframe1.Click里代码:
this.page1.caption = transf(thisform.text1.value) &&修改一下
this.page2.caption =
this.page3.caption =
this.page4.caption =
每个page的click代码只有一句:
this.parent.click()
activate 事件的代码可以不用了。
label4的赋值没有成功的原因是,你在textbox的lostfocus事件里赋值的,它没有得到焦点自然也就不会触发lostfocus。
这样解决你的困惑没有呢??
[此贴子已经被作者于2023-8-30 13:19编辑过]