I''ve looked through the help file but can't find a direct answer to some bqasic questions. I have a small read-only TRichViewEdit with text inserted and cleared programmatically.
1. How can I check if the editor is empty (has no text)? In other words, what's the equivalent of TMemo.Lines.Count=0 ?
2. How can I get all text from the editor without selecting it and without using clipboard? I.e., the equivalent of stringVar := TMemo.Lines.Text.
(The editor contains only text and I need to retrieve it as a plain-text string, without any formatting).
3. How can I select text if I know only the offset, i.e. the equivalent of TMemo.SelStart := x and TMemo.SelLength := y?
4. How can I toggle wrapping lines? (Can line wrapping be turned off?)
Thanks a lot,
.marek
(registered user)
Very basic questions
Hi Marek,
RV->ItemCount == 1 && RV->GetItemStyle(0) >= 0 && RV->GetItemText(0).IsEmpty()
An "empty" RV still contains a single empty text item (as do table cells).
HTH,
Michel
I'm using the following condition:1. How can I check if the editor is empty (has no text)? In other words, what's the equivalent of TMemo.Lines.Count=0 ?
RV->ItemCount == 1 && RV->GetItemStyle(0) >= 0 && RV->GetItemText(0).IsEmpty()
An "empty" RV still contains a single empty text item (as do table cells).
Take a look at GetAllText().2. How can I get all text from the editor without selecting it and without using clipboard? I.e., the equivalent of stringVar := TMemo.Lines.Text.
(The editor contains only text and I need to retrieve it as a plain-text string, without any formatting).
Check out the RVLinear unit. RVSetSelection() should do the trick.3. How can I select text if I know only the offset, i.e. the equivalent of TMemo.SelStart := x and TMemo.SelLength := y?
I think you may need to set MinTextWidth to a very large number to make a large "virtual margin". Check the "Scrolling in RichView" Help topic. I've never tried this though.4. How can I toggle wrapping lines? (Can line wrapping be turned off?)
HTH,
Michel
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Thanks, Michel.
Some additional information.
from RVGetText unit,
or
function RVGetTextRange(rv: TCustomRichView; RangeStart, RangeLength: Integer): String;
function RVGetTextLength(rv: TCustomRichView): Integer;
from RVLinear:
s := RVGetTextRange(rv, 0, RVGetTextLength(rv));
Use RVGetText if you want to display this text to the user.
RVGetTextRange may be useful if you need a one-to-one correspondence between TRichView and the text string. It is compatible with the following functions from the same unit:
function RVGetLinearCaretPos(rve: TCustomRichViewEdit): Integer;
procedure RVSetLinearCaretPos(rve: TCustomRichViewEdit; LinearPos: Integer);
procedure RVGetSelection(rv: TCustomRichView; var SelStart, SelLength: Integer);
procedure RVSetSelection(rv: TCustomRichView; SelStart, SelLength: Integer);
I.e. SelStart&SelLength may be used as indices in the string returned by RVGetTextRange (but SelStart is counted from 0, and string indices are counted from 1.
Some additional information.
function GetAllText(rv: TCustomRichView): String;How can I get all text from the editor without selecting it and without using clipboard
from RVGetText unit,
or
function RVGetTextRange(rv: TCustomRichView; RangeStart, RangeLength: Integer): String;
function RVGetTextLength(rv: TCustomRichView): Integer;
from RVLinear:
s := RVGetTextRange(rv, 0, RVGetTextLength(rv));
Use RVGetText if you want to display this text to the user.
RVGetTextRange may be useful if you need a one-to-one correspondence between TRichView and the text string. It is compatible with the following functions from the same unit:
function RVGetLinearCaretPos(rve: TCustomRichViewEdit): Integer;
procedure RVSetLinearCaretPos(rve: TCustomRichViewEdit; LinearPos: Integer);
procedure RVGetSelection(rv: TCustomRichView; var SelStart, SelLength: Integer);
procedure RVSetSelection(rv: TCustomRichView; SelStart, SelLength: Integer);
I.e. SelStart&SelLength may be used as indices in the string returned by RVGetTextRange (but SelStart is counted from 0, and string indices are counted from 1.
Use RVGetSelection and RVSetSelection from RVLinear unit (see above)How can I select text if I know only the offset, i.e. the equivalent of TMemo.SelStart := x and TMemo.SelLength := y?
By including rvpaoNoWrap in all paragraph styles:How can I toggle wrapping lines? (Can line wrapping be turned off?)
Code: Select all
for i := 0 to RVStyle1.ParaStyles.Count-1 do
RVStyle1.ParaStyles[i].Options := RVStyle1.ParaStyles[i].Options+[rvpaoNoWrap];
RichView1.Reformat;