1) It depends on what you want.
SelectAll+DeleteSelection is an edition operation, it can be undone by user, and it will fail if the document has items protected from deletion.
Clear+Format just clears the document, cannot be undone, can be used for implementing "File | New" command.
2) You can use SetSelectionBounds. It changes the selection, and the caret is always at the end of the selection. For example, moving to the beginning:
Code: Select all
with RichEditor1 do
SetSelectionBounds(0, GetOffsBeforeItem(0), 0, GetOffsBeforeItem(0));
But using SetSelectionBounds may be difficult in some cases, because it uses double coordinates (item index and offset in the item). Moreover, cells in tables have their own items, not included in the range of items of the main document.
TRichView provides also standard RichEdit-like programming interface for changing selection, functions from RVLinear.pas. for example:
Code: Select all
procedure RVGetSelection(rv: TCustomRichView; var SelStart, SelLength: Integer);
procedure RVSetSelection(rv: TCustomRichView; SelStart, SelLength: Integer);
function RVGetLinearCaretPos(rve: TCustomRichViewEdit): Integer;
procedure RVSetLinearCaretPos(rve: TCustomRichViewEdit; LinearPos: Integer);
3) RVGetText unit contains some useful functions, including:
Code: Select all
// Returns character to the left of caret.
// If caret is at the beginning of line, - to the right.
// If no character, returns empty string
function GetCurrentChar(rve: TCustomRichViewEdit): String;