procedure TForm1.BitBtn2Click(Sender: TObject); //"局域网"按钮的单击事件 begin FileAppendProc1(); RadioButton2.Checked:=true; end;
procedure TForm1.FileAppendProc1(); //保存文件的函数 var NetFile : TextFile; NetFilename : string; FileAppend,tempStr : string; begin NetFilename :='netcfg2.txt'; FileAppend :=S5+MaskEdit1.Text+S1+MaskEdit2.Text+S2+MaskEdit3.Text+S3+S4; //MessageDlg('This is commend'+FileAppend,mtInformation,[mbOK],0); AssignFile(Netfile,'net.txt'); //net.txt文件要放在应用程序的同一目录中 Reset(NetFile); begin try Memo1.Lines.Text:=''; while not Eof(NetFile) do begin Readln(NetFile,tempStr); Memo1.Lines.Add(tempStr) ; end; finally begin CloseFile(NetFile); end; end; AssignFile(Netfile,NetFilename); Rewrite(NetFile); try Writeln(NetFile,''); finally CloseFile(NetFile); end; Memo1.Lines.Add(FileAppend); Memo1.Lines.SaveToFile(NetFilename); end; end;
procedure TForm1.MaskEdit1Exit(Sender: TObject); //IP地址输入出错处理 var ip1,ip2,ip3,ip4: Integer; begin if (copy(MaskEdit1.Text,1,3)=' ') or (copy(MaskEdit1.Text,5,3)=' ') or (copy(MaskEdit1.Text,9,3)=' ') or (copy(MaskEdit1.Text,13,3)=' ') then begin showmessage('请注意,不能有空域值') ; MaskEdit1.SetFocus; end; if (copy(MaskEdit1.Text,1,3)<>' ') and (copy(MaskEdit1.Text,5,3)<>' ') and (copy(MaskEdit1.Text,9,3)<>' ') and (copy(MaskEdit1.Text,13,3)<>' ') then begin ip1:=strtoint(trim(copy(MaskEdit1.Text,1,3))); ip2:=strtoint(trim(copy(MaskEdit1.Text,5,3))); ip3:=strtoint(trim(copy(MaskEdit1.Text,9,3))); ip4:=strtoint(trim(copy(MaskEdit1.Text,13,3))); if (ip1<0) or (ip1>254) or (ip2<0) or (ip2>254) or(ip3<0) or (ip3>254) or (ip4<0) or (ip4>254) then begin showmessage('您的输入不正确,请重新输入!'); MaskEdit1.SetFocus; end; end; end; |