TAdvRichEditor Replace / ReplaceAll and some more questions

Hi,

I have a couple of questions related to the Replace() and ReplaceAll() methods of TAdvRichEditor. I can't find any documentation 'bout them in the control guide (I really miss the old help system on those occasions). Fortunatelly, we have this forum but it would be nice if those guides would cover the components, their methods and properties more extensively

  1. Is there a way to know how many occurrences where replaced using the method ReplaceAll() of TAdvRichEditor?. It returns a bool (successful or not) but it doesn't help too much.

  2. I'm getting some random results using Replace() method. Sometimes it replaces what it should and sometimes it doesn't. I suspect it's related to the starting point the method uses to start its search. How can I see what is the starting point the Replace() method is using?. How can I change it? How should the method be used?

  3. How can I get the caret position and how can I change it programmatically?

  4. The last one, I promise. If I change programmatically the image contained in a TPictureElement (let's say the user replaces an image with another one through a dialog) and the new image is smaller or bigger than the original one, I need to reflesh / repaint the TAdvRichEditor because the vertical scrollbar does not get updated properly to the new document size. The only way I was able to achieve this is by using the TidyElements() method but I don't know if that is its main goal (probably not).

Thanks and regards.

  1. There is at this moment not a built-in function to count the number of replaces. This is a good suggestion for a future update.
  2. Replace starts from the caret.
  3. You can set the caret position with AdvRichEditor.SelStart / AdvRichEditor.SelLength = 0 and call AdvRichEditor.SelectionToCaret;
  4. Did you try to update this with a BeginUpdate/EndUpdate block?

Thanks @brunofierens for the reply. I have some nuances I would like to be solved if you don't mind.

  1. Thanks. It would be great.
  2. See point 3.
  3. If I want to obtain where the caret is within the current document I can't use SelStart because is not accesible (I can set value but not get it). Any ideas about how can I get the caret position in the text?. Which would be the best technique / approach if I would like to replicate the Rad Studio status bar and show the caret position within the text (current line and position inside that line) or even the caret position inside the whole document. I can't find info about all of those topics in the component pdf guide.
  4. It worked like a charm. Thanks a lot. Just one thing, When it's supposed TidyElements() to be used?

Thanks a lot again for your patience and wisdom :slight_smile:

I cannot see an issue with reading AdvRichEditor.SelStart.
I dropped a TAdvRichEditor and a button the form with button click handler:

procedure TForm1.Button1Click(Sender: TObject);
begin
  caption := advricheditor1.SelStart.ToString;
end;

After typing text and clicking the button, it showed the last caret position.

I suppose I 'm doing somethng wrong but if I add this line ...

I have this compile error.

image

I'm using C++ under Rad Studio XE3.

In Delphi this works fine. Possibly C++Builder has problems with the overload.
We'll change this to not use overloads.