trichview.com

trichview.support




Re: List index out of bounds (-1).


Return to index


Author

Message

Sergey Tkachenko

Posted: 03/30/2004 17:34:23


This procedure assumes that it's called when the selection is not empty.

If it's empty, GetSelectionBounds (line 6) returns -1 in StartNo, so line 7

will generate error.

You can insert]


if StartNo<0 then

  exit;


between lines 6 and 7.


One more note: it's assumed that this procedure is called after

ApplyTextStyle or ApplyStyleConversion. Otherwise it will set tags even to

partially selected items.



>

> 1 procedure SetURLToSelection(const URL: string; Editor: TRichViewEdit);

> 2 var i, StartNo, EndNo, StartOffs, EndOffs: Integer;

> 3  rve: TCustomRichViewEdit;

> 4 begin

> 5  rve := Editor.TopLevelEditor;

> 6  rve.GetSelectionBounds(StartNo, StartOffs, EndNo, EndOffs, True);

> 7  if StartOffs >= rve.GetOffsAfterItem(StartNo) then

> 8    inc(StartNo);

> 9  if EndOffs <= rve.GetOffsBeforeItem(EndNo) then

> 10    dec(EndNo);

> 11  rve.BeginUndoGroup(rvutTag);

> 12  rve.SetUndoGroupMode(True);

> 13  for i := StartNo to EndNo do

> 14    rve.SetItemTagEd(i, Integer(StrNew(PChar(URL))));

> 15  rve.SetUndoGroupMode(False);

> 16 end;

>

> --

> Regards,

> Jon

>

>






Powered by ABC Amber Outlook Express Converter