Page 1 of 1

How to transfer text between TRichView And TRichViewEdit

Posted: Sun Jan 25, 2009 11:15 am
by Kassit
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)

Posted: Sun Jan 25, 2009 12:46 pm
by hamden
Hi;
Try using TStream:

var Stream: TMemoryStream;

Stream := TMemoryStream.Create;
srv.RichViewEdit.SaveRVFToStream(Stream, False);
Stream.Position := 0;
rv.LoadRVFFromStream(Stream);
Stream.Free;
rv.Format;


let me know your answer;
Hamden

Posted: Sun Jan 25, 2009 8:23 pm
by Kassit
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 .

Posted: Mon Jan 26, 2009 8:31 am
by Ar4i
You can always use Insert**** instead of Load*** method, which will insert the contents instead of replacing them.

Posted: Mon Jan 26, 2009 4:12 pm
by Sergey Tkachenko
Yes, you can use rv.InsertRVFFromStream(Stream, rv.ItemCount) instead of rv.LoadRVFFromStream(Stream) to append data to existing document.

Clear does not add empy line, but formatting empty document in TRichViewEdit does.

Posted: Mon Jan 26, 2009 5:36 pm
by Kassit
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.
Sergey Tkachenko wrote: Clear does not add empy line, but formatting empty document in TRichViewEdit does.
Thanks Dear Sergey
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;
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

Posted: Mon Jan 26, 2009 5:56 pm
by Sergey Tkachenko
1. RichViewEdit is formatted automatically before displaying. Just call Clear before adding content.

2. Where AdditinalText should be added to, and where its style is defined?

Posted: Mon Jan 26, 2009 7:39 pm
by Kassit
Sergey Tkachenko wrote:1. RichViewEdit is formatted automatically before displaying. Just call Clear before adding content.
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: 2. Where AdditinalText should be added to, and where its style is defined?
When return key pressed i want to add a text to what has been typed in RichViewEdit.
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

Posted: Tue Jan 27, 2009 9:11 am
by Sergey Tkachenko
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.

Posted: Tue Jan 27, 2009 9:20 am
by Sergey Tkachenko
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:

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; 
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).

Posted: Wed Jan 28, 2009 7:03 pm
by Kassit
Thanks Dear Sergey

Problem solved.