| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2604 人关注过本帖
标题:[求助]在记录前/后插入记录
只看楼主 加入收藏
lyxc34
Rank: 2
等 级:论坛游民
帖 子:139
专家分:50
注 册:2011-7-3
收藏
得分:0 
回复 20楼 茵梦湖
请问,你这是用RightClick事件中调用菜单实现的吧,插入的代码是用insert吗?
2011-07-25 20:02
lyxc34
Rank: 2
等 级:论坛游民
帖 子:139
专家分:50
注 册:2011-7-3
收藏
得分:0 
又出问题了,帮忙找下错哈,全用代码写表单和控件不容易啊。
程序代码:
form_Stu = CREATEOBJECT("_Stu")
form_Stu.Show
READ EVENTS
RETURN

DEFINE CLASS _Stu AS Form
    AutoCenter=.T.
    BackColor=RGB(181,221,243)
    BorderStyle=0
    Caption = "学生信息管理"
    Height=600
    MaxButton=.F.
    ShowWindow=2
    Width=800
    WindowState = 0
    ADD OBJECT XskGrid AS grid
    ADD OBJECT Sp as Shape WITH;
      Anchor = 240
      BackStyle = 0
      Height = 30
      Width = 200
      Left = (thisform.Width-this.Width)/2
      Top = 10
    ADD OBJECT Lb as Label WITH;
      Alignment = 2
      Anchor = 240
      AutoSize = .T.
      BackStyle = 0
      Caption = "学生信息管理"
      FontBold = .T.
      FontSize = 12
      Height = 20
      Left = (thisform.Width-this.Width)/2
      Top = 10
    ADD OBJECT Img1 as Image WITH;
      BackStyle = 0
      Height = 16
      Width = 16
      Left = thisform.Width-40
      Top = 10
    ADD OBJECT Img2 as Image WITH;
      BackStyle = 0
      Height = 16
      Width = 16
      Left = thisform.Width-20
      Top = 10    
    PROCEDURE Load
        USE h:\vfp\data\tables\xsk ORDER xh IN 0
    ENDPROC
    PROCEDURE Arrange
         WITH This.XskGrid
             .RecordMark = .F.
             .Top = 50
             .Left = 5
             .Height = This.Height - .Top - 5     &&报错在这里,说表达式计算结果为一非法值。如果把ADD OBJECT Sp as Shape
             .Width = This.Width - .Left - 5      &&到ADD OBJECT Img2 as Image这几段代码去掉就不会报错。
         ENDWITH
         WITH This.Img1.Click
             thisform.XskGrid.AllowCellSelection= .F. 
         ENDWITH
         WITH This.Img2.Click
             thisform.XskGrid.AllowCellSelection= .T. 
             thisform.Release
         ENDWITH
    ENDPROC 
    
    PROCEDURE Activate
         This.Arrange         
     ENDPROC 
    
    PROCEDURE Resize
         This.Arrange
    ENDPROC
        
    PROCEDURE Unload
        CLEAR EVENTS
        CLOSE TABLES ALL
    ENDPROC

ENDDEFINE
2011-07-25 20:08
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
回复 22楼 lyxc34
既然在Arrange過程計算控件的寬高,就不用在前面給它們定值了,只給出窗體的尺寸即可。另:這裡使用Arrange模式,已經取代Anchor功能,你Anchor了,再計算時就會出現負值。

只有到Activate事件,窗體的尺寸才會穩定下來,此時再取ThisForm.Height就得到真實的窗體高度,用這個真實高度來計算才對,在Init階段,窗體的高度是隨機的。你綁定的Anchor值,如果是絕對參考,再運算就可能出錯。有Arrange功能,就不需用Anchor了,那時VFP9才有的,但我這種是在VFP6也能實現的。

[ 本帖最后由 TonyDeng 于 2011-7-25 20:19 编辑 ]

授人以渔,不授人以鱼。
2011-07-25 20:13
lyxc34
Rank: 2
等 级:论坛游民
帖 子:139
专家分:50
注 册:2011-7-3
收藏
得分:0 
Arrange里面只定义了Grid的宽高,我是在Add Object的同时给其他控件定义属性。
2011-07-25 20:23
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
你那些ADD OBJECT 語句轉行時全漏了分號!

授人以渔,不授人以鱼。
2011-07-25 20:31
lyxc34
Rank: 2
等 级:论坛游民
帖 子:139
专家分:50
注 册:2011-7-3
收藏
得分:0 
  那个分号可以不要,在帮助里面示例就是这样写的。问题解决了,和你说的一样,应该先在arrange里面定义控件大小,再在Activate里面引用arrange过程,直接定义控件大小会出错。还有,上面的代码里面Click事件不能直接这样写,要写在Procedure里面。
  感觉用代码编表单的时候位置要调整好还是比较麻烦的,我想可不可以结合一下,先把控件在表单里面调整好,然后再根据位置再写代码。
2011-07-25 20:39
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
給你改過,自己對比一下

程序代码:
form_Stu = CREATEOBJECT("_Stu")

 form_Stu.Show

 READ EVENTS

 RETURN

 
DEFINE CLASS _Stu AS Form
     AutoCenter=.T.
     BackColor=RGB(181,221,243)
     BorderStyle=0
     Caption = "学生信息管理"
     Height=600
     MaxButton=.F.
     ShowWindow=2
     Width=800
     *WindowState = 0
     
     ADD OBJECT XskGrid AS grid
     ADD OBJECT Sp as Shape WITH Anchor = 240, BackStyle = 0, Height = 30, Width = 200, Left = (thisform.Width-this.Width)/2, Top = 10
     ADD OBJECT Lb as Label WITH Alignment = 2,Anchor = 240, AutoSize = .T., BackStyle = 0, Caption = "学生信息管理", FontBold = .T., FontSize = 12, Height = 20, Left = (thisform.Width-this.Width)/2, Top = 10
     ADD OBJECT Img1 as Image WITH BackStyle = 0, Height = 16, Width = 16, Left = thisform.Width-40, Top = 10
     ADD OBJECT Img2 as Image WITH BackStyle = 0, Height = 16, Width = 16, Left = thisform.Width-20, Top = 10
       
    PROCEDURE Load
         *USE h:\vfp\data\tables\xsk ORDER xh IN 0
     ENDPROC
     
     PROCEDURE Arrange
          WITH This.XskGrid
              .RecordMark = .F.
              .Top = 50
              .Left = 5
              .Height = This.Height - .Top - 5
              .Width = This.Width - .Left - 5
          ENDWITH
     ENDPROC 
    
     PROCEDURE Img1.Click
         thisform.XskGrid.AllowCellSelection= .F. 
     ENDPROC 
     
     PROCEDURE Img2.Click
         thisform.XskGrid.AllowCellSelection= .T. 
         thisform.Release
     ENDPROC 
     
    PROCEDURE Activate
          This.Arrange         
      ENDPROC 
    
    PROCEDURE Resize
          This.Arrange
     ENDPROC
         
     PROCEDURE Destroy
         CLEAR EVENTS
     ENDPROC 
     
     PROCEDURE Unload
         CLOSE TABLES ALL
     ENDPROC
ENDDEFINE


图片附件: 游客没有浏览图片的权限,请 登录注册


[ 本帖最后由 TonyDeng 于 2011-7-25 20:45 编辑 ]

授人以渔,不授人以鱼。
2011-07-25 20:43
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
分號可以不要,但逗號不能省。

授人以渔,不授人以鱼。
2011-07-25 20:46
lyxc34
Rank: 2
等 级:论坛游民
帖 子:139
专家分:50
注 册:2011-7-3
收藏
得分:0 
我改过的是这样的,和你改过的结果是一样的。
程序代码:
form_Stu = CREATEOBJECT("_Stu")
form_Stu.Show
READ EVENTS
RETURN

DEFINE CLASS _Stu AS Form
    AutoCenter=.T.
    BackColor=RGB(181,221,243)
    BorderStyle=0
    Caption = "学生信息管理"
    Height=600
    MaxButton=.F.
    ShowWindow=2
    Width=800
    WindowState = 0
    ADD OBJECT XskGrid AS grid
    ADD OBJECT Sp as Shape
    ADD OBJECT Lb as Label
    ADD OBJECT Img1 as Image
    ADD OBJECT Img2 as Image
    PROCEDURE Load
        USE h:\vfp\data\tables\xsk ORDER xh IN 0
    ENDPROC
    PROCEDURE Arrange
         WITH This.XskGrid
             .RecordMark = .F.
             .Top = 50
             .Left = 5
             .Height = This.Height - .Top - 5
             .Width = This.Width - .Left - 5
         ENDWITH
         WITH This.Sp
              .BackStyle = 0
              .Height = 30
              .Width = 200
              .Left = (thisform.Width-200)/2
              .Top = 10
         ENDWITH
         WITH This.Lb
               .Alignment = 2
               .AutoSize = .T.
               .BackStyle = 0
               .Caption = "学生信息管理"
               .FontBold = .T.
               .FontSize = 12
               .Height = 20
               .Left = (thisform.Width-100)/2
               .Top = 15
         ENDWITH
         WITH This.Img1
               .BackStyle = 0
               .Height = 16
               .Width = 16
               .Left = thisform.Width-40
               .Top = 10
         ENDWITH
         WITH This.Img2
               .BackStyle = 0
               .Height = 16
               .Width = 16
               .Left = thisform.Width-20
               .Top = 10
         ENDWITH         
    ENDPROC
    
    PROCEDURE Img1.Click
         thisform.XskGrid.AllowCellSelection= .F.        
    ENDPROC
    
    PROCEDURE Img2.Click
         thisform.XskGrid.AllowCellSelection= .T. 
         thisform.Release       
    ENDPROC
    
    PROCEDURE Activate
         This.Arrange         
    ENDPROC 
    
    PROCEDURE Resize
         This.Arrange
    ENDPROC
        
    PROCEDURE Unload
        CLEAR EVENTS
        CLOSE TABLES ALL
    ENDPROC

ENDDEFINE
2011-07-25 20:47
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
事先在表單裏把控件排得再好,也禁不住用戶拖拉任意改變窗體形狀的折騰,除非你設定不准用戶改變窗體形狀。有些控件,可能需要隨著窗體變化而變化,比如轉行什麽的,原先排一行的按鈕組被壓成兩行之類,這是事先設計無法實現的。當然,這些東西個人喜歡,只要找到容易編寫和維護的途徑就可以了。

授人以渔,不授人以鱼。
2011-07-25 20:53
快速回复:[求助]在记录前/后插入记录
数据加载中...
 
   



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

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