我先在全局里定义了一个mscomm:
comm:TMSComm;
然后用函数初始化并打开它:
if not Assigned(comm) then
        comm:=TMSComm.Create(nil);
comm.CommPort:= 1;  
comm.Settings:= '9600,n,8,1';
comm.PortOpen:= true;  
comm.InputLen:=0;
comm.SThreshold := 1;
comm.NullDiscard:=false;然后我要定义一个函数,使得它成为comm的OnComm事件,该怎么定义实现?

解决方案 »

  1.   

    mscomm1.oncomm = MyFunction(MyFunction是自己定义的函数),这样就能把oncomm事件内的代码映射到自己的函数里面了
      

  2.   

    主要是这个
    MyFunction(MyFunction是自己定义的函数)我不知道怎么定义,老是报错啊
      

  3.   

    帮人帮到底。procedure   TForm1.FormCreate(Sender:   TObject);   
      var   
          Mscomm1:TMSComm;   
      begin   
          Mscomm1:=TMSComm.Create();   
          Mscomm1.InBufferCount   :=0;   //   清空接收缓冲区   
          Mscomm1.InputLen   :=0;   //   Input读取整个缓冲区内容   
          Mscomm1.RThreshold   :=1;   //   每次接收到字符即产生OnComm事件  
          MsComm1.OnComm:=ComGetData; 
      end;   
        
      procedure   TForm1.ComGetData(Sender:TObject);     
      begin     
          if   (sender   is   TMSComm)   then   
                if   (sender   is   TMSComm).CommEvent   =   2   then     
                Memo1.text:=Memo1.Text+(sender   is   TMSComm).Input;   
      end;     
      

  4.   

    if (sender is TMSComm).CommEvent = 2 then
    光标处于.后面,报错:record,object or class type required.
      

  5.   

    if (sender is TMSComm).CommEvent = 2 then这句应该是 if (sender as TMSComm).CommEvent = 2 then吧. "is"的话返回的肯定是boolean类型,它不是一个类或者记录...
      

  6.   

    同意楼上的修改成procedure TForm1.FormCreate(Sender: TObject);
    var
      Mscomm1:TMSComm;
    begin
      Mscomm1:=TMSComm.Create(nil);
      Mscomm1.InBufferCount :=0; // 清空接收缓冲区
      Mscomm1.InputLen :=0; // Input读取整个缓冲区内容
      Mscomm1.RThreshold :=1; // 每次接收到字符即产生OnComm事件
      MsComm1.OnComm:=ComGetData;
    end;procedure TForm1.ComGetData(Sender:TObject);
    begin
      if (sender is TMSComm) then
      if (Sender as TMSComm).CommEvent = 2 then
      Memo1.text:=Memo1.Text+(sender as TMSComm).Input;
    end;