procedure TForm1.Button1Click(Sender: TObject);
var
s : String ;
tempStr ,Temp_s: String ;
i:Integer ;
begin
s := edit1.text ;
tempStr := '';
for I := length(s) downto 1 do
begin
if s[i] = '.' then
begin
temp_s := copy (s,1,i);
break ;
end ;
tempStr := s[i]+tempstr ;
end ;
try
i := strtoint(tempstr);
except
end ;
if i = 255 then
begin
//处理
end ;
edit1.Text := temp_s +inttostr(i+1);end;
这样可以!也可以用其他办法:
edit1中让用户输入网段:如:‘192.168.2‘就可以了
edit2中输入开始的ip:如:1
edit3中输入结束的ip:如:3
这样你不是更好吗?
var
s : String ;
tempStr ,Temp_s: String ;
i:Integer ;
begin
s := edit1.text ;
tempStr := '';
for I := length(s) downto 1 do
begin
if s[i] = '.' then
begin
temp_s := copy (s,1,i);
break ;
end ;
tempStr := s[i]+tempstr ;
end ;
try
i := strtoint(tempstr);
except
end ;
if i = 255 then
begin
//处理
end ;
edit1.Text := temp_s +inttostr(i+1);end;
这样可以!也可以用其他办法:
edit1中让用户输入网段:如:‘192.168.2‘就可以了
edit2中输入开始的ip:如:1
edit3中输入结束的ip:如:3
这样你不是更好吗?
TIPArray = array[0..3] of Word;
TcqIPAddress = class
private
FIPWord: TIPArray;
FIPAddress: string;
FIPs: TStrings;
procedure SetIPAddress(const Value: string);
function GetIPAddress: string;
function GetIP(const Index: Integer): Word;
public
property IP1: Word index 1 read GetIP;
property IP2: Word index 2 read GetIP;
property IP3: Word index 3 read GetIP;
property IP4: Word index 4 read GetIP;
property IPAddress: string read GetIPAddress write SetIPAddress;
constructor Create;
procedure IncAddress(ACount: Integer = 1);
end;
{ TcqIPAddress }procedure StrToStrings(S: AnsiString; Sep: AnsiString; const List: TStrings);
var
I, L: Integer;
Left: AnsiString;
begin
Assert(List <> nil);
List.Clear;
L := Length(Sep);
I := Pos(Sep, S);
while (I > 0) do
begin
Left := LeftStr(S, I - 1);
List.Add(Left);
Delete(S, 1, I + L - 1);
I := Pos(Sep, S);
end;
if S <> '' then
List.Add(S);
end;constructor TcqIPAddress.Create;
begin
FIPs := TStringList.Create;
end;function TcqIPAddress.GetIP(const Index: Integer): Word;
begin
Result := FIPWord[Index - 1]
end;function TcqIPAddress.GetIPAddress: string;
begin
Result := Format('%d.%d.%d.%d', [FIPWord[0], FIPWord[1],
FIPWord[2], FIPWord[3]]);
end;procedure TcqIPAddress.IncAddress(ACount: Integer);
var
i: Integer;
begin
for i := 3 downto 0 do
begin
Inc(FIPWord[i], ACount);
if FIPWord[i] > $FF then
begin
Dec(FIPWord[i], $100);
ACount := 1;
end
else
Break;
end;
end;procedure TcqIPAddress.SetIPAddress(const Value: string);
var
i: Integer;
begin
if FIPAddress <> Value then
begin
FIPAddress := Value;
StrToStrings(FIPAddress, '.', FIPs);
if FIPs.Count <> 4 then
raise Exception.Create('Invalid IP');
try
for i := 0 to 3 do
FIPWord[i] := StrToInt(FIPs[i]);
except
raise Exception.Create('Invalid IP');
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
a := TcqIPAddress.Create;
end;procedure TForm1.Button6Click(Sender: TObject);
begin
a.IPAddress := Edit1.Text;
end;procedure TForm1.Button7Click(Sender: TObject);
begin
a.IncAddress();
Edit1.Text := a.IPAddress;
end;