Very basic questions

General TRichView support forum. Please post your questions here
Post Reply
marekjed
Posts: 4
Joined: Tue Nov 01, 2005 8:19 pm

Very basic questions

Post 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)
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post 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
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
marekjed
Posts: 4
Joined: Tue Nov 01, 2005 8:19 pm

Post by marekjed »

Thanks a lot, Sergey and Michel. This was exactly what I needed.

.marek
Post Reply