给你一个我做的例子;
procedure Tform1.Comm1ReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
begin
SetLength(s, BufferLength);
Move(Buffer^, pchar(s)^, BufferLength);
edit2.text:=s;
end;
procedure Tform1.BitBtn1Click(Sender: TObject);
begin
comm1.WriteCommData(pchar(edit1.text),length(edit1.text));
end;
procedure Tform1.BitBtn2Click(Sender: TObject);
begin
comm1.commname:=combobox1.Text;
comm1.StartComm;
comm1.BaudRate:=strtoint(combobaudrate.Text);
case combodatabits.ItemIndex of
0:comm1.ByteSize:=_5;
1:comm1.ByteSize:=_6;
2:comm1.ByteSize:=_7;
3:comm1.ByteSize:=_8;
end;
case combostopbits.ItemIndex of
0:comm1.stopbits:=_1;
1:comm1.stopbits:=_1_5;
2:comm1.stopbits:=_2;
end;
case comboparity.ItemIndex of
0:comm1.Parity:=None;
1:comm1.Parity:=Odd;
2:comm1.Parity:=Even;
3:comm1.Parity:=Mark;
4:comm1.Parity:=Space;
end;
if comboparity.ItemIndex=0 then comm1.ParityCheck:=false
else comm1.paritycheck:=true;
BitBtn2.Enabled:=false;
end;
procedure Tform1.BitBtn3Click(Sender: TObject);
begin
comm1.StopComm;
BitBtn2.Enabled:=true;
end;
procedure Tform1.Button1Click(Sender: TObject);
begin
edit1.Clear;
edit2.clear;
end;