I have been using the following code to replace the selection with a bitmap image:
procedure MergeFieldToBitmap(var Bmp: TBitmap; const ImgName: string; const StretchX,StretchY: Integer);
var
info: TRVGraphicItemInfo;
s, SplitText: TRVRawByteString;
begin
re.DeleteSelection;
info := TRVGraphicItemInfo.CreateEx(RVData, Bmp, rvvaBaseline);
info.ImageWidth := Bmp.Width * StretchX;
info.ImageHeight := Bmp.Height * StretchY;
s := RVU_GetRawUnicode(ImgName);
SplitText := '';
TRVEditRVData(re.RVData).InsertSomething(info, s, SplitText, False, False, True);
Bmp := nil;
end; {MergeFieldToBitmap}
Having upgraded to the latest version this code now causes a list index out of bounds error on the InsertSomething command.
The error is raised in unit RVERVData on line 1919
As follows:
then begin
info.SameAsPrev := True;
info.ParaNo := GetItemPara(DrawItems[CaretDrawItemNo].ItemNo); //< HERE
end
else begin
CaretDrawItemNo = -1
Crucially the code is called before the form is displayed. Is there a fix/workaround for this?
List Index Out Of Bounds When Inserting Bitmap
-
- Posts: 6
- Joined: Thu Jul 16, 2009 9:29 am
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 6
- Joined: Thu Jul 16, 2009 9:29 am
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
The recommended way for inserting resized picture is:
It is guaranteed that it will work in future versions, unlike using undocumented methods.
As for the error, the most possible reason for it is unformatted document at the moment of the image insertion.
Code: Select all
re.BeginUpdate;
re.TopLevelEditor.BeginUndoGroup(rvutInsert);
re.TopLevelEditor.SetUndoGroupMode(True);
try
if re.InsertPicture(...) then begin
re.SetCurrentItemExtraIntProperty(rvepImageWidth, StretchX, True);
re.SetCurrentItemExtraIntProperty(rvepImageHeight, StretchY, True);
end;
finally
re.TopLevelEditor.SetUndoGroupMode(False);
re.EndUpdate;
end;
As for the error, the most possible reason for it is unformatted document at the moment of the image insertion.
-
- Posts: 6
- Joined: Thu Jul 16, 2009 9:29 am
-
- Site Admin
- Posts: 17560
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 6
- Joined: Thu Jul 16, 2009 9:29 am