Y
yecloudy
Unregistered / Unconfirmed
GUEST, unregistred user!
unit IP;
interface
uses
SysUtils;
function MakeIpAdress(b1,b2,b3,b4:byte):longword;
function First_IPAdress(x:Longint):Byte;
function Second_IPAdress(x:Longint):Byte;
function Third_IPAdress(x:Longint):Byte;
function Fourth_IPAdress(x:Longint):Byte;
function ToTotal(value:string):Longint;
function ToIp(Total:Longint):string;
implementation
function MakeIpAdress(b1,b2,b3,b4:byte):Cardinal;
var
a,b,c,d,e,f:Cardinal ;
begin
a:= longint(b1) shl 24;
b:= longint(b2) shl 16;
c:= longint(b3) shl 8;
d:= longint(b4);
e:=(a + b);
f:=(c + d);
Result:=(e + f);//这里出错。
end;
function First_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 24) and $0FF);
end;
function Second_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 16) and $0FF);
end;
function Third_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 8) and $0FF);
end;
function Fourth_IPAdress(x:Longint):Byte;
begin
Result:=Byte(x and $0FF);
end;
function ToTotal(value:string):Longint;
var B:Array[0..3] of byte;
Str:string;
i,cnt:integer;
begin
b[0]:=0;
b[1]:=0;
b[2]:=0;
b[3]:=0;
cnt:=0;
i:=pos('.',value);
while (Length(value) > 0 ) and (cnt < 4 ) do begin
if (i = 0) then I:=length(value) + 1;
str:=copy(value,0,i - 1);
b[cnt]:=strtoint(str);
value:=copy(value,i+1,length(value));
i:=pos('.',value);
inc(cnt);
end;
Result:=MakeIpAdress(B[0],b[1],b[2],b[3]);
end;
Function Toip(Total:longint):String;
begin
Result:=IntToStr(First_IpAdress(total))+'.'+IntToStr(Second_IpAdress(total))+'.'+
IntToStr(Third_IpAdress(total))+'.'+IntToStr(Fourth_IpAdress(total));
end;
end.
interface
uses
SysUtils;
function MakeIpAdress(b1,b2,b3,b4:byte):longword;
function First_IPAdress(x:Longint):Byte;
function Second_IPAdress(x:Longint):Byte;
function Third_IPAdress(x:Longint):Byte;
function Fourth_IPAdress(x:Longint):Byte;
function ToTotal(value:string):Longint;
function ToIp(Total:Longint):string;
implementation
function MakeIpAdress(b1,b2,b3,b4:byte):Cardinal;
var
a,b,c,d,e,f:Cardinal ;
begin
a:= longint(b1) shl 24;
b:= longint(b2) shl 16;
c:= longint(b3) shl 8;
d:= longint(b4);
e:=(a + b);
f:=(c + d);
Result:=(e + f);//这里出错。
end;
function First_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 24) and $0FF);
end;
function Second_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 16) and $0FF);
end;
function Third_IPAdress(x:Longint):Byte;
begin
Result:=Byte((x shr 8) and $0FF);
end;
function Fourth_IPAdress(x:Longint):Byte;
begin
Result:=Byte(x and $0FF);
end;
function ToTotal(value:string):Longint;
var B:Array[0..3] of byte;
Str:string;
i,cnt:integer;
begin
b[0]:=0;
b[1]:=0;
b[2]:=0;
b[3]:=0;
cnt:=0;
i:=pos('.',value);
while (Length(value) > 0 ) and (cnt < 4 ) do begin
if (i = 0) then I:=length(value) + 1;
str:=copy(value,0,i - 1);
b[cnt]:=strtoint(str);
value:=copy(value,i+1,length(value));
i:=pos('.',value);
inc(cnt);
end;
Result:=MakeIpAdress(B[0],b[1],b[2],b[3]);
end;
Function Toip(Total:longint):String;
begin
Result:=IntToStr(First_IpAdress(total))+'.'+IntToStr(Second_IpAdress(total))+'.'+
IntToStr(Third_IpAdress(total))+'.'+IntToStr(Fourth_IpAdress(total));
end;
end.