Page 1 of 1

Insert a bitmap in a table cell

Posted: Sat Sep 09, 2023 10:37 am
by fara2000
Hello sergey
When I insert a bitmap in a table cell. I try to free the bitmap when done, but An exception in arised Why???
Please Help!!!

procedure TFScienceStudio.InsertBitmap1Click(Sender: TObject);
var Table:TrvTableItemInfo;
BitMap:TBitmap;
Row,Col:Integer;
begin
Table:=GetTable(Rich.RichViewEdit.RVData,'');
Bitmap:=TBitmap.Create;
Row:=0;
Col:=0;
Bitmap.Canvas.Font.Size:=20;
Bitmap.Width:=Bitmap.Canvas.TextWidth('Question');
Bitmap.Height:=Bitmap.Canvas.TextHeight('Question');
Bitmap.Canvas.Font.color:=Clred;
Bitmap.Canvas.TextOut(0,0,'Hello');
Table.EditCell(Row, Col);
// moving the caret to the end of this cell
with TCustomRVFormattedData(Table.Cells[Row, Col].GetRVData) do
SetSelectionBounds(ItemCount-1, GetOffsAfterItem(ItemCount-1), ItemCount-1, GetOffsAfterItem(ItemCount-1));
Rich.RichViewEdit.InsertPicture('',Bitmap, rvvaAbsMiddle);
Rich.RichViewEdit.Change;
Rich.RichViewEdit.Format;
Bitmap.free;
end;

Re: Insert a bitmap in a table cell

Posted: Sat Sep 09, 2023 10:41 am
by standay
fara2000,

Sergey can confirm, but as I recall when you insert a picture (RichViewEdit.InsertPicture) the graphic is then "owned" by the richview and you no longer have to free it, the richview will do that for you. Just comment out the Bitmap.free call.

Stan

Re: Insert a bitmap in a table cell

Posted: Sat Sep 09, 2023 11:31 am
by Sergey Tkachenko
Yes, it's correct.
Do not free the image after calling InsertPicture or AddPicture

Re: Insert a bitmap in a table cell

Posted: Sat Sep 09, 2023 12:29 pm
by fara2000
Thank you very much for tghe immediate response