|
TCustomRichView.GetWordAt, GetWordAtW |
Top Previous Next |
|
Returns word at the specified coordinates procedure GetWordAt(X,Y: Integer; var RVData: TCustomRVFormattedData; var ItemNo: Integer; var Word: String); overload; function GetWordAt(X,Y: Integer): String; overload; 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).
The simplified version of GetWordAt always returns ANSI string:
GetWordAtW always returns Unicode string:
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: See also properties: See also methods: |