InsertText Question

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

InsertText Question

Post by standay »

I have a blank rve. I want to add a break and one return. So, I do this:

Code: Select all

  rve.InsertBreak( 1, rvbs3d, clNone );
it works fine, just what I want. Now, I want one return after it, so I add this:

Code: Select all

  rve.InsertText(#13);
That works, but I always get 2 returns, not 1. How do I get 1 return? I've tried all sorts of things but can't get that to put in just 1 return!
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: InsertText Question

Post by Sergey Tkachenko »

Since breaks (horizontal lines) occupy the whole line, the next content will be added from new line in any case.
InsertText considers #13 as: <empty text> <line break> <empty text>, so you have two line breaks. It's by design.

But there is a problem. One would expect that InsertText('') adds an empty text item after a break. But it does not, it does nothing for ''.
Normally, it is ok, but not when the caret is at the end of a break or a table.
It will be fixed in the next update.
A quick fix:
- open RVERVData.pas,
- in procedure TRVEditRVData.InsertTextW, change the code

Code: Select all

  if ptr = endptr then
  begin
    Invalidate;
    exit;
  end;
to

Code: Select all

  if (ptr = endptr) and
    not (GetItem(GetCurItemNo).GetBoolValue(rvbpFullWidth) and
      (GetOffsetInCurItem >= GetOffsAfterItem(GetCurItemNo))) then
  begin
    Invalidate;
    exit;
  end;
PS: if you want to generate a new document, it's more efficient to use Add*** methods instead:

Code: Select all

rve.Clear;
rve.AddBreak(...);
rve.AddNL('', 0, 0);
rve.Format;
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: InsertText Question

Post by standay »

Thanks Sergey, that fixed it.

Usually in this part of the code I'm adding to the top of a doc, but I sometimes use it in other places so insert works for me.

Thanks again
standay
Posts: 256
Joined: Fri Jun 18, 2021 3:07 pm

Re: InsertText Question

Post by standay »

Sergey,

You were right about the add methods. I was trying to use a style template and while I got it to work, it was much harder than this:

Code: Select all

    i := rve.CurItemNo;
    rve.AddNL( ' Log: ' + DayText, 1, -1); //adds item 1
    rve.AddBreak(1, rvbs3d, clNone);       //adds item 2
    rve.AddNL('',0);                       //adds item 3
    rve.Format;                            //so we can see changes
    rve.SetSelectionBounds( i+3, rve.GetOffsAfterItem(i+3),
      i+3, rve.GetOffsAfterItem(i+3) );    //set sel at end
"Add" worked much better for me.

Stan
Post Reply