spcomm发送和接受的代码 高手指点!!!!
procedure TForm1.Button1Click(Sender: TObject);
begin
senddata(edit1.text); 发送edit1中的字符串
edit2.Text :=recdata; 接受到的字符串显示在edit2中
procedure senddata(s:string); 发送函数没有问题
var comandstr:string;
begin
comandstr:=s+char(13);
form1.comm1.writecommdata(pchar(ComandStr),length(ComandStr));
end;
procedure TForm1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;接受函数 edit2不能显示收到的字符串 BufferLength: Word);
begin
move(Buffer^, PChar(@RecData[1])^, BufferLength);
end;
[解决办法]
SetLength(RecData,BufferLength);move(Buffer^, PChar(@RecData[1])^, BufferLength);edit2.text:=RecData