|
楼主 |
发表于 2014-3-19 15:44:31
|
显示全部楼层
comeheres 发表于 2014-3-18 19:03
应该是哪个StrToInt转换出现,把非数字的字符串进行转换了,因为EConvertError是字符串对象转换错误异常类
(开始时把每一个StrToInt部分都用Try...Expect来捕捉没有作用,然后我把每个部分都加提示类捕捉(下面代码蓝色部分)都没有任何效果,请高手指点一下,先谢了)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, ComCtrls, ScktComp;
type
TForm1 = class(TForm)
img1: TImage;
lbl1: TLabel;
edt1: TEdit;
lbl2: TLabel;
edt2: TEdit;
lbl3: TLabel;
edt3: TEdit;
lbl4: TLabel;
edt4: TEdit;
pnl1: TPanel;
pnl2: TPanel;
pnl3: TPanel;
lst1: TListBox;
pb1: TProgressBar;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
tmr1: TTimer;
clntsckt1: TClientSocket;
procedure FormCreate(Sender: TObject);
procedure pnl2Click(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
procedure pnl3Click(Sender: TObject);
procedure clntsckt1Connect(Sender: TObject; Socket: TCustomWinSocket);
procedure clntsckt1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure pnl1Click(Sender: TObject);
procedure clntsckt1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
img1.Top:=0;
img1.Left:=0;
end;
procedure TForm1.pnl2Click(Sender: TObject);
begin
try
if Edt1.Text = '' then
showmessage('请输入IP')
else if Edt2.Text = '' then
showmessage('请输入端口')
else if Edt3.Text = '' then
showmessage('请输入端口')
else if Edt4.Text = '' then
showmessage('请输入扫描速率')
else
begin
if pnl2.Caption = '停止' then
begin
tmr1.Enabled:= False;
clntsckt1.Port:= StrToInt(Edt2.Text);
pnl2.caption:= '扫描';
pb1.step:= 0;
edt1.enabled:= True;
Edt2.enabled:= True;
Edt3.enabled:= True;
Edt4.Enabled:= True;
pnl2.Color:= clNavy;
pnl1.visible:= False;
end
else
begin
pb1.StepBy(-(StrToInt(Edt3.Text)));
Clntsckt1.Port:= StrToInt(Edt2.Text);
Lst1.Items.Clear;
Lbl7.caption:= Edt2.Text;
pb1.Min:= 0;
pb1.Max:= ((StrToInt(Edt3.Text))-(StrToInt(Edt2.Text)));;
Tmr1.Interval:= StrToInt(Edt4.Text);
Edt1.enabled:= False;
Edt2.enabled:= False;
Edt3.enabled:= False;
Edt4.Enabled:= False;
Tmr1.Enabled:= True;
Pnl2.Caption:= '停止';
Pnl2.Color:= clRed;
end;
end;
except
on ECONVERTERROR do
showmessage('这里出错1');
end;
end;
procedure TForm1.tmr1Timer(Sender: TObject);
var
s,d:Integer;
begin
try
if clntsckt1.Port = StrToInt(Edt3.Text) then
begin
Tmr1.Enabled:= False;
Pnl2.Caption:= '扫描';
Edt1.enabled:= True;
Edt2.enabled:= True;
Edt3.enabled:= True;
Edt4.Enabled:= True;
Pnl2.Color:= clNavy;
Pnl1.visible:= False;
end
else
begin
if clntsckt1.Port = StrToInt(lbl7.caption) then
begin
d:= clntsckt1.Port + 1;
lbl7.Caption:= IntToStr(d);
s:= StrToInt(lbl7.caption);
clntsckt1.address:= Edt1.Text;
clntsckt1.Port:= s;
clntsckt1.open;
pnl3.Visible:= True;
pb1.StepBy(1);
end;
end;
except
on ECONVERTERROR do
showmessage('这里出错2');
end;
end;
procedure TForm1.pnl3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.clntsckt1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
try
lst1.Items.Add('Port:' + IntToStr(clntsckt1.port));
clntsckt1.Close;
if Edt3.Text = Lbl7.Caption then
Tmr1.Enabled:= False;
except
on ECONVERTERROR do
showmessage('这里出错3');
end;
end;
procedure TForm1.clntsckt1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
tmr1.Enabled:= True;
end;
procedure TForm1.pnl1Click(Sender: TObject);
begin
try
if Pnl1.Caption = '恢复扫描' then
begin
Tmr1.Enabled:= True;
if Tmr1.Enabled = True then
Pnl1.caption:= '暂停扫描';
Pnl3.Color:= clyellow;
end
else
begin
Tmr1.Enabled:= False;
Pnl3.caption:= '恢复扫描';
Pnl3.Color:= cllime;
pb1.step:= 0;
end;
except
on ECONVERTERROR do
showmessage('这里出错4');
end;
end;
procedure TForm1.clntsckt1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
try
ErrorCode:=0;
except
on ECONVERTERROR do
showmessage('这里出错5');
end;
end;
end.
|
|