
procedure TComThread.Execute;
  repeat
    // wait for event to occur on serial port
    WaitCommEvent(FComPort.Handle, Mask, @Overlapped);
    Signaled := WaitForMultipleObjects(2, @EventHandles, False, INFINITE);
    // if event occurs, dispatch it
    if (Signaled = WAIT_OBJECT_0 + 1)
      and GetOverlappedResult(FComPort.Handle, Overlapped, BytesTrans, False)
    then
    begin
      FEvents := IntToEvents(Mask);
      <b>DispatchComMsg</b>;
<hr>

procedure TComThread.DispatchComMsg;
begin
  case FComPort.SyncMethod of
    smThreadSync: Synchronize(<b>DoEvents</b>); // call events in main thread
    smWindowSync: SendEvents; // call events in thread that opened the port
    smNone:       <b>DoEvents</b>; // call events inside monitoring thread
  end;
end;
<hr>

procedure TComThread.DoEvents;
begin

  if evError in FEvents then
    FComPort.<B>CallError</b>;

end;
<hr>


procedure TCustomComPort.CallError;
begin
  DoError(<b>LastErrors</b>);
end;
<hr>

function TCustomComPort.LastErrors: TComErrors;
  if not <b>ClearCommError</b>(FHandle, Errors, @ComStat) then
    raise EComPort.Create(CError_ClearComFailed, GetLastError);
  Result := [];
  if ((CE_RXPARITY and Errors) <> 0) and FParity.Check then // get around a bug
    Result := Result + [ceRxParity];
