rvico TRichView Reference | TRichView

TCustomRichView.GetWordAt, GetWordAtA, GetWordAtW

Top  Previous  Next

Returns word at the specified coordinates

procedure GetWordAt(X,Y: Integer;

  out RVData: TCustomRVFormattedDataout ItemNo: Integer; 

  out Word: TRVUnicodeString); overload;

function GetWordAtA(X,Y: Integer): TRVAnsiString;

function GetWordAtW(X,Y: Integer): TRVUnicodeString

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

(changed in version 18)

Input parameters

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

Output parameters

Word (or returned value for the 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 (it may be the main document, cell, or cell inplace editor).

 

unicode Unicode notes:

Internally, all text is stored as Unicode. GetWordAtA converts it to ANSI using Style.DefCodePage.

GetWordAt returns:

ANSI string, like GetWordAtA, in Delphi 2007 and older

Unicode (UTF-16) string, like GetWordAtW, in Delphi 2009 and newer

Unicode (UTF-8) string, in Lazarus

 

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.

uses CRVFData;

...

procedure TForm1.RichView1RVMouseUp(Sender: TCustomRichView;

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

var

  LItemNo: Integer;

  LRVData: TCustomRVFormattedData;

  LWord: TRVUnicodeString;

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;

 

See also events:

OnRVMouseDown;

OnRVMouseUp;

OnRVRightClick;

OnRVDblClick.

See also properties:

Delimiters.

See also methods:

SelectWordAt


TRichView © trichview.com