spcomm 组件的数据接收,如何做成基于过程接收而不是基于事件接收,谁有好的处理方法,或者给出一个mmscomm组建的使用例子

解决方案 »

  1.   

    没试过,要不改spcomm的源码,要不就换控件,至于例子,网上很多,哪个控件的都有
      

  2.   

    下面是一接收程序的样例(主要部分),大家可根据实际需要进行完善。
      在Form中放置一Memo控件用于显示接收的数据,Combobox1选择通信参数(Setting属性值),Combobox2选择串口(CommPort属性值),按Button1开始接收数据,按Button2停止接收。
      procedure TForm1.FormCreate(Sender: TObject);
      begin
      Mscomm1.InBufferCount :=0; // 清空接收缓冲区
      Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
      Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
      end;
      procedure TForm1.Button1Click(Sender: TObject);
      begin
      Mscomm1.Settings :=ComboBox1.Text;
      if ComboBox2.Text =′com1′ then // 假设只考虑COM1和COM2两种情况
      Mscomm1.CommPort :=1
      else
      Mscomm1.CommPort :=2;
      Mscomm1.PortOpen :=true; // 打开串口
      Mscomm1.DTREnable :=true; // 数据终端准备好
      Mscomm1.RTSEnable :=true; // 请求发送
      end;
      procedure TForm1.Button2Click(Sender: TObject);
      begin
      Mscomm1.PortOpen :=false; // 关闭串口
       Mscomm1.DTREnable :=false;
      Mscomm1.RTSEnable :=false;
      end;
      procedure TForm1.MSComm1Comm(Sender: TObject);
      var
      recstr:Olevariant;
      begin
       if Mscomm1.CommEvent = 2 then
      begin
      recstr := Mscomm1.Input ;
      Memo1.text := Memo1.Text + recstr;
      end;
      end; (江西 万雪勇)