procedure Tipsq_Form.Button1Click(Sender: TObject);
var ip1,ip2,ip3,ip4,ip,sqlstr:string;
    ipa,ipb,ipc,ipd:integer;
begin
  ip1:=Trim(ip1_Edit.Text);
  ip2:=Trim(ip2_Edit.Text);
  ip3:=Trim(ip3_Edit.Text);
  ip4:=Trim(ip4_Edit.Text);
  ipa:=StrToInt(Trim(ip1_Edit.Text));
  ipb:=StrToInt(Trim(ip2_Edit.Text));
  ipc:=StrToInt(Trim(ip3_Edit.Text));
  ipd:=StrToInt(Trim(ip4_Edit.Text));
  //判断ip合法性··············
  if ipa<1 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipa>254 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipb<1 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipb>254 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipc<1 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipc>254 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipd<1 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
  if ipd>254 then
  begin
    ShowMessage('请输入正确的IP!');
    exit;
  end;
end;
我这样判断输入的是不是IP地址不可以吗?四个Edit框,分别判断输入的范围是否为0—255;
运行后点击确定没反应···⊙﹏⊙b汗

解决方案 »

  1.   

    我给你一个方法判断是否是正确的IP地址:function IsValidIP(const IP: string): Boolean;
    {
      判断字符串IP是否是一个合法的IP地址(不验证是否可以访问得到)
      是,返回True,否则返回False
    }
    var
      Ar: TStringDynArray;
      i: integer;
    begin
      Result := False;
      Ar := SplitString(IP, '.');
      if Length(Ar) <> 4 then Exit;
      for i := Low(Ar) to High(Ar) do
      try
        if not (StrToInt(Ar[i]) in [0..255]) then Exit;
      except
        Exit;
      end;
      Result := True;
    end;
      

  2.   


    var
     IPa:set of '0'..'255'; 
     IPb:set of '0'..'255';
     IPc:set of '0'..'255';
     IPd:set of '0'..'255';
    begin
     ip1:=Trim(ip1_Edit.Text);
     ip2:=Trim(ip2_Edit.Text);
     ip3:=Trim(ip3_Edit.Text);
     ip4:=Trim(ip4_Edit.Text);
     if (not (ip1 in IPa)) or (not (ip2 in IPb)) or( not (ip3 in IPc)) or (not (ip4 in IPd)) then
     begin
       ShowMessage('请输入正确的IP!');
     end;   
    end;
    思路大概这样,应该可行
      

  3.   

    即uses上winsock单元if (inet_addr(pchar(your_ip_var_str)=-1) then
      shomessage('no') else shomessage('yes');
      

  4.   

    少了一个括号,应该是(inet_addr(pchar(your_ip_var_str)) = -1)
      

  5.   


    var
     IPa:set of '0'..'255'; 
     IPb:set of '0'..'255';
     IPc:set of '0'..'255';
     IPd:set of '0'..'255';这样定义集合貌似不行吧····(╯3╰)
      

  6.   


    implementation
    uses winsock_unit
    if (inet_addr(pchar(Trim(ip1_Edit.Text))=-1) then
    shomessage('no') 
    else 
    shomessage('yes'); dinoalex   是这样用吗?···(inet_addr(pchar(your_ip_var_str)) = -1) //这句是啥意思?
    我菜鸟····不好意思···~~~~(>_<)~~~~ ··
      

  7.   

    是这样用,请参考 http://msdn.microsoft.com/en-us/library/ms738563(VS.85).aspx如果转换不成功,即返回-1
      

  8.   

    应该是winsock吧,难道你的DELPHI版本里的是winsock_unit??