| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1257 人关注过本帖
标题:请教:下面是张洪举VFP9中的用类定义写的代码为什么不能运行?
只看楼主 加入收藏
sylknb
Rank: 4
等 级:贵宾
威 望:14
帖 子:1547
专家分:184
注 册:2006-6-3
结帖率:79.38%
收藏
已结贴  问题点数:20 回复次数:12 
请教:下面是张洪举VFP9中的用类定义写的代码为什么不能运行?
附件
program3.rar (1.47 KB)



PUBLIC oform1

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


    **************************************************
*-- Form:         form1 (d:\vfp8jc\基础篇\10\software\10.3.15\form6.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   01/29/04 05:14:10 PM
*
DEFINE CLASS form1 AS form


    Top = 0
    Left = 0
    Height = 231
    Width = 406
    DoCreate = .T.
    Caption = "单击列标头排序示例"
    Name = "form1"


    ADD OBJECT form1.grid1 AS grid WITH ;
        ColumnCount = 7, ;
        ChildOrder = "语文成绩", ;
        DeleteMark = .F., ;
        Height = 189, ;
        Left = 6, ;
        Panel = 1, ;
        RecordMark = .F., ;
        RecordSource = "tblstudent", ;
        SplitBar = .F., ;
        Top = 6, ;
        Width = 390, ;
        GridLineColor = RGB(128,128,128), ;
        LockColumns = 2, ;
        Name = "Grid1", ;
        Column1.ControlSource = "tblstudent.学号", ;
        Column1.Width = 59, ;
        Column1.Name = "Column1", ;
        Column2.ControlSource = "tblstudent.姓名", ;
        Column2.Width = 62, ;
        Column2.Name = "Column2", ;
        Column3.ControlSource = "tblstudent.学期", ;
        Column3.Width = 54, ;
        Column3.Name = "Column3", ;
        Column4.ControlSource = "tblstudent.语文成绩", ;
        Column4.Width = 71, ;
        Column4.Name = "Column4", ;
        Column5.ControlSource = "tblstudent.数学成绩", ;
        Column5.Width = 67, ;
        Column5.Name = "Column5", ;
        Column6.ControlSource = "tblstudent.英语成绩", ;
        Column6.Width = 90, ;
        Column6.Name = "Column6", ;
        Column7.ControlSource = "tblstudent.总成绩", ;
        Column7.Width = 90, ;
        Column7.Name = "Column7"


    ADD OBJECT form1.grid1.column1.header1 AS header WITH ;   **提示语法错误,以下只要是add object from1.grid1.column..... with 都提示语法错误
        Caption = "学号", ;
        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 = "姓名", ;
        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 = "学期", ;
        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 form1.grid1.column4.header1 AS header WITH ;
        Caption = "语文成绩", ;
        Picture = "up.bmp", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column4.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column5.header1 AS header WITH ;
        Caption = "数学成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column5.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column6.header1 AS header WITH ;
        Caption = "英语成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column6.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column7.header1 AS header WITH ;
        Caption = "总成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column7.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 201, ;
        Left = 285, ;
        Height = 25, ;
        Width = 94, ;
        Caption = "关闭(\<C)", ;
        Name = "Command1"


    PROCEDURE header1.Click
        LOCAL lnRecno
        lnRecno=IIF(EOF() OR BOF(),1,RECNO())  &&保存当前记录号
        IF UPPER(JUSTSTEM(This.Picture))="UP"
            This.Picture="Down.bmp"
            SET ORDER TO 语文成绩 DESCENDING   &&降序排列
        ELSE
            This.Picture="Up.bmp"
            SET ORDER TO 语文成绩 ASCENDING    &&升序排列
        ENDIF

        Thisform.Refresh  
        GO lnRecno
    ENDPROC


    PROCEDURE command1.Click
        RELEASE Thisform
    ENDPROC


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


[ 本帖最后由 sylknb 于 2012-11-29 12:41 编辑 ]
搜索更多相关主题的帖子: PUBLIC software 基础 
2012-11-29 12:40
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
不需要form1.,把这6个字符删掉!

授人以渔,不授人以鱼。
2012-11-29 15:57
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
看下帮助文件中VFP语法的应用

坚守VFP最后的阵地
2012-11-29 17:24
sylknb
Rank: 4
等 级:贵宾
威 望:14
帖 子:1547
专家分:184
注 册:2006-6-3
收藏
得分:0 
我把下面14处的form1删除后,还是提示语法错误
ADD OBJECT grid1.column1.header1 AS header WITH ;  
        Caption = "学号", ;
        Name = "Header1"


    ADD OBJECT grid1.column1.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column2.header1 AS header WITH ;
        Caption = "姓名", ;
        Name = "Header1"


    ADD OBJECT grid1.column2.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column3.header1 AS header WITH ;
        Caption = "学期", ;
        Name = "Header1"


    ADD OBJECT grid1.column3.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column4.header1 AS header WITH ;
        Caption = "语文成绩", ;
        Picture = "up.bmp", ;
        Name = "Header1"


    ADD OBJECT grid1.column4.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column5.header1 AS header WITH ;
        Caption = "数学成绩", ;
        Name = "Header1"


    ADD OBJECT grid1.column5.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column6.header1 AS header WITH ;
        Caption = "英语成绩", ;
        Name = "Header1"


    ADD OBJECT grid1.column6.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT grid1.column7.header1 AS header WITH ;
        Caption = "总成绩", ;
        Name = "Header1"


    ADD OBJECT grid1.column7.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"

2012-11-29 17:28
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
grid1下面的控件不是这样用add object加上去的,我都不知道张当初写这段代码怎么能通得过(可能是旧版VFP的语法),整个就不是那样写。在form表单类代码中,最多就只能add object到一层grid,grid下面的控件,不可以在form层add object进去,而是在某段运行代码中addobject()进去的——也可以创建一个继承自grid的子类自己组装控件,然后整个add object到form中。

授人以渔,不授人以鱼。
2012-11-29 17:37
sylknb
Rank: 4
等 级:贵宾
威 望:14
帖 子:1547
专家分:184
注 册:2006-6-3
收藏
得分:0 
附上原form6等内容
form6.rar (5.58 KB)


能不能用类游览器从已知的表单中提示代码并转为prg
我从form6表单中提取了代码
**************************************************
*-- Form:         form1 (d:\10.3.15\form6.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- 时间戳:   05/26/04 03:42:09 PM
*



PUBLIC oform1

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

*---- 以上4句本人加上去的,下面都是从类游览器中提取form6.scx中的代码ADD OBJECT form1.grid1.column1.header1 AS header WITH 为什么提示语法错误

DEFINE CLASS form1 AS form


    Top = 10
    Left = 6
    Height = 231
    Width = 406
    DoCreate = .T.
    Caption = "单击列标头进行数据排序示例"
    Name = "Form1"


    ADD OBJECT grid1 AS grid WITH ;
        ColumnCount = 7, ;
        ChildOrder = "语文成绩", ;
        DeleteMark = .F., ;
        GridLines = 3, ;
        HeaderHeight = 19, ;
        Height = 189, ;
        Left = 6, ;
        Panel = 1, ;
        RecordMark = .F., ;
        RecordSource = "tblstudent", ;
        ScrollBars = 3, ;
        SplitBar = .F., ;
        Top = 6, ;
        Width = 390, ;
        GridLineColor = RGB(128,128,128), ;
        LockColumns = 0, ;
        AllowCellSelection = .T., ;
        Name = "Grid1", ;
        Column1.ControlSource = "tblstudent.学号", ;
        Column1.Width = 59, ;
        Column1.Name = "Column1", ;
        Column2.ControlSource = "tblstudent.姓名", ;
        Column2.Width = 62, ;
        Column2.Name = "Column2", ;
        Column3.ControlSource = "tblstudent.学期", ;
        Column3.Width = 54, ;
        Column3.Name = "Column3", ;
        Column4.ControlSource = "tblstudent.语文成绩", ;
        Column4.Width = 71, ;
        Column4.Name = "Column4", ;
        Column5.ControlSource = "tblstudent.数学成绩", ;
        Column5.Width = 67, ;
        Column5.Name = "Column5", ;
        Column6.ControlSource = "tblstudent.英语成绩", ;
        Column6.Width = 90, ;
        Column6.Name = "Column6", ;
        Column7.ControlSource = "tblstudent.总成绩", ;
        Column7.Width = 90, ;
        Column7.Name = "Column7"


    ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
        Caption = "学号", ;
        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 = "姓名", ;
        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 = "学期", ;
        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 form1.grid1.column4.header1 AS header WITH ;
        Caption = "语文成绩", ;
        Picture = "up.bmp", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column4.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column5.header1 AS header WITH ;
        Caption = "数学成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column5.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column6.header1 AS header WITH ;
        Caption = "英语成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column6.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT form1.grid1.column7.header1 AS header WITH ;
        Caption = "总成绩", ;
        Name = "Header1"


    ADD OBJECT form1.grid1.column7.text1 AS textbox WITH ;
        BorderStyle = 0, ;
        Margin = 0, ;
        ForeColor = RGB(0,0,0), ;
        BackColor = RGB(255,255,255), ;
        Name = "Text1"


    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 201, ;
        Left = 285, ;
        Height = 25, ;
        Width = 94, ;
        Caption = "关闭(\<C)", ;
        Name = "Command1"


    PROCEDURE header1.Click
        LOCAL lnRecno
        lnRecno=IIF(EOF() OR BOF(),1,RECNO())  &&保存当前记录号
        IF UPPER(JUSTSTEM(This.Picture))="UP"
            This.Picture="Down.bmp"
            SET ORDER TO 语文成绩 DESCENDING   &&降序排列
        ELSE
            This.Picture="Up.bmp"
            SET ORDER TO 语文成绩 ASCENDING    &&升序排列
        ENDIF

        Thisform.Refresh  
        GO lnRecno
    ENDPROC


    PROCEDURE command1.Click
        RELEASE Thisform
    ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
2012-11-29 18:05
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
类设计器是VFP语言之外另外编制的一个实用软件,不是语言内置的,它所生成的代码,归它自己解释,编译后再提交给VFP内核执行。我从来不使用这种设计器,如果它生成的代码是这种形式,要改编为正宗的语法,不如自己重新写一个还省力。编译不通过,就是证据。

授人以渔,不授人以鱼。
2012-12-01 11:22
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:20 
这种代码不可取的道理其实很简单,看看这段:
程序代码:
ADD OBJECT grid1 AS grid WITH ;
        ColumnCount = 7, ;
        ChildOrder = "语文成绩", ;
        DeleteMark = .F., ;
        GridLines = 3, ;
        HeaderHeight = 19, ;
        Height = 189, ;
        Left = 6, ;
        Panel = 1, ;
        RecordMark = .F., ;
        RecordSource = "tblstudent", ;
        ScrollBars = 3, ;
        SplitBar = .F., ;
        Top = 6, ;
        Width = 390, ;
        GridLineColor = RGB(128,128,128), ;
        LockColumns = 0, ;
        AllowCellSelection = .T., ;
        Name = "Grid1", ;
        Column1.ControlSource = "tblstudent.学号", ;
        Column1.Width = 59, ;
        Column1.Name = "Column1", ;
        Column2.ControlSource = "tblstudent.姓名", ;
        Column2.Width = 62, ;
        Column2.Name = "Column2", ;
        Column3.ControlSource = "tblstudent.学期", ;
        Column3.Width = 54, ;
        Column3.Name = "Column3", ;
        Column4.ControlSource = "tblstudent.语文成绩", ;
        Column4.Width = 71, ;
        Column4.Name = "Column4", ;
        Column5.ControlSource = "tblstudent.数学成绩", ;
        Column5.Width = 67, ;
        Column5.Name = "Column5", ;
        Column6.ControlSource = "tblstudent.英语成绩", ;
        Column6.Width = 90, ;
        Column6.Name = "Column6", ;
        Column7.ControlSource = "tblstudent.总成绩", ;
        Column7.Width = 90, ;
        Column7.Name = "Column7"


每个字段都是重复写出的,而不是使用节省劳动力的循环(想想你有几十个字段的情景),而且每栏的宽度Width居然是硬编码数值,正犯程序代码的大忌。这样的代码不是好榜样,也不好重用,如果要改它,需要做的功夫太多,不如重新写一个,这就是我说的理由。这种代码,明显是电脑程序自生成的,它可以重复劳动,但人不可以这样做,拿这种代码来改,是不现实的。

授人以渔,不授人以鱼。
2012-12-01 12:19
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:400
帖 子:11857
专家分:43421
注 册:2006-5-13
收藏
得分:0 
我不理解为何弃“可视化”而不用。

活到老,学到老!http://www.(该域名已经被ISP盗卖了)E-mail:hu-jj@
2012-12-01 14:11
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
以下是引用hu9jj在2012-12-1 14:11:51的发言:

我不理解为何弃“可视化”而不用。
同感
2012-12-01 14:46
快速回复:请教:下面是张洪举VFP9中的用类定义写的代码为什么不能运行?
数据加载中...
 
   



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

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