不用判断了下面会限制你的输入procedure TForm1.FormCreate(Sender: TObject); begin InitCommonControl(ICC_INTERNET_CLASSES); hIP := CreateWindow(WC_IPADDRESS,nil,WS_CHILD or WS_VISIBLE,20,20,130,23, Handle,0,hInstance,nil); end;
Function TmainForm.CheckIP(ipstr:string) : boolean; var i,j,k : integer; Fields :array[0..3] of string; begin Result:=False; j:=0; k:=0; For i:=1 to Length(ipstr) do begin IF j=3 then begin Fields[j]:=Copy(ipstr,1+k,Length(ipstr)-k); break; End; IF Copy(ipstr,i,1)='.' then begin Fields[j]:=Copy(ipstr,1+k,i-k-1); k:=i; inc(j); End; End; IF j<>3 then exit Else For j:=0 to 3 do begin IF strtointDef(Fields[j],-1)=-1 then exit Else IF (strtoint(Fields[j])<0) Or (strtoint(Fields[j])>255) then exit; End; result:=True; End;
begin
InitCommonControl(ICC_INTERNET_CLASSES);
hIP := CreateWindow(WC_IPADDRESS,nil,WS_CHILD or WS_VISIBLE,20,20,130,23, Handle,0,hInstance,nil);
end;
var
i,j,k : integer;
Fields :array[0..3] of string;
begin
Result:=False;
j:=0;
k:=0;
For i:=1 to Length(ipstr) do begin
IF j=3 then begin
Fields[j]:=Copy(ipstr,1+k,Length(ipstr)-k);
break;
End;
IF Copy(ipstr,i,1)='.' then begin
Fields[j]:=Copy(ipstr,1+k,i-k-1);
k:=i;
inc(j);
End;
End;
IF j<>3 then exit
Else
For j:=0 to 3 do begin
IF strtointDef(Fields[j],-1)=-1 then exit
Else
IF (strtoint(Fields[j])<0) Or (strtoint(Fields[j])>255) then exit;
End;
result:=True;
End;
注意uses CommCtrl, ComCtrls;
得到窗口句柄, 再用GetWindowText取出来