1) I use the following functions to delete everything in the editor
RichEditor1.selectall;
RichEditor1.deleteselection;
Is any better way to do that?
2) How can I control the cursor and change its position, like make it go to the first place of the content?
3) How can I get the current character?
Thanks in advance.
About deleting content and getting the current charater
-
- Site Admin
- Posts: 17562
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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:
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:
3) RVGetText unit contains some useful functions, including:
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));
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);
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;