inserting text at the top with different style
inserting text at the top with different style
Hi,
I have some stuff in a TRichViewEdit. At the top, there is a piece of text, centered and some whatever font and color.
I would like to insert few lines of text above, at the top, and I would like that my new inserted text to have some specific style. No matter what I tried, the inserted piece is sticked to the text at the top and the style is screwed up one way or the other.
The help file for InsertText says "Inserted text has current text and current paragraph style." I understand that. But how do I insert a piece of text at the top and give it a different style *without* breaking the existing body?
Thanks
I have some stuff in a TRichViewEdit. At the top, there is a piece of text, centered and some whatever font and color.
I would like to insert few lines of text above, at the top, and I would like that my new inserted text to have some specific style. No matter what I tried, the inserted piece is sticked to the text at the top and the style is screwed up one way or the other.
The help file for InsertText says "Inserted text has current text and current paragraph style." I understand that. But how do I insert a piece of text at the top and give it a different style *without* breaking the existing body?
Thanks
-
- Site Admin
- Posts: 17561
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
// moving to the beginning of the document
rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
// changing the current text style
rve.CurTextStyleNo := ...
// inserting text
rve.InsertText(...);
not working
Nope, this is still not working for me. The inserted text (which I would like it to be left aligned) picks up the alignment from the first paragraph of the body (which is centered).
My inserted text looks like this:
_______'#$D#$A#$D#$A'abc@xyz.com schrieb am 18.03.2015 14:53:08: '#$D#$A#$D#$A
Thanks,
My inserted text looks like this:
_______'#$D#$A#$D#$A'abc@xyz.com schrieb am 18.03.2015 14:53:08: '#$D#$A#$D#$A
Thanks,
Also, if I set the para style, like this:
rve.CurParaStyleNo := ...
Than this breaks the body of the original text. The paragraph which was centered (at the top) it becomes left aligned.
rve.CurParaStyleNo := ...
Than this breaks the body of the original text. The paragraph which was centered (at the top) it becomes left aligned.
-
- Site Admin
- Posts: 17561
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Code: Select all
// moving to the beginning of the document
rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
// changing the current text style
rve.CurTextStyleNo := ...
// inserting an empty paragraph
rve.InsertText(#$D#$A);
// applying the required paragraph style to this empty paragraph
rve.ApplyParaStyle(...);
// inserting the rest of text
rve.InsertText(#$D#$A'abc@xyz.com schrieb am 18.03.2015 14:53:08: '#$D#$A#$D#$A
);
not working
I am still not having luck. I do 3 insertions at the top of the message (it's an email message getting answered) and they don't look ok.
Plus, your recommendation to insert an empty paragraph is not good for me as this is inserting additional white space not desired.
I think the flow should be as simple as this:
1. position the cursor where we want it;
2. prepare "that location" for inserting text:
- set font attributes
- set paragraph attributes
3. Insert the text.
Another possibility could be:
1. position the cursor where we want it;
2. insert the text (say that the text is 30 characters long)
3. select 30 characters and apply whatever formats to the selection
This also does not work for me because the selection I made does not really equals the length of the text I am inserting. I was using methods from RVLinear, but I don't know what I am doing wrong, the selection is bad, so this is not working also.
Plus, your recommendation to insert an empty paragraph is not good for me as this is inserting additional white space not desired.
I think the flow should be as simple as this:
1. position the cursor where we want it;
2. prepare "that location" for inserting text:
- set font attributes
- set paragraph attributes
3. Insert the text.
Another possibility could be:
1. position the cursor where we want it;
2. insert the text (say that the text is 30 characters long)
3. select 30 characters and apply whatever formats to the selection
This also does not work for me because the selection I made does not really equals the length of the text I am inserting. I was using methods from RVLinear, but I don't know what I am doing wrong, the selection is bad, so this is not working also.
-
- Site Admin
- Posts: 17561
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Yes, my code has a bug: after InsertText(#$D#$A), the caret is in the second paragraph, so we need to return it back.
If you remove #$D#$A from the beginning of the second InsertText, the inserted text will be inserted in very beginning.
I tested in the ActionTest demo:
This code adds a text line and two empty paragraphs after it.
If you remove the final #$D#$A#$D#$A, there will be no empty lines.
If you remove #$D#$A from the beginning of the second InsertText, the inserted text will be inserted in very beginning.
I tested in the ActionTest demo:
Code: Select all
function GetGreenTextStyle(RVStyle: TRVStyle): Integer;
var TextStyle: TFontInfo;
begin
TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(RVStyle.TextStyles[0]);
TextStyle.Color := clGreen;
Result := RVStyle.FindTextStyle(TextStyle);
TextStyle.Free;
end;
function GetRightAlParaStyle(RVStyle: TRVStyle): Integer;
var ParaStyle: TParaInfo;
begin
ParaStyle := TParaInfo.Create(nil);
ParaStyle.Assign(RVStyle.ParaStyles[0]);
ParaStyle.Alignment := rvaRight;
Result := RVStyle.FindParaStyle(ParaStyle);
ParaStyle.Free;
end;
procedure TForm3.ToolButton73Click(Sender: TObject);
begin
RichViewEdit1.SetSelectionBounds(0, RichViewEdit1.GetOffsBeforeItem(0),
0, RichViewEdit1.GetOffsBeforeItem(0));
RichViewEdit1.CurTextStyleNo := GetGreenTextStyle(RVStyle1);
RichViewEdit1.InsertText(#$D#$A);
RichViewEdit1.SetSelectionBounds(0, RichViewEdit1.GetOffsBeforeItem(0),
0, RichViewEdit1.GetOffsBeforeItem(0));
RichViewEdit1.ApplyParaStyle(GetRightAlParaStyle(RVStyle1));
RichViewEdit1.InsertText('abc@xyz.com schrieb am 18.03.2015 14:53:08: '#$D#$A#$D#$A);
end;
If you remove the final #$D#$A#$D#$A, there will be no empty lines.
test case (still not working for me)
I just sent you a very simple test case.
regards
Lucian
regards
Lucian
testcase 2
I resent the project, please use test2.zip
Lucian
Lucian
-
- Site Admin
- Posts: 17561
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
All right!
It worked in the test and I understand now. I'll work this on the application and see if my problem is gone.
Thank you,
Lucian
Thank you,
Lucian