change text in an item

General TRichView support forum. Please post your questions here
Post Reply
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

change text in an item

Post by Cosmin3 »

Hi, Sergey.

I want to change a text fragment from an text item.
For example in an item I have text: "It's a wonderles world" with charset, let's say, 200. I want to change the word "wonderles" with "wonderful" (same length) but with charset, let's say, 250. So I will obtain 3 items: "It's a " and " world" with charset 200 and "wonderful" with charset 250.
Question is: how can I do this so it executes as fast as possible (I make a lot of changes to large texts)? And in both situations: with or without Undo.
I was thinking of using the text fragment ("wonderful") to make a rtf as string, convert it to a stream and then insert it over the old selected text ("wonderles") with InsertRTFFromStreamEd; but it's too slow (especially in table cells where I have to enter in edit mode even if I don't need Undo).

Thank you in advance for any idea.
Best regards.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

With undo: select the word to change (SetSelectionBounds) and apply a new style (ApplyTextStyle, or ApplyStyleConversion).
If the text is inside table cell, initialize cell editing before calling SetSelectionBounds:

Code: Select all

var RVData: TCustomRVFormattedData;

RVData := TCustomRVData(Cell.Edit);
RVData.SetSelectionBounds(...);
RichViewEdit1.ApplyTextStyle(...);
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Without undo: consider creating a copy of document in another richview. Add items one by one, using Add*** methods, with necessary modifications.
Cosmin3
Posts: 54
Joined: Sat Apr 05, 2008 12:04 pm

Post by Cosmin3 »

With undo: I have to create a new style (for ApplyTextStyle), copy the style of the current text item with Assign, change the charset and then check if it's not a duplicate. If I don't check, on some texts it will have a lot of duplicates. And, if I check, on other texts it will take a lot of time: tenth of thousand of words changed x hundreds (maybe thousands) of styles checked. I entend to make the program work even on slower computers. You know better than me how fast is IsEqual function so please tell me if it's worth implementing...

Without undo: It's a good idea but I didn't make anything like this until now. In RootEditor is simple to copy items but I didn't know how to "rebuild" a table (maybe with another tables in it). If you're sure that this method is faster than the one with undo maybe you can show me how...
Thank you.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you really have hundreds or thousands text styles with different properties, and all of them exists in one document?
In all cases, with or without undo, you need to determine which style to use for chosen words, so you cannot avoid searching in existing styles.
Post Reply