编程论坛
注册
登录
编程论坛
→
VFP论坛
怎么才能让自定义属性对用户只读
sam_jiang
发布于 2023-09-07 20:17, 266 次点击
如题,如何设置属性对用户只读?而程序可以改变它的值?
用protect和hidden关键词的话,用户也无法访问这个属性了。。。
1 回复
#2
sam_jiang
2023-09-07 20:59
想到解决方案,但不知道有没有更好的?
程序代码:
clea
otest
=
CREATEOBJECT(
'
employee
'
)
otest.hiredate
=
{
^
2022
-
12
-
01
}
?otest.hiredate
otest.sethiredate()
?otest.hiredate
DEFINE CLASS employee
AS
CUSTOM
*
!
*
HIDDEN HireDate
*
!
*
PROTECTED HireDate
First_Name
=
"Jiang"
Last_Name
=
"Sam"
Address
=
""
HireDate
=
{
^
2017
-
06
-
05
}
cprogramname
=
[]
&&
用来判断修改者
PROCEDURE
GetHireDate
RETURN
This.HireDate
ENDPROC
PROCEDURE
hiredate_assign
PARAMETERS m.vnewval
m.voldval
=
this.hiredate
if
strextract(this.cprogramname,
[
.
]
,
[]
)
==
UPPER
(
[
sethiredate
]
)
*
!
*
检查cprogramname修改者是不是我们制定的方法
this.hiredate
=
m.vnewval
ELSE
this.hiredate
=
m.voldval
ENDIF
this.cprogramname
=
[]
&&
恢复不可修改状态
PROCEDURE
sethiredate
this.cprogramname
=
PROGRAM()
&&
传递方法名给属性cprogramname
this.hiredate
=
DATE()
ENDDEFINE
1