接收事件中:我原来的代码是这样var
  tmp:string;
begin
  move(buffer^,tmp,bufferlength);
  memo1.lines.add(tmp);
end;程序报错,请问我该怎么写?接收到的应该就是普通字符串
一般情况下是怎么写的啊?

解决方案 »

  1.   

    Spcomm串口控件的例程
    //串口初始化           procedure TForm1.BitBtn3Click(Sender: TObject);
                begin
                   comm1.startcomm;
                end;
                  //关闭串口
                procedure TForm1.BitBtn4Click(Sender: TObject);
                begin
                   comm1.StopComm;
                end;
                //发送数据
                procedure TForm1.BitBtn1Click(Sender: TObject);{var str:string;
                    ch1:char;
                begin
                comm1.WriteCommData(ch,1);
                end.
                //接收数据
                procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
                  BufferLength: Word);
                type   ss=array[1..500]of char ;
                var    str1:^ss;
                       i:integer;
                       s:array[0..15] of char ;
                       n:integer;
                begin
                       str1:=Buffer;
                     //s[]=('0','1','2','3'...'E')
                       for i:=0 to 9 do
                       s[i]:=chr(48+i);
                       for i:=10 to 15 do
                       s[i]:=chr(55+i);
                       for i:=1 to bufferlength do
                       begin
                       n:=ord(str1^[i]);
                       listbox1.Items.add(
                                 inttostr(listbox1.Items.Count+1)
                                 +' - '+s[n div 16]+s[n mod 16]);
                       end;
                       listbox1.Refresh;
                      if listbox1.Items.count > strtoint(form2.edit1.text)
                      then listbox1.Items.Clear;
                end;
      

  2.   

    var
      Recbuff:array of byte; setlength(Recbuff, BufferLength);
     move(buffer,recbuff, BufferLength);
      

  3.   

    procedure TForm1.Comm2ReceiveData(Sender: TObject; Buffer: Pointer;
      BufferLength: Word);
    var
      str:string;
    begin
      setlength(str,bufferlength);
      move(buffer^,pchar(str)^,bufferlength);
      memo1.Lines.Add(str);
    end;