ThbComPort.OnReceive
Unit: hbComm
 

The OnReceivea event occurs when data has been received from the communications port and is stored in the receive queue waiting to be handled.

Availability

Design-Time: Read, Write / Run-Time: Read, Write

Declaration

procedure OnReceive(Sender: TObject; Count: Integer);
property OnReceive: ThbComPortCountEvent;

Remarks

Windows does not guarantee to send a message for every character received, especially at higher baud rates. Therefore, the best plan is to use the OnReceive handler to process all the data that is currently in the receive queue, using successive calls to Read or ReadStr until the queue is empty.

Example 1

procedure TForm1.hbComPort1OnReceive(Sender: TObject; Count: Integer);
var
  s : String;
begin
  s := hbComPort1.ReadStr(Count); // or hbComPort1.ReadStr;
  { process data ... }
end;

Example 2

procedure TForm1.hbComPort1OnReceive(Sender: TObject; Count: Integer);
var
  s : String;
begin
  SetLength(s, Count);
  hbComPort1.Read(S[1], Count);
  { process data ... }
end;