![]() |
#2
schtg4 天前 05:39
|
10/6更新代码如下:

DEFINE CLASS iptextbox as TextBox
Height = 20
InputMask = "###.###.###.###"
Width = 114
Name = "iptextbox"
PROCEDURE init
this.SelStart=0
this.SelLength=3
ENDPROC
PROCEDURE keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
DO CASE
CASE nkeycode=32 OR nkeycode=9 OR nkeycode=46 OR nkeycode=13 &&space,tab,".",enter
IF this.selstart>AT(".",this.value,3)
IF nkeycode=32 OR nkeycode=46 OR nkeycode=13
NODEFAULT
KEYBOARD '{TAB}'
ENDIF
ELSE
NODEFAULT
ctext=SUBSTR(this.Value,1,this.selstart)
ndot=OCCURS(".",ctext) &&有几个“.”
IF !(this.SelStart=AT(".",this.value,ndot) AND nkeycode=46)
ndot=IIF(ndot=3,3,ndot+1)
ndotpos=AT(".",this.value,ndot)
this.SelStart=ndotpos
this.SelLength=3
ENDIF
ENDIF
CASE BETWEEN(nkeycode,48,57) &&0-9
NODEFAULT
DODEFAULT()
*!* 上面2句必不可少,否则this.selstart的值不正确,这是通过下面这句代码发现的。
*!* SET MESSAGE TO TRANSFORM(this.SelStart)) &&用来观察this.selstart的表现
IF INLIST(this.SelStart,AT(".",this.Value,1),AT(".",this.Value,2),AT(".",this.Value,3))
this.SelLength=3
ENDIF
ENDCASE
ENDPROC
PROCEDURE valid
n=ALINES(atemp,this.Value,5,".")
IF n#4
SET MESSAGE TO "每个地址段的值不能为空"
RELEASE atemp
RETURN .f.
ELSE
FOR i =1 TO ALEN(atemp)
IF !BETWEEN(EVALUATE(atemp(i)),0,255)
SET MESSAGE TO "无效的ip地址端值"+atemp(i)
npos=AT(atemp(i),this.Value,1)-1
this.SelStart=npos
this.SelLength=3
RELEASE atemp
RETURN .f.
ENDIF
ENDFOR
ENDIF
endproc
ENDDEFINE
[此贴子已经被作者于2025-10-6 21:41编辑过]