How Find&Replace "anithing in a TrichEdit?

General TRichView support forum. Please post your questions here
Post Reply
alogrep
Posts: 52
Joined: Fri Oct 27, 2006 5:25 pm

How Find&Replace "anithing in a TrichEdit?

Post by alogrep »

Hi
I have a TRichView control with 'regular' text and tables (and maybe other items in the future).
I want to traverse everything in the control and translate it from the original language (as written at design time) to another language.
Example a TRichViewEdit with text and tables.
I want to do: search the whole text and when you find 'Hello' (but not ('Hello2') change it to 'Ciao'. Also I want to say: go and search for all tables and if cell[0,0] text is 'Question' change it to 'Domanda'.
Any easy way?
Thanks.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Should it be an editing operation or not? (editing operations are slower, they can be undone by users).

As for implementing as editing operation, use rve.SearchText

Code: Select all

var ltable: TRVTableItemInfo;
      lrve: TCustomRichViewEdit;

// replacing all occurences of word 'Hello' to 'Ciao'
rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
while rve.SearchText('Hello', [rvseoDown, rvseoWholeWord]) do
  rve.InsertText('Ciao');

// replacing word 'Question' to 'Domanda' in the
// top left cells of tables
rve.SetSelectionBounds(0, rve.GetOffsBeforeItem(0), 0, rve.GetOffsBeforeItem(0));
while rve.SearchText('Question', [rvseoDown, rvseoWholeWord]) do
  if rve.InplaceEditor<>nil then begin
    lrve := rve;
    while TCustomRichViewEdit(lrve.InplaceEditor).InplaceEditor<>nil do
      lrve := rve;
    ltable := lrve.GetCurrentItem as TRVTableItemInfo;
    if ltable.Cells[0, 0].GetRVData=rve.TopLevelEditor.RVData then
      rve.InsertText('Domanda');
  end;
alogrep
Posts: 52
Joined: Fri Oct 27, 2006 5:25 pm

Post by alogrep »

it would be non editing. What would I substitute in your code (to apply it to non editing)?
Thanks
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the help file, in the topic "Controls, Documents, Items", there is an example, procedure AllUpperCase.
This procedure enumerates all items in the document (include items of table cells) and changes all text to upper case.
You can change this procedure to implement another operation on strings (replacing words instead of changing character case)
alogrep
Posts: 52
Joined: Fri Oct 27, 2006 5:25 pm

Post by alogrep »

I applied that code, but there is a problem:
This is my exact code:

Code: Select all

    with rv1 do begin
       for I := 0 to RVData.Items.Count - 1 do
          if RVData.GetItemStyle(I) >= 0 then begin
            s:= RVData.GetItemTextA(I);
            translatit(s);
            RVData.SetItemTextA(I,s);
          end;
     end;
Now, the original word in line 1 is "Ciao".
Translait translates it to "Hello" (so 's' after the call to translatit is 'Hello', checked with breakpoint) but the richedit control shows "Hell", i.e. it seems thta truncates the word to the length of the original?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

call rv1.Format after this code.
Post Reply