I need to go to the first line of the document and insert a line of text, using tWPRichText component. Can you tell me how I can do that?
How to Insert text at beginning of document?
-
-
- Offizieller Beitrag
WPRichText.CPPosition := 0;
WPRichText.InputString('some Text') -
That's what I though, but it isn't working:
CodemNotes.AsString := ds.FieldByName(aFieldName).AsString; aLine := #13 + #10 + ansiDateTimeToStr(now, false) +' '+ dmMain.tblUserNAME.AsString + ': '; mNotes.CPPosition := 0; mNotes.InputString(aLine);
but the new line keeps getting added to the end.
[/img] -
- Offizieller Beitrag
Hi,
I don't know why the code should not work.
But in any case you can also use low level code which gives more control:
WPRichText1.BodyText.InsertPar(WPRichText1.BodyText.FirstPar).SetText('First Line');
Don't forget if you need to see the text:
WPRichText1.ReformatAll(true,true);
-
almost right.
it's putting the cursor down to the next line, but I need the cursor at the end of the inserted line.
is that possible?
(and does it matter that I'm using html instead of rtf?) -
- Offizieller Beitrag
If you use HTML it is possible that there is an invisible paragraph at the beginning. This can be the problem with the CPPosition := 0;
WPRichText1.BodyText.InsertPar
does not move the cursor like CPPosition does, it is simply creating a new paragraph at the beginning.
You can move the cursor with CPPosition, CPLineNr and other.
You probably want this:
ActiveParagraph := WPRichText1.BodyText.FirstPar;
ActibvePosInPar := ActiveParagraph.CharCount; -
thank you, that worked
-
- Offizieller Beitrag
Also here: The problem is the use of wpUseDIVTree in FormatOptionsEx2
in FormatOptionsEx2. That mode is not compatible the the regular
formatter.