| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3711 人关注过本帖
标题:运行时,怎么添加自定义属性?
只看楼主 加入收藏
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
结帖率:91.53%
收藏
已结贴  问题点数:100 回复次数:21 
运行时,怎么添加自定义属性?
[local]1[/local]

程序代码:
&&main.prg

SET TALK OFF    &&不显示命令结果
SET ECHO ON    &&调试时跟踪
SET DATE TO ANSI    &&yy.mm.dd的时间格式
SET ESCAPE OFF    &&按ESC键不中断命令或程序运行
SET SAFETY OFF    &&改写文件时不提示
SET EXACT ON    &&精确字符串比较?
SET DELETED ON    &&忽略做了删除标记的记录
SET CENTURY ON    &&显示四位年份
CLOSE ALL
CLEAR ALL
&&_screen.Visible= .F.  &&在config.fpw中用SCREEN=OFF代替了
PUBLIC currUser &&,userPerm 登录用户权限
myDrv=SYS(5)
myDir=SYS(2003)
myProgPath=myDrv+myDir
SET DEFAULT TO &myProgPath    &&当前程序所在盘和所在路径
SET PROCEDURE TO "myFormClass","myControlClass" ADDITIVE &&ADDITIVE参数的作用有待测试
PUBLIC testLoginCount  &&问题在这里
testLoginCount=3

mainForm=CREATEOBJECT("mForm")
    WITH mainForm
        .caption="水电工程处材料管理系统"
        .autoCenter=.t.
        .borderStyle=2
        .icon="logo.ico"
        .picture="主背景.bmp"
        .height=550
        .width=770
        .maxButton=.f.
        &&.show
    ENDWITH 
USE 授权用户
loginForm=CREATEOBJECT("logForm")
    WITH loginForm
        .caption="欢迎登录材料管理系统"
        .autoCenter=.t.
        .width=300
        .height=200
        .titleBar=0
        .picture="登录背景.bmp"
        .icon="logo.ico"
        .controlBox=.f.        
    ENDWITH
loginForm.show
READ EVENTS
RETURN 

DEFINE CLASS mForm as myForm
    showWindow=2
    ADD OBJECT cmdExit as exitBtn WITH caption="退出系统",top=504,left=108,height=25,width=60
        
    PROCEDURE show
        thisform.autoCenter=.t.
        MESSAGEBOX(currUser,64,"aaa")
    ENDPROC
    
    PROCEDURE destroy
        CLEAR EVENTS 
    ENDPROC 
ENDDEFINE

DEFINE CLASS logForm as Form 
    showWindow=2
    ADD OBJECT cmdLogin as loginBtn
    ADD OBJECT cmdExit as logExitBtn WITH top=168,left=228,height=25,width=60,caption="退 出"
    ADD OBJECT userNameCombo as logCbx
    ADD OBJECT passwordCheck as logPass
    ADD OBJECT lbl1 as Label WITH caption="水电工程处",;
        alignment=2,;
        backStyle=0,;
        fontSize=16,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=48,;
        top=12,;
        width=204
    
    ADD OBJECT lbl2 as Label WITH caption="材料管理系统",;
        alignment=2,;
        backStyle=0,;
        fontSize=18,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=63,;
        top=48,;
        width=174

    ADD OBJECT lbl3 as Label WITH caption="用户名:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=84,;
        width=60
        
    ADD OBJECT lbl4 as Label WITH caption="密 码:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=132,;
        width=60
        
*!*        PROCEDURE load 
*!*            LOCAL testLoginCount
*!*            testLoginCount=3
*!*        ENDPROC 
ENDDEFINE

DEFINE CLASS logExitBtn as CommandButton 
    PROCEDURE click
        CLOSE ALL 
        CLEAR events
        IF _vfp.StartMode==4
            QUIT 
        ENDIF  
    ENDPROC 
ENDDEFINE 

DEFINE CLASS loginBtn as CommandButton
    top=168
    left=144
    height=25
    width=60
    caption="登 录"
    
    PROCEDURE click
        IF ALLTRIM(thisform.userNameCombo.Value)==ALLTRIM(授权用户.用户名) ;
            AND ALLTRIM(thisform.passwordCheck.value)==ALLTRIM(授权用户.密码)
            currUser=ALLTRIM(授权用户.用户名)
            thisform.Release
            mainForm.show
        ELSE
            testLoginCount=testLoginCount-1
            IF testLoginCount=0
                MESSAGEBOX("尝试登录过于频繁,程序将退出!如有问题,请联系程序管理员!",64,"非法登录警告!")
                thisform.Release 
            ELSE
                msgText="用户名或密码错误,你还有"+ALLTRIM(STR(testLoginCount))+"次机会!"
                =MESSAGEBOX(msgText,64,"重试登录")
                thisform.passwordCheck.Value=""
                thisform.passwordCheck.SetFocus()
            ENDIF
        ENDIF
        SELECT 授权用户
        USE 
ENDDEFINE 

DEFINE CLASS logCbx as ComboBox 
    left=96
    top=84
    width=156
    height=24
    fontSize=12
    rowSource="授权用户.用户名"
    rowSourceType=6
ENDDEFINE 

DEFINE CLASS logPass as TextBox
    passwordChar="*"
    left=96
    height=24
    top=132
    width=156
    fontSize=12
ENDDEFINE 


程序代码:
&&myControlClass.prg

DEFINE CLASS exitBtn as CommandButton 
    PROCEDURE click
        RELEASE thisform
    ENDPROC 
ENDDEFINE


程序代码:
&&myFormClass.prg

DEFINE CLASS myForm as Form 
    PROCEDURE arrange
        FOR EACH obj IN this.controls FOXOBJECT
            IF (VARTYPE(obj.canArrange)=="L").and.obj.canArrange
                obj.arrange
            ENDIF         
        NEXT  
    ENDPROC 
    
    PROCEDURE activate
        this.arrange
    ENDPROC 
    
    PROCEDURE reSize
        this.arrange
    ENDPROC 
ENDDEFINE


问题描述:testLoginCount,用于计数登录次数

用表单设计器设计表单的时候,我把它放在表单的init里,就可以了

可是,用代码设计的时候,写在表单类定义的init里,还不行,只能在程序最开始用public,这样做,用完之后,还不知道怎么销毁

想起之前的贴子,有几位老师说,可以用表单自定义属性代替全局变量,查了帮助,只看到设计器里怎么做,运行时用代码创建表单,就不知道怎么做了

请各位老师指教
2015-12-14 14:53
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:50 
程序代码:
of = CREATEOBJECT("form1")
of.show(1)

DEFINE CLASS form1 as Form
    myABCD = "自定义属性"
    
    PROCEDURE Init
        this.Caption = this.myABCD
    ENDPROC
ENDDEFINE
2015-12-14 15:05
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
动态可用AddProperty()方法
2015-12-14 15:08
不懂才问
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:大草原
等 级:贵宾
威 望:29
帖 子:1503
专家分:6593
注 册:2010-7-5
收藏
得分:0 
程序代码:
&&main.prg

SET TALK OFF    &&不显示命令结果
SET ECHO ON    &&调试时跟踪
SET DATE TO ANSI    &&yy.mm.dd的时间格式
SET ESCAPE OFF    &&按ESC键不中断命令或程序运行
SET SAFETY OFF    &&改写文件时不提示
SET EXACT ON    &&精确字符串比较?
SET DELETED ON    &&忽略做了删除标记的记录
SET CENTURY ON    &&显示四位年份
CLOSE ALL
CLEAR ALL
&&_screen.Visible= .F.  &&在config.fpw中用SCREEN=OFF代替了
PUBLIC currUser &&,userPerm 登录用户权限
myDrv=SYS(5)
myDir=SYS(2003)
myProgPath=myDrv+myDir
SET DEFAULT TO &myProgPath    &&当前程序所在盘和所在路径
SET PROCEDURE TO "myFormClass","myControlClass" ADDITIVE &&ADDITIVE参数的作用有待测试
*!*    PUBLIC testLoginCount  &&问题在这里
*!*    testLoginCount=3

mainForm=CREATEOBJECT("mForm")
    WITH mainForm
        .caption="水电工程处材料管理系统"
        .autoCenter=.t.
        .borderStyle=2
        .icon="logo.ico"
        .picture="主背景.bmp"
        .height=550
        .width=770
        .maxButton=.f.
        &&.show
    ENDWITH 
USE 授权用户
loginForm=CREATEOBJECT("logForm")
    WITH loginForm
        .caption="欢迎登录材料管理系统"
        .autoCenter=.t.
        .width=300
        .height=200
        .titleBar=0
        .picture="登录背景.bmp"
        .icon="logo.ico"
        .controlBox=.f.        
    ENDWITH
loginForm.show
READ EVENTS
RETURN 

DEFINE CLASS mForm as myForm
    showWindow=2
    ADD OBJECT cmdExit as exitBtn WITH caption="退出系统",top=504,left=108,height=25,width=60
        
    PROCEDURE show
        thisform.autoCenter=.t.
        MESSAGEBOX(currUser,64,"aaa")
    ENDPROC
    
    PROCEDURE destroy
        CLEAR EVENTS 
    ENDPROC 
ENDDEFINE

DEFINE CLASS logForm as Form 
    showWindow=2
    testLoginCount=3
    ADD OBJECT cmdLogin as loginBtn
    ADD OBJECT cmdExit as logExitBtn WITH top=168,left=228,height=25,width=60,caption="退 出"
    ADD OBJECT userNameCombo as logCbx
    ADD OBJECT passwordCheck as logPass
    ADD OBJECT lbl1 as Label WITH caption="水电工程处",;
        alignment=2,;
        backStyle=0,;
        fontSize=16,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=48,;
        top=12,;
        width=204
    
    ADD OBJECT lbl2 as Label WITH caption="材料管理系统",;
        alignment=2,;
        backStyle=0,;
        fontSize=18,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=63,;
        top=48,;
        width=174

    ADD OBJECT lbl3 as Label WITH caption="用户名:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=84,;
        width=60
        
    ADD OBJECT lbl4 as Label WITH caption="密 码:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=132,;
        width=60
        
        PROCEDURE init 
            LOCAL varTestLoginCount
            varTestLoginCount=this.testLoginCount
        ENDPROC 
ENDDEFINE

DEFINE CLASS logExitBtn as CommandButton 
    PROCEDURE click
        CLOSE ALL 
        CLEAR events
        IF _vfp.StartMode==4
            QUIT 
        ENDIF  
    ENDPROC 
ENDDEFINE 

DEFINE CLASS loginBtn as CommandButton
    top=168
    left=144
    height=25
    width=60
    caption="登 录"
    
    PROCEDURE click
        IF ALLTRIM(thisform.userNameCombo.Value)==ALLTRIM(授权用户.用户名) ;
            AND ALLTRIM(thisform.passwordCheck.value)==ALLTRIM(授权用户.密码)
            currUser=ALLTRIM(授权用户.用户名)
            thisform.Release
            mainForm.show
        ELSE
            varTestLoginCount=varTestLoginCount-1
            IF varTestLoginCount=0
                MESSAGEBOX("尝试登录过于频繁,程序将退出!如有问题,请联系程序管理员!",64,"非法登录警告!")
                thisform.Release 
            ELSE
                msgText="用户名或密码错误,你还有"+ALLTRIM(STR(varTestLoginCount))+"次机会!"
                =MESSAGEBOX(msgText,64,"重试登录")
                thisform.passwordCheck.Value=""
                thisform.passwordCheck.SetFocus()
            ENDIF
        ENDIF
        SELECT 授权用户
        USE 
ENDDEFINE 

DEFINE CLASS logCbx as ComboBox 
    left=96
    top=84
    width=156
    height=24
    fontSize=12
    rowSource="授权用户.用户名"
    rowSourceType=6
ENDDEFINE 

DEFINE CLASS logPass as TextBox
    passwordChar="*"
    left=96
    height=24
    top=132
    width=156
    fontSize=12
ENDDEFINE 


用这个自定义属性  还是提示找不到变量

类定义在类创建之前,所以…………

有些属性和方法写在类定义里

有些属性和方法写在类的实例化里

有没有一些方法可以写在实例化之后的程序里?

报告老师,我低头不是因为我在装低调,是你问的问题,我真的不会答,,,
2015-12-14 15:27
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
慢慢瞧瞧
2015-12-14 15:34
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
帮助文件最少要看10遍才能写代码

坚守VFP最后的阵地
2015-12-14 15:45
sdta
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:江苏省连云港市
等 级:版主
威 望:335
帖 子:9841
专家分:27213
注 册:2012-2-5
收藏
得分:0 
光凭兴趣是学不好编程的,该掌握的知识一定要掌握。
典型的不会走路,就想学跑

坚守VFP最后的阵地
2015-12-14 15:48
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10607
专家分:43182
注 册:2014-5-20
收藏
得分:0 
“用这个自定义属性  还是提示找不到变量 ”
具体是指那个自定义属性?

“有没有一些方法可以写在实例化之后的程序里?”
直接写FUNCTION调用好了。
如果是事件可以绑定到其他类对象的自定义方法。

一般情况自已封装的类极少这样运作。
2015-12-14 16:08
zyxxzhyg
Rank: 3Rank: 3
来 自:江西
等 级:论坛游侠
威 望:5
帖 子:58
专家分:134
注 册:2014-6-26
收藏
得分:50 
PROCEDURE init
            LOCAL varTestLoginCount
            varTestLoginCount=this.testLoginCount
        ENDPROC
中定义的为过程 init的局部变量,不能在后面用,考虑改为属性才行
 thisform.varTestLoginCount=thisform.varTestLoginCount-1
            IF thisform.varTestLoginCount=0
                MESSAGEBOX("尝试登录过于频繁,程序将退出!如有问题,请联系程序管理员!",64,"非法登录警告!")
                thisform.Release
            ELSE
                msgText="用户名或密码错误,你还有"+ALLTRIM(STR(thisform.varTestLoginCount))+"次机会!"
                =MESSAGEBOX(msgText,64,"重试登录")
                thisform.passwordCheck.Value=""
                thisform.passwordCheck.SetFocus()
            ENDIF
        ENDIF
        SELECT 授权用户
        ** USE
关了表,无法再次输入?
2015-12-14 16:30
zyxxzhyg
Rank: 3Rank: 3
来 自:江西
等 级:论坛游侠
威 望:5
帖 子:58
专家分:134
注 册:2014-6-26
收藏
得分:0 
SET TALK OFF    &&不显示命令结果
SET ECHO ON    &&调试时跟踪
SET DATE TO ANSI    &&yy.mm.dd的时间格式
SET ESCAPE OFF    &&按ESC键不中断命令或程序运行
SET SAFETY OFF    &&改写文件时不提示
SET EXACT ON    &&精确字符串比较?
SET DELETED ON    &&忽略做了删除标记的记录
SET CENTURY ON    &&显示四位年份
CLOSE ALL
CLEAR ALL
&&_screen.Visible= .F.  &&在config.fpw中用SCREEN=OFF代替了
PUBLIC currUser &&,userPerm 登录用户权限

PUBLIC LCSys16,LCNowpath
LCSys16=SYS(16)      &&获取当前程序所在的全路径,包括当前运行程序名。
LCNowpath=LEFT(LCsys16,RAT("\",LCSys16,1))   &&获取当前运行程序所在工作目录。

SET DEFAULT TO &LCNowpath    &&当前程序所在盘和所在路径
SET PROCEDURE TO "myFormClass","myControlClass" ADDITIVE &&ADDITIVE参数的作用有待测试
*!*    PUBLIC testLoginCount  &&问题在这里
*!*    testLoginCount=3

mainForm=CREATEOBJECT("mForm")
    WITH mainForm
        .caption="水电工程处材料管理系统"
        .autoCenter=.t.
        .borderStyle=2
        .icon="logo.ico"
        .picture="主背景.bmp"
        .height=550
        .width=770
        .maxButton=.f.
        &&.show
    ENDWITH
USE 授权用户
loginForm=CREATEOBJECT("logForm")
    WITH loginForm
        .caption="欢迎登录材料管理系统"
        .autoCenter=.t.
        .width=300
        .height=200
        .titleBar=0
        .picture="登录背景.bmp"
        .icon="logo.ico"
        .controlBox=.f.        
    ENDWITH
loginForm.show
READ EVENTS
RETURN

DEFINE CLASS mForm as myForm
    showWindow=2
    ADD OBJECT cmdExit as exitBtn WITH caption="退出系统",top=504,left=108,height=25,width=60
        
    PROCEDURE show
        thisform.autoCenter=.t.
        MESSAGEBOX(currUser,64,"aaa")
    ENDPROC
   
    PROCEDURE destroy
        CLEAR EVENTS
    ENDPROC
ENDDEFINE

DEFINE CLASS logForm as Form
       showWindow=2
      testLoginCount=3
    ADD OBJECT cmdLogin as loginBtn
    ADD OBJECT cmdExit as logExitBtn WITH top=168,left=228,height=25,width=60,caption="退 出"
    ADD OBJECT userNameCombo as logCbx
    ADD OBJECT passwordCheck as logPass
    ADD OBJECT lbl1 as Label WITH caption="水电工程处",;
        alignment=2,;
        backStyle=0,;
        fontSize=16,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=48,;
        top=12,;
        width=204
   
    ADD OBJECT lbl2 as Label WITH caption="材料管理系统",;
        alignment=2,;
        backStyle=0,;
        fontSize=18,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=63,;
        top=48,;
        width=174

    ADD OBJECT lbl3 as Label WITH caption="用户名:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=84,;
        width=60
        
    ADD OBJECT lbl4 as Label WITH caption="密 码:",;
        backStyle=0,;
        fontSize=12,;
        foreColor=RGB(0,0,0),;
        height=24,;
        left=24,;
        top=132,;
        width=60
        
        PROCEDURE init
            this.AddProperty ( "varTestLoginCount")
            this.varTestLoginCount=this.testLoginCount
        ENDPROC
ENDDEFINE

DEFINE CLASS logExitBtn as CommandButton
    PROCEDURE click
        CLOSE ALL
        CLEAR events
        IF _vfp.StartMode==4
            QUIT
        ENDIF  
    ENDPROC
ENDDEFINE

DEFINE CLASS loginBtn as CommandButton
    top=168
    left=144
    height=25
    width=60
    caption="登 录"
   
    PROCEDURE click
        IF ALLTRIM(thisform.userNameCombo.Value)==ALLTRIM(授权用户.username) ;
            AND ALLTRIM(thisform.passwordCheck.value)==ALLTRIM(授权用户.id)
            currUser=ALLTRIM(授权用户.username)
            thisform.Release
            mainForm.show
        ELSE
            thisform.varTestLoginCount=thisform.varTestLoginCount-1
            IF thisform.varTestLoginCount=0
                MESSAGEBOX("尝试登录过于频繁,程序将退出!如有问题,请联系程序管理员!",64,"非法登录警告!")
                thisform.Release
            ELSE
                msgText="用户名或密码错误,你还有"+ALLTRIM(STR(thisform.varTestLoginCount))+"次机会!"
                =MESSAGEBOX(msgText,64,"重试登录")
                thisform.passwordCheck.Value=""
                thisform.passwordCheck.SetFocus()
            ENDIF
        ENDIF
        SELECT 授权用户
        ** USE
ENDDEFINE

DEFINE CLASS logCbx as ComboBox
    left=96
    top=84
    width=156
    height=24
    fontSize=12
    rowSource="授权用户.username"
    rowSourceType=6
ENDDEFINE

DEFINE CLASS logPass as TextBox
    passwordChar="*"
    left=96
    height=24
    top=132
    width=156
    fontSize=12
ENDDEFINE
用户表我修改过,所以字段名不同,已正常运行
2015-12-14 16:31
快速回复:运行时,怎么添加自定义属性?
数据加载中...
 
   



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

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