Result :=True ;
IdSMTP1.Host:='smtp.163.com';
IdSmtp1.Port:=24;//这是我故意让程序出错
statusbar1.SimpleText:='Connectting....';
try
IdSmtp1.Connect;//运行到此将会出现一个exception
except
on Exception do
begin
statusbar1.SimpleText:='Connected error';
result:=false;
end;
end;
if Result then
statusbar1.SimpleText:='Connection ready'
else
statusbar1.SimpleText:='Connected error';
end;
IdSMTP1.Host:='smtp.163.com';
IdSmtp1.Port:=24;//这是我故意让程序出错
statusbar1.SimpleText:='Connectting....';
try
IdSmtp1.Connect;//运行到此将会出现一个exception
except
on Exception do
begin
statusbar1.SimpleText:='Connected error';
result:=false;
end;
end;
if Result then
statusbar1.SimpleText:='Connection ready'
else
statusbar1.SimpleText:='Connected error';
end;
begin
try
IdSMTP1.Host:='smtp.163.com';
IdSmtp1.Port:=24;//这是我故意让程序出错
statusbar1.SimpleText:='Connectting....';
IdSmtp1.Connect;//运行到此将会出现一个exception
except
on Exception do
begin
statusbar1.SimpleText:='Connected error';
result:=false;
exit;
end;
end;
statusbar1.SimpleText:='Connection ready';
result:=true;
end;
应改为 出现异常的类型
但是IdSMTP中并无onConnectionFailed事件...to tccb(tccb);
能否说详细点,最好给点例子。
IdSMTP1.Host:='smtp.163.com';
IdSmtp1.Port:=24;//这是我故意让程序出错
statusbar1.SimpleText:='Connectting....';
IdSmtp1.Connect;//运行到此将会出现一个exception
except
statusbar1.SimpleText:='Connected error';
result:=false;
exit;
end;如果在 except END 中间出错,程序会立刻终止!一般,你即使不写TRY语句,出错也不会使整个程序崩溃,但如果在except END 中间出错,程序会立刻终止!所以建议你看看是不是这里错了。
我经过跟踪发现:
except
on Exception do
begin
statusbar1.SimpleText:='Connected error';
result:=false;
exit;
end;
end;
这段代码根本就没有执行!!!这是怎么回事?
procedure TForm1.Button1Click(Sender: TObject);
begin
NMSMTP1.Host:='smtp.163.com';
NMSMTP1.Port:=24;//这是我故意让程序出错
try
NMSMTP1.Connect;//运行到此将会出现一个exception
except
on e:Exception do
begin
showmessage(e.Message);
end;
end;
end;
在IDE中运行,结果IDE先报一个调试错误,然后出现一个对话框,完成正确。不知道兄弟你是什么原因?
NMSMTP1.Host:='smtp.163.com';
NMSMTP1.Port:=24;//这是我故意让程序出错
NMSMTP11.Connect;//运行到此将会出现一个exception
except
on e:exception do
showmessage(e.message);
end;
我没有IdSmtp1控件,我用NMSMTP控件,在IDE中测试,先是IDE 报一个调试错误,然后出现一个对话框,完全正确。不知你是什么原因。。
IdSMTP1.Host:='smtp.163.com';
IdSmtp1.Port:=24;//这是我故意让程序出错
statusbar1.SimpleText:='Connectting....';
try
IdSmtp1.Connect;//运行到此将会出现一个exception
except
on Exception do
begin
statusbar1.SimpleText:='Connected error';
result:=false;
end;
end;
if Result then
statusbar1.SimpleText:='Connection ready'
else
statusbar1.SimpleText:='Connected error';
end;