How to transfer text between TRichView And TRichViewEdit
How to transfer text between TRichView And TRichViewEdit
Hi
How to transfer text between RichView And RichViewEdit with same style.
I mean i want TRichView to the get the text from TRichViewEdit and show as it was in TRichViewEdit (i mean style)
How to transfer text between RichView And RichViewEdit with same style.
I mean i want TRichView to the get the text from TRichViewEdit and show as it was in TRichViewEdit (i mean style)
That was very good idea
But there is a problem that when i send new text previous text will clear. but i don't want it to clear that. actually i'm writing a program like a messenger and want to be able to change the transfered text myself and then show it in the RichView
also i have an another problem when i clear the RichViewEdit using "Clear" procedure is resets the style and puts a blank line at the first line of RichViewEdit. Then focus is on second line .
But there is a problem that when i send new text previous text will clear. but i don't want it to clear that. actually i'm writing a program like a messenger and want to be able to change the transfered text myself and then show it in the RichView
also i have an another problem when i clear the RichViewEdit using "Clear" procedure is resets the style and puts a blank line at the first line of RichViewEdit. Then focus is on second line .
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Thank you all
"InsertRVFFromStream" really solved the inserting problem but i can't edit that still. i want to add some text to what the user types in RichViewEdit and then inserting it in RichView.
also it is important to apply some style to added text.
I don't format it but still there is an empty line
this is the real source code:
also i want to add "AdditinalText" to the formatted text. is it possible to add it to stream or something else without missing styles ?
thanks again for you helping
"InsertRVFFromStream" really solved the inserting problem but i can't edit that still. i want to add some text to what the user types in RichViewEdit and then inserting it in RichView.
also it is important to apply some style to added text.
Thanks Dear SergeySergey Tkachenko wrote: Clear does not add empy line, but formatting empty document in TRichViewEdit does.
I don't format it but still there is an empty line
this is the real source code:
Code: Select all
procedure TransferText(AdditinalText: String);
var Stream: TMemoryStream;
begin
Stream := TMemoryStream.Create;
RVE.SaveRVFToStream(Stream, False);
Stream.Position := 0;
RV.InsertRVFFromStream(Stream, RV.ItemCount);
Stream.Free;
RV.Format;
RVE.Clear;
end;
thanks again for you helping
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
my application is a like a chat box. i write something in RichViewEdit and as chatbox i want to show it in RichView when return key pressed. so i should clear the RichViewEdit to another text. but i have an empty line in RichViewEdit when calling "Clear".Sergey Tkachenko wrote:1. RichViewEdit is formatted automatically before displaying. Just call Clear before adding content.
When return key pressed i want to add a text to what has been typed in RichViewEdit.Sergey Tkachenko wrote: 2. Where AdditinalText should be added to, and where its style is defined?
Lets think the text in RichViewEdit is "Hello World". so i want to add "Lesson 1:" at first of it and show it as "Lesson1: Hello World" in RichView. also i want apply style to AdditionalText like making "Lesson 1:" Bold.
Thanks Again
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
1. Clear deletes all items. If an empty line appears, this means something that was called (between Clear and adding a new content) added this empty line. It may be a call of Format or redrawing.
I can see you call RVE.Clear in TransferText. As I understand, RVE is redrawn after calling this function. And this redrawing adds a new line.
(by the way, Clear requires subsequent calling Format before redrawing, but in this case it formats itself automatically).
But as I understand, a text in RVE is typed by the user. In this case I do not understand how an empty string appears before the typed content.
If you add content in RVE yourself in code, just call Clear one more time before adding it.
I can see you call RVE.Clear in TransferText. As I understand, RVE is redrawn after calling this function. And this redrawing adds a new line.
(by the way, Clear requires subsequent calling Format before redrawing, but in this case it formats itself automatically).
But as I understand, a text in RVE is typed by the user. In this case I do not understand how an empty string appears before the typed content.
If you add content in RVE yourself in code, just call Clear one more time before adding it.
-
- Site Admin
- Posts: 17566
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
2. If in all calls of TransferText, AdditionalText has the same font, you can reserve some text style for it.
You can do it at design time, by editing TextStyles property of TRVStyle component linked to RV. For example, you can use TextStyles[0] for it and define its properties at design time (or at run time, when the application starts).
After that, you can write:
If you want to add the content of RVE to RV not from new line, but in the same paragraph as AdditionalText, you can change the call of InsertRVFFromStream to RV.AppendRVFFromStream(Stream, -1).
You can do it at design time, by editing TextStyles property of TRVStyle component linked to RV. For example, you can use TextStyles[0] for it and define its properties at design time (or at run time, when the application starts).
After that, you can write:
Code: Select all
procedure TransferText(AdditionalText: String);
var Stream: TMemoryStream;
begin
RV.AddNL(AdditionalText, 0, 0);
Stream := TMemoryStream.Create;
RVE.SaveRVFToStream(Stream, False);
Stream.Position := 0;
RV.InsertRVFFromStream(Stream, RV.ItemCount);
Stream.Free;
RV.FormatTail; // can be used in this case, faster than Format
RVE.Clear;
RVE.Format;
end;