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.
How Find&Replace "anithing in a TrichEdit?
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
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;
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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)
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)
I applied that code, but there is a problem:
This is my exact code: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?
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;
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?
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: