CaretOffs Problem

General TRichView support forum. Please post your questions here
Post Reply
DickBryant
Posts: 148
Joined: Wed Dec 07, 2005 2:02 pm
Contact:

CaretOffs Problem

Post by DickBryant »

Is there an issue with doing a .Clear on a TRichViewEdit and then attempting to enter text into it? Perhaps I must always do a Format after doing a clear? I'm not quite sure what the problem is because in most instances it does seem to work to do a Clear and then be able to type into the TRV control.

When it does cause an error, the first character typed causes an exception in the code below because CaretOffs = -1.

procedure TRVEditRVData.InsertTextTyping(text: String; Key: Char);
var ditem: TRVDrawLineInfo;
item: TCustomRVItemInfo;
ItemNo, Offs, Len : Integer;
s: String;
Minus,SavedCaretOffs: Integer;
{.....................................................}
procedure DoInsert;
begin
if not TCustomRichViewEdit(RichView).BeforeChange(False) then
exit;
BeginUndoSequence(rvutInsert, True);
InsertString(Text,FCurTextStyleNo,True,False); { inserting character in new item }
Refresh;
Change;
end;
{.....................................................}
begin
if (GetRVStyle=nil) or (PartialSelectedItem<>nil) or not CanDelete then begin
Beep;
exit;
end;
Len := Length(text);
{$IFNDEF RVDONOTUSEUNICODE}
if GetRVStyle.TextStyles[GetActualCurStyleNo].Unicode then
Len := Length(text) div 2;
{$ENDIF}
CaretDrawItemNo := CharEnds.Items[CaretOffs].DrawItemNo;
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, calling Format is required after calling Clear (before displaying or calling any editing method)
Post Reply