rvico TRichView Reference | TRichView

TCustomRichView.GetWordAt, GetWordAtW

Top  Previous  Next

Returns word at the specified coordinates

procedure GetWordAt(X,Y: Integer;

  var RVData: TCustomRVFormattedDatavar ItemNo: Integer; 

  var Word: String); overload;

function GetWordAt(X,Y: Integer): Stringoverload;

function GetWordAtW(X,Y: Integer): WideString

Input parameters

(X,Y) – client coordinates (coordinates relative to the top left corner of RichView window).

Output parameters

Word (or returned value for simplified versions) – receives word (if it is a text item), or name of non-text item. See the Unicode note below. "Word" is defined as a part of string between delimiters. Delimiters are listed in Delimiters property.

ItemNo – receives index of item at (X,Y), or -1 if there is no item at this point. This is an index of item in RVData object (this is may be the main document, cell, or cell inplace editor).

 

unicode Unicode note: the advanced version of GetWordAt is not recommended for Unicode applications. The simplified version of GetWordAt and GetWordAtW are recommended for Unicode applications.

The simplified version of GetWordAt always returns ANSI string:

If the item is a non-text item, or a text item of ANSI style, the text is returned as it is.
If the item is a Unicode text item, the function converts Unicode text to ANSI (Unicode text is converted basing on Charset of the item text style).

GetWordAtW always returns Unicode string:

If the item is a Unicode text item, the text is returned as it is.
If the item is a non-text item, or a text item of ANSI style, the function converts ANSI text to Unicode (ANSI text is converted basing on Charset of the item text style, or on RVStyle.DefCodePage for non-text items).

The advanced version of GetWordAt always returns ANSI string: the item text is returned as it is, without conversion, be careful.

 

For example, you can use this method inside OnRVMouseDown and OnRVMouseUp.

This method must be called only when the document is formatted.

 

Example: displaying the clicked words (only text items!) in Label1.

We cannot use simplified version of GetWordAt because we cannot know if the returned text is for text item.

This example does not work properly if document may contain Unicode text.

uses CRVFData;

...

procedure TForm1.RichView1RVMouseUp(Sender: TCustomRichView;

  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);

var

  LItemNo: Integer;

  LRVData: TCustomRVFormattedData;

  LWord: String;

begin

  ItemNo<0 then

    exit; // we already know that the mouse is not above item

  Sender.GetWordAt(X,Y, LRVData, LItemNo, LWord);

  if LItemNo<0 then

    exit;

  if LRVData.GetItemStyle(LItemNo)>=0 then // text item?

    Label1.Caption := LWord;

end;

 

Example: the same, but Unicode is supported

uses CRVFData;

...

procedure TForm1.RichView1RVMouseUp(Sender: TCustomRichView;

  Button: TMouseButton; Shift: TShiftState; ItemNo, X, Y: Integer);

var

  LItemNo, LStyleNo: Integer;

  LRVData: TCustomRVFormattedData;

  LWord: String;

begin

  ItemNo<0 then

    exit; // we already know that the mouse is not above item

  Sender.GetWordAt(X,Y, LRVData, LItemNo, LWord);

  if LItemNo<0 then

    exit;

  LStyleNo := LRVData.GetItemStyle(LItemNo);

  if LStyleNo>=0 then // text item?

  begin

    if Sender.Style.TextStyles[LStyleNo].Unicode then

      LWord :=RVU_UnicodeToAnsi(LRVData.GetStyleCodePage(LStyleNo), LWord);

    Label1.Caption := LWord;

  end;

end;

 

See also events:

OnRVMouseDown;
OnRVMouseUp;
OnRVRightClick;
OnRVDblClick.

See also properties:

Delimiters.

See also methods:

SelectWordAt


RichView © Sergey Tkachenko