Post
by Sergey Tkachenko » Sun Aug 11, 2019 12:46 pm
Answers
1) If you need to assign an event handler in code, it's not necessary to create a control at design time. You can simply implement the proper function (in the private or the public section). It must be void __fastcall and must have the proper parameters.
2) AddNL has the optional third parameter ParaNo. If you do not specify it, -1 is assumed, meaning addition to the end of the last paragraph. If you specify a positive value, it must an index in RVStyle->ParaStyles->Items[]; a new paragraph will be added with attributes specified in this ParaStyle.
I modified your code to pass 0 to this parameter.
Additionally, I changed Format() to FormatTail(). FormatTail is faster: it formats only content that was added after the last call of Format or FormatTail. FormatTail can be used ONLY if new content starts a new paragraph. You can still use Format, FormatTail is used only for efficiency.
3) Use AddControl. If you need to add from new line, specify the index of a paragraph style in ParaNo parameter. If you need to add to the end of the last line, specify -1 there.
Do not use InsertControl. This method is inherited from parent VCL classes and must not be used (in TRichViewEdit, another InsertControl is declared, it is used to insert in the caret position).
4) I added a new button that adds tabbed text. To specify tab stops, you need to add a paragraph style having the proper Tabs, in RVStyle->ParaStyles. My demo shows how to do it in code. The proper paragraph style is created when it is needed (or existing style is reused). You can add this style at designtime instead; or you can create it one time in code before adding content, store its index and use it later.