| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1226 人关注过本帖
标题:表单事件方法
只看楼主 加入收藏
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
回复 20楼 sam_jiang
表单变量.rar (2.84 KB)

2023-08-29 20:43
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
增加了代码
图片附件: 游客没有浏览图片的权限,请 登录注册
2023-08-29 20:46
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
回复 17楼 sam_jiang
文件已上传,现在变量能引用过来了。我取消了this.parent.click,也能成功引用,不懂其中的道理。请你指点一下,label4的赋值没有成功的原因。谢谢你!
2023-08-29 20:53
laowan001
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:66
帖 子:1089
专家分:2682
注 册:2015-12-30
收藏
得分:0 
以下是引用tjdeming在2023-8-29 15:21:52的发言:

谢谢你!变量没有引用过来


不能够啊,page1.click 这样试下
messagebox(ntext)
2023-08-30 11:02
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:15 
以下是引用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编辑过]

2023-08-30 13:12
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
回复 25楼 sam_jiang
程序代码:
**************************************************
*-- Form:         form1 (d:\documents\visual foxpro 项目\表单变量\表单1.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   08/29/23 08:38:00 PM
*

PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


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 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 =
        PUBLIC nText,ST,ET
        *!* public 声明的变量要释放,不然表单关闭了,它们依然存在。
        * nText=0
         nText= thisform.TEXT1.value &&此值本来就是0,跟上一句是重复的
        st =  = ** 注意到你对3个变量赋值
    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
         ThisForm.Refresh
    ENDPROC


    PROCEDURE pageframe1.Page3.Click
      *  this.parent.click()
        thisform.pageframe1.page3.caption=ET
         ThisForm.Refresh
    ENDPROC


    PROCEDURE pageframe1.Page4.Click
      * this.parent.click
        thisform.pageframe1.page4.caption=ET+ST
         ThisForm.Refresh
    ENDPROC


*!*        PROCEDURE text1.LostFocus
*!*            thisform.label4.caption=str(ntext)
*!*            ThisForm.Refresh
*!*        ENDPROC


    PROCEDURE command1.Click
        **退出前释放public申明过的变量
        CLEAR MEMORY    
        clear
        quit
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************

非常感谢!!!
晚上弄了很长时间,总算能运行了。主要是想学习下变量的引用,简化语句。

*!*退出前释放public申明过的变量
        CLEAR MEMORY 这样写对不对?   
2023-08-30 20:27
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
clear memory 可以的。

release all也可以。
2023-08-30 20:44
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
在表单中增加了一个命令按钮后:
 PROCEDURE command2.Click
        if ntext<>0   &&&提示找不到(ntext)变量
        (str(ntext))  
       endif
     
  ENDPROC
问题在哪儿?
程序代码:
 PROCEDURE command2.Click
if ntext<>0   &&&提示找不到(ntext)变量
     =allt(str(ntext)) 
  endif
ENDPROC



[此贴子已经被作者于2023-8-30 20:56编辑过]

2023-08-30 20:49
tjdeming
Rank: 2
等 级:论坛游民
帖 子:429
专家分:54
注 册:2013-3-4
收藏
得分:0 
回复 27楼 sam_jiang
好!谢谢你。
图片附件: 游客没有浏览图片的权限,请 登录注册


[此贴子已经被作者于2023-8-30 21:00编辑过]

2023-08-30 20:50
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:789
专家分:1165
注 册:2021-10-13
收藏
得分:0 
判断变量存在与否有专门的函数的。

if type([ntext])="U" && vartype(ntext)="U"
    return .f.
else
    *!* your code here
endif
2023-08-31 15:36
快速回复:表单事件方法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050214 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved