About deleting content and getting the current charater

General TRichView support forum. Please post your questions here
Post Reply
KFC123
Posts: 13
Joined: Fri Apr 21, 2006 7:27 am

About deleting content and getting the current charater

Post by KFC123 »

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

Post by Sergey Tkachenko »

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