Page 1 of 1

CaretOffs Problem

Posted: Fri Jun 09, 2006 11:27 pm
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;

Posted: Sat Jun 10, 2006 11:00 am
by Sergey Tkachenko
Yes, calling Format is required after calling Clear (before displaying or calling any editing method)