怎样在INPUTBOX里检测,所输入的IP地址是否正确(0分)

  • 主题发起人 topdelphi
  • 开始时间
T

topdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样在INPUTBOX里检测,所输入的IP地址是否正确,如果不是,就提示,我的代码如下,
我的功能是要判断,输入的是不是IP地址格式,还是输入的IP是否符合要求请教如何修改。
procedure TForm1.N2Click(Sender: TObject);
begin
try
if clientsocket1.Active then
clientsocket1.Active :=false;
if inputquery('请输入计算机地址','address name:',server) then
if length(server)>0 then
with clientsocket1 do
begin
host:=server;
active:=true;
n2.Checked :=false;
end;
except
beep;
showmessage('连接类型出错,或地址不正确');

end;
end;
 
function InputIP(var asIPAddr: string): Boolean;
var
frmInput: TForm;
hIPEdit: HWND;
begin
frmInput := CreateMessageDialog('请输入IP地址:', mtInformation, [mbOK, mbCancel]);
with frmInput do
try
Caption := 'IP地址输入窗口';
Width := 300;
Height := 110;
with TButton(Components[2]) do
begin
Left := 150;
Top := 23;
Width := 80;
Caption := '确定';
Left := Left + 50;
TabOrder := 2;
end;

with TButton(Components[3]) do
begin
Left := 150;
Top := 50;
Width := 80;
Caption := '取消';
Left := Left + 50;
TabOrder := 3;
end;

{IPEdit1 := TIPEdit.Create(frmInput);
with IPEdit1 do
begin
Parent := frmInput;
ParentWindow := TButton(Components[3]).ParentWindow;
Name := 'ipEdit1';
SetBounds(56, 32, 130, 23);
Visible := True;
TabOrder := 1;
SetFocus;
end;}
InitCommonControl(ICC_INTERNET_CLASSES);
hIPEdit := CreateWindow(WC_IPADDRESS, nil, WS_TABSTOP or WS_CHILD or WS_VISIBLE, 56, 32, 130, 23, Handle, 0, hInstance, nil);
Windows.SetFocus(hIPEdit);

Result := ShowModal = IDOK; //mrOK; IDCANCEL; IDYES
if Result then
begin
SetLength(asIPAddr, 15);
GetWindowText(hIPEdit, pChar(asIPAddr), 15);
end;
finally
Free;
end;
end;
 
先生首先谢谢你的代码,但是你的代码创建了这个多的窗体按钮控件,而且有很多不懂的地方
而且在调用的时候,INPUTIP时也需要参数,请问这个参数是什么的参数,
可以加点注释嘛,还有下面几行代码是注释掉的,请问真的没用吗,而且有两句运行时出错

{IPEdit1 := TIPEdit.Create(frmInput);
with IPEdit1 do
begin
Parent := frmInput;
ParentWindow := TButton(Components[3]).ParentWindow;
Name := 'ipEdit1';
SetBounds(56, 32, 130, 23);
Visible := True;
TabOrder := 1;
SetFocus;
end;}

//下面两句是运行时出错,
InitCommonControl(ICC_INTERNET_CLASSES);
hIPEdit := CreateWindow(WC_IPADDRESS, nil, WS_TABSTOP or WS_CHILD or WS_VISIBLE, 56, 32, 130, 23, Handle, 0, hInstance, nil);
 
顶部