上面有点问题,应该恢复初始状态:
function IsOpened(Comm: TComm):Boolean;
begin
result:= false;
try
Comm.StartComm;
except
on E: ECommsError do
if E.Message= 'This serial port already opened'
then begin
result:= true;
end;
end;
if not result
then begin
Comm.StopComm;
end;
end;
自己截获异常:
function IsOpened;
begin
result:= false;
try
Comm1.StartComm;
except
on E: ECommsError do
if E.Message= 'This serial port already opened'
then result:= true;
end;
end;