Page 1 of 1

Replacing all 'simiar' text occurrencies in richviewedit

Posted: Fri Aug 08, 2008 7:27 am
by alogrep
Hi
I want to do this:
given a text file of this format:
aaaaaaaa
{bmc xyz.gif)
bbbbbbbbb
{bmc xyz123.gif}
etc
I want to replace all the "{bmc " occurrencies with the gif they refer to.
So I can use rve.SearchText('{bmc ',GetRVESearchOptions(frOptions)).
But then? it will select "{bmc ", but how do I get the other variable length part (e.g. "xyz.jpg}" or "xyz123.jp}" that follows it?
Also, once I have determined the whole text (e.g. "{bmc xyz.jpg}"
can I use:
do while rve.SearchText('{bmc ',GetRVESearchOptions(frOptions)).
// get filename here
jp.LoadFromFile(filename);
rve.insertPicture('',jp, rvvaBaseline);
end;
rve.Format;
so that "{bmc xyz.gif}" disappears and the pic is shown in its place?
In order to SAVE the incorporated picture, do I need to set anything, before I save the document?
Thanksa lot.

Posted: Mon Aug 11, 2008 8:20 am
by Sergey Tkachenko
If SearchText finds the string, it selects it.
You can get the full text of the item containing the selection as rve.TopLevelEditor.GetItemTextA(rve.TopLevelEditor.CurItemNo) (because SearchText can select only inside a single item). This text will include the full code (e.g. "{bmc xyz.jpg}"). The caret is always at the end of selection, after "{bmc ". The caret position is rve.TopLevelEditor.OffsetInCurItem (the index of character (from 1) after the caret). Now you can find the position of '}', select the whole code (using rve.TopLevelEditor.SetSelectionBounds) and insert a picture to replace the selection.