Synchronizing cursor position in RTF text

  • I try to have the text spoken by the SAPI 5.3 component TSPVoice. I feed the component with WPRichText.AsAnsiString('ANSI') and it speaks. I then want the spoken word to be highlighted and use the component's OnWord event like this:

    procedure TForm1.SPVoiceWord(ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant; CharacterPosition, Length: Integer);
    begin
    with WPRichText do
    begin
    SelStart := CharacterPosition;
    SelLength := Length;
    // or alternatively SelectWord;
    end;
    end;

    The problem is after a word contains a bookmark or a hyperlink, CharacterPosition is no longer equal to the cursor position; the cursor lags behind.

    Any ideas on how I can solve this problem?