我的程序需要拦截MSComm错误代码,并转换成中文,怎么实现呢?请大家多多指教!
比如说;我的com端口未打开,系统会弹出一个对话框,opration valid only when the port is open;现在,我需要拦截此消息,并转换成中文,“仅当端口打开时操作才有效”,怎么实现呢?最好给我简单代码。
还有,这个错误代码值是8018,SMComm.commevent = 8018 ,是这样表示吗?

解决方案 »

  1.   

    就是捕捉系统异常吧?try
       ...
    except
       on E:Exception do
          showmessage(e.Message);
       end;...是你执行的语句
      

  2.   

    try 
      ... 
    except 
      on E:Exception do 
         begin
         if e.message='xxxxxxx' then
            showmessage('yyyyyy');
         end;
      end; 也可以直接根据Exception的类型判断
    比如串口被占用时会跳出个系统提示框,里面有 ... raised exception class EcommsError with message.....
    那你就
    try 
      ... 
    except 
      on E:EcommsError do 
         showmessage('yyyyyy');
      end; 
      

  3.   

    一个一个修改啊。
    找找MSComm错误代码的位置
      

  4.   

    skylkj,多谢,问题已解决,接分。