Syntax 2 For RichTextEdit controls
Description
Determines the line and column position of the insertion point
or the start and end of selected text in an RichTextEdit control.
Controls
RichTextEdit and DataWindow controls
Syntax
|
1 |
<span>rtename</span>.<span>Position</span> ( <span>fromline</span>, <span>fromchar</span> {, <span>toline</span>, <span>tochar</span> } ) |
|
Argument |
Description |
|---|---|
|
rtename |
The name of the RichTextEdit or DataWindow |
|
fromline |
A long variable in which you want to |
|
fromchar |
A long variable in which you want to |
|
toline (optional) |
A long variable in which you want to |
|
tochar (optional) |
A long variable in which you want to |
Return Values
Band enumerated datatype. Returns the band (Detail!, Header!,
or Footer!) containing the selection or insertion point.
Usage
Position reports the position of the insertion point if you
omit the toline and tochar arguments.
If text is selected, the insertion point can be at the beginning or
the end of the selection. For example, if the user dragged down
to select text, the insertion point is at the end.
If there is a selection, a character argument can be set to
0 to indicate that the selection begins or ends at the start of
a line, with nothing else selected on that line. When the user drags
up, the selection can begin at the start of a line and fromchar is
set to 0. When the user drags down, the selection can end at the beginning
of a line and tochar is set to 0.
Selection or insertion point
To find out whether there is a selection or just an insertion
point, specify all four arguments. If toline and tochar are
set to 0, then there is no selection, only an insertion point. If
there is a selection and you want the position of the insertion
point, you will have to call Position again with only
two arguments. This difference is described next.
The position of the insertion point and end of selection can differ
When reporting the position of selected text, the positions
are inclusive—Position reports the first
line and character and the last line and character that are selected.
When reporting the position of the insertion point, Position identifies the
character just after the insertion point. Therefore, if text is
selected and the insertion point is at the end, the values for the
insertion point and the end of the selection differ.
To illustrate, suppose the first four characters in line 1
are selected and the insertion point is at the end. If you request
the position of the insertion point:
|
1 |
rte_1.Position(ll_line, ll_char) |
Then:
-
ll_line is
set to 1 -
ll_char is set to
5, the character following the insertion point
If you request the position of the selection:
|
1 |
rte_1.Position(ll_startline, ll_startchar, & |
|
1 |
   ll_endline, ll_endchar) |
-
ll_startline and ll_startchar are
both set to 1 -
ll_endline is 1 and ll_endchar is
set to 4, the last character in the selection
Passing values to SelectText
Because values obtained with Position provide
more information that simply a selection range, you cannot pass
the values directly to SelectText. In particular, 0 is not a valid
character position when selecting text, although it is meaningful
in describing the selection.
Examples
This example calls Position to
get the band and the line and column values for the beginning and
end of the selection. The values are converted to strings and displayed
in the StaticText st_status:
|
1 |
integer li_rtn |
|
1 |
long ll_startline, ll_startchar |
|
1 |
long ll_endline, ll_endchar |
|
1 |
string ls_s, ls_band |
|
1 |
band l_band |
|
1 |
|
1 |
// Get the band and start and end of the selection |
|
1 |
l_band = rte_1.<span>Position</span>(ll_startline, ll_startchar,& |
|
1 |
   ll_endline, ll_endchar) |
|
1 |
|
1 |
// Convert position values to strings |
|
1 |
ls_s = "Start line/char: " + String(ll_startline) & |
|
1 |
   + ", " + String(ll_startchar) |
|
1 |
ls_s = ls_s + " End line/char: " & |
|
1 |
   + String(ll_endline) + ", " + String(ll_endchar) |
|
1 |
|
1 |
// Convert Band datatype to string |
|
1 |
CHOOSE CASE l_band |
|
1 |
CASE Detail! |
|
1 |
   ls_band = " Detail" |
|
1 |
CASE Header! |
|
1 |
   ls_band = " Header" |
|
1 |
CASE Footer! |
|
1 |
   ls_band = " Footer" |
|
1 |
CASE ELSE |
|
1 |
   ls_band = " No band" |
|
1 |
END CHOOSE |
|
1 |
   ls_s = ls_s + ls_band |
|
1 |
|
1 |
// Display the information |
|
1 |
st_status.Text = ls_s |
This example extends the current selection down 1
line. It takes into account whether there is an insertion point
or a selection, whether the insertion point is at the beginning
or end of the selection, and whether the selection ends at the beginning
of a line:
|
1 |
integer rtn |
|
1 |
long l1, c1, l2, c2, linsert, cinsert |
|
1 |
long l1select, c1select, l2select, c2select |
|
1 |
|
1 |
// Get selectio start and end |
|
1 |
rte_1.<span>Position</span>(l1, c1, l2, c2) |
|
1 |
// Get insertion point |
|
1 |
rte_1.<span>Position</span>(linsert, cinsert) |
|
1 |
|
1 |
IF l2 = 0 and c2 = 0 THEN //insertion point |
|
1 |
   l1select = linsert |
|
1 |
   c1select = cinsert |
|
1 |
   l2select = l1select + 1 // Add 1 to end line |
|
1 |
   c2select = c1select |
|
1 |
|
1 |
ELSEIF l2 > l1 THEN // Selection, ins pt at end |
|
1 |
   IF c2 = 0 THEN // End of selection (ins pt) |
|
1 |
   // at beginning of a line (char 0) |
|
1 |
      c2 = 999 // Change to end of prev line |
|
1 |
      l2 = l2 - 1 |
|
1 |
   END IF |
|
1 |
|
1 |
   l1select = l1 |
|
1 |
   c1select = c1 |
|
1 |
   l2select = l2 + 1 // Add 1 to end line |
|
1 |
   c2select = c2 |
|
1 |
|
1 |
ELSEIF l2 < l1 THEN // selection, ins pt at start |
|
1 |
   IF c1 = 0 THEN // End of selection (not ins pt) |
|
1 |
   // at beginning of a line |
|
1 |
      c1 = 999 // Change to end of prev line |
|
1 |
      l1 = l1 - 1 |
|
1 |
   END IF |
|
1 |
   l1select = l2 |
|
1 |
   c1select = c2 |
|
1 |
   l2select = l1 + 1 // Add 1 to end line |
|
1 |
   // (start of selection) |
|
1 |
   c2select = c1 |
|
1 |
|
1 |
ELSE // l1 = l2, selection on one line |
|
1 |
   l1select = l1 |
|
1 |
   l2select = l2 + 1 // Add 1 to line |
|
1 |
   IF c1 < c2 THEN // ins pt at end |
|
1 |
      c1select = c1 |
|
1 |
      c2select = c2 |
|
1 |
   ELSE // c1 > c2, ins pt at start |
|
1 |
      c1select = c2 |
|
1 |
      c2select = c1 |
|
1 |
   END IF |
|
1 |
END IF |
|
1 |
|
1 |
// Select the extended selection |
|
1 |
rtn = rte_1.SelectText( l1select, c1select, & |
|
1 |
   l2select, c2select ) |
For an example of selecting each word in a RichTextEdit control,
see SelectTextWord.