How to transfer text between TRichView And TRichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
Kassit
Posts: 10
Joined: Sat Jan 24, 2009 12:25 pm
Location: Iran (Islamic Republic Of)
Contact:

How to transfer text between TRichView And TRichViewEdit

Post 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)
hamden
Posts: 6
Joined: Sat Oct 25, 2008 7:40 pm
Location: Brasil
Contact:

Post 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
Kassit
Posts: 10
Joined: Sat Jan 24, 2009 12:25 pm
Location: Iran (Islamic Republic Of)
Contact:

Post 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 .
Ar4i
Posts: 30
Joined: Tue Apr 24, 2007 7:03 am

Post by Ar4i »

You can always use Insert**** instead of Load*** method, which will insert the contents instead of replacing them.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Kassit
Posts: 10
Joined: Sat Jan 24, 2009 12:25 pm
Location: Iran (Islamic Republic Of)
Contact:

Post 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
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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?
Kassit
Posts: 10
Joined: Sat Jan 24, 2009 12:25 pm
Location: Iran (Islamic Republic Of)
Contact:

Post 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
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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).
Kassit
Posts: 10
Joined: Sat Jan 24, 2009 12:25 pm
Location: Iran (Islamic Republic Of)
Contact:

Post by Kassit »

Thanks Dear Sergey

Problem solved.
Post Reply