Replacing all 'simiar' text occurrencies in richviewedit

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

Replacing all 'simiar' text occurrencies in richviewedit

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

Post 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.
Post Reply