注册 登录
编程论坛 VFP论坛

表单方法事件2

tjdeming 发布于 2023-08-31 20:15, 639 次点击
在运行表单时,点击引用、引用2命令按钮时没有成功,出现了错误。
只有本站会员才能查看附件,请 登录

错误之处请予以指正 不胜感激!
8 回复
#2
schtg2023-09-01 06:25
回复 楼主 tjdeming
你的出现什么错误?我测试是正常的啊
只有本站会员才能查看附件,请 登录
#3
tjdeming2023-09-01 20:22
回复 2楼 schtg
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
是VFP6.0
#4
schtg2023-09-01 20:31
回复 3楼 tjdeming
你的变量赋值在此处
只有本站会员才能查看附件,请 登录

应该是先单击 pageframe1之后才单击“引用”或“引用2”。
若不单击pageframe1就可以的话,需要更换赋值位置,或更换赋值来源哈。

[此贴子已经被作者于2023-9-1 20:37编辑过]

#5
sam_jiang2023-09-01 20:46
回复 4楼 schtg
改在表单的init事件中赋值吧。。。
#6
tjdeming2023-09-02 21:13
回复 5楼 sam_jiang
公有变量放在了表单INIT了,原出现的错误没解决,还增加了单击页框时显示空白了
TEXT1是数据型二个组合框也是数据型,VFP6.0. 搞了二个晚上没有解决问题。求助一下。谢谢你!
程序代码:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
    Top = 88
    Left = 85
    Height = 229
    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 = 104, ;
        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 command2 AS commandbutton WITH ;
        Top = 16, ;
        Left = 332, ;
        Height = 25, ;
        Width = 61, ;
        Caption = "引用", ;
        Name = "Command2"
  
    ADD OBJECT command3 AS commandbutton WITH ;
        Top = 16, ;
        Left = 240, ;
        Height = 25, ;
        Width = 61, ;
        Caption = "引用2", ;
        Name = "Command3"
      
  
    PROCEDURE pageframe1.Click
*!*             PUBLIC nText,ST,ET, RIQI
*!*            *!* public 声明的变量要释放,不然表单关闭了,它们依然存在。
*!*           nText= thisform.TEXT1.value &&此值本来就是0,跟上一句是重复的
*!*            st = *!*            et = *!*            RIQI="J1,J2,J3,J4"
*!*           
*!*             ** 注意到你对3个变量赋值
     ENDPROC

   PROCEDURE INIT
         PUBLIC nText,ST,ET, RIQI
       Text= thisform.TEXT1.value
        st = = ="J1,J2,J3,J4"
      
     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 command2.Click
      =str(ntext)
ENDPROC

PROCEDURE command3.Click
  =RIQI
ENDPROC


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

 ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
#7
sam_jiang2023-09-02 23:29
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form
    Top = 88
    Left = 85
    Height = 229
    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 = 104, ;
        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 command2 AS commandbutton WITH ;
        Top = 16, ;
        Left = 332, ;
        Height = 25, ;
        Width = 61, ;
        Caption = "引用", ;
        Name = "Command2"
  
    ADD OBJECT command3 AS commandbutton WITH ;
        Top = 16, ;
        Left = 240, ;
        Height = 25, ;
        Width = 61, ;
        Caption = "引用2", ;
        Name = "Command3"
      
  
    PROCEDURE pageframe1.Click
*!*             PUBLIC nText,ST,ET, RIQI
*!*            *!* public 声明的变量要释放,不然表单关闭了,它们依然存在。
            nText= thisform.TEXT1.value &&此值本来就是0,跟上一句是重复的
            st =
            et =
            RIQI="J1,J2,J3,J4"
           
             *!* 注意到你对3个变量赋值
     
     ENDPROC

   PROCEDURE INIT
         PUBLIC nText,ST,ET, RIQI
*!*               nText= thisform.TEXT1.value
*!*            st =
*!*            et =
*!*            RIQI="J1,J2,J3,J4"
      
     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 command2.Click
      thisform.pageframe1.click() &&给变量赋值
      (str(ntext))
ENDPROC

PROCEDURE command3.Click
    thisform.pageframe1.click() &&给变量赋值
  
ENDPROC


 PROCEDURE command1.Click
   CLEAR MEMORY *!*退出前释放public申明过的变量
    thisform.release

 ENDPROC


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

多用调试器,可以查看变量的值。。。

[此贴子已经被作者于2023-9-2 23:31编辑过]

#8
sam_jiang2023-09-02 23:44
回复 6楼 tjdeming
[引用]公有变量放在了表单INIT了,原出现的错误没解决,还增加了单击页框时显示空白了
TEXT1是数据型二个组合框也是数据型,VFP6.0. 搞了二个晚上没有解决问题。求助一下。谢谢你!
   

    PROCEDURE pageframe1.Click
*!*这段代码被你注释掉了,也就是说你的4个变量在init中初始化,当你改变form上combo和textbox的值的时候,并没有传给你的4个变量

        在这里给四个变量赋值           
            nText= thisform.TEXT1.value
            st =
            et =
            RIQI="J1,J2,J3,J4"
      

     ENDPROC

   PROCEDURE INIT
         PUBLIC nText,ST,ET, RIQI
  *!*下面四句放在pageframe的click里面吧
   *!*   Text= thisform.TEXT1.value 你这里错了,应该是ntext,而不是text
   *!*      st =
   *!*      et =
   *!*      RIQI="J1,J2,J3,J4"
      
     ENDPROC

PROCEDURE command2.Click
*!* 执行这个事件的时候,并没有对变量进行赋值,所以要调用pageframe的click事件
thisform.pageframe1.click()     
(ntext)
ENDPROC

PROCEDURE command3.Click
*!* 执行这个事件的时候,并没有对变量进行赋值,所以要调用pageframe的click事件
thisform.pageframe1.click()
  
ENDPROC

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


ENDDEFINE
#9
tjdeming2023-09-03 20:16
回复 8楼 sam_jiang
非常感谢你的耐心解答,我修正代码后能实现想要的了
1