Page 1 of 1

Very basic questions

Posted: Thu Nov 03, 2005 11:28 pm
by marekjed
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)

Posted: Fri Nov 04, 2005 1:07 pm
by Michel
Hi Marek,
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 ?
I'm using the following condition:
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).
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).
Take a look at GetAllText().
3. How can I select text if I know only the offset, i.e. the equivalent of TMemo.SelStart := x and TMemo.SelLength := y?
Check out the RVLinear unit. RVSetSelection() should do the trick.
4. How can I toggle wrapping lines? (Can line wrapping be turned off?)
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.

HTH,

Michel

Posted: Fri Nov 04, 2005 7:48 pm
by Sergey Tkachenko
Thanks, Michel.

Some additional information.
How can I get all text from the editor without selecting it and without using clipboard
function GetAllText(rv: TCustomRichView): String;
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.
How can I select text if I know only the offset, i.e. the equivalent of TMemo.SelStart := x and TMemo.SelLength := y?
Use RVGetSelection and RVSetSelection from RVLinear unit (see above)
How can I toggle wrapping lines? (Can line wrapping be turned off?)
By including rvpaoNoWrap in all paragraph styles:

Code: Select all

for i := 0 to RVStyle1.ParaStyles.Count-1 do
  RVStyle1.ParaStyles[i].Options := RVStyle1.ParaStyles[i].Options+[rvpaoNoWrap];
RichView1.Reformat;

Posted: Sat Nov 05, 2005 1:51 am
by marekjed
Thanks a lot, Sergey and Michel. This was exactly what I needed.

.marek