精
精灵鸟
Unregistered / Unconfirmed
GUEST, unregistred user!
检验IP数据是否合法的函数,下面注释 error 的行出现 Invalid Typecast 错误,请各位大虾帮忙看看
function validateIP(addr:string):boolean;
var
b : integer;
counter : integer;
loc:integer;
tempchr:string;
addr1:string;
type a = array[1..4] of string;
label endd;
label ends;
begin
counter:=0;
addr1:=addr;
for b:=1 to 4 do a:=''
/*error*/
loc:=Pos('.',addr);
while loc>0 do
begin
inc(counter);
addr:=copy(addr,loc,length(addr));
loc:=Pos('.',addr);
end;
if counter<>3 then
begin
goto endd;
end;
loc:=1;
for b:=1 to length(addr1) do
if pos(copy(addr1,b,1),'1234567890')>0 then
appendstr(a[loc],copy(addr1,b,1)) /*error*/
else
begin
if copy(addr1,b,1)='.' then inc(loc)
else
goto endd;
end;
for b:=1 to 4 do
if strtoint(a) < 0 or strtoint(a)>255 then goto endd
/*error*/
ValidateIP:=True;
goto ends;
endd:
validateIP:=False;
ends:
end;
function validateIP(addr:string):boolean;
var
b : integer;
counter : integer;
loc:integer;
tempchr:string;
addr1:string;
type a = array[1..4] of string;
label endd;
label ends;
begin
counter:=0;
addr1:=addr;
for b:=1 to 4 do a:=''
/*error*/
loc:=Pos('.',addr);
while loc>0 do
begin
inc(counter);
addr:=copy(addr,loc,length(addr));
loc:=Pos('.',addr);
end;
if counter<>3 then
begin
goto endd;
end;
loc:=1;
for b:=1 to length(addr1) do
if pos(copy(addr1,b,1),'1234567890')>0 then
appendstr(a[loc],copy(addr1,b,1)) /*error*/
else
begin
if copy(addr1,b,1)='.' then inc(loc)
else
goto endd;
end;
for b:=1 to 4 do
if strtoint(a) < 0 or strtoint(a)>255 then goto endd
/*error*/
ValidateIP:=True;
goto ends;
endd:
validateIP:=False;
ends:
end;