Insert a bitmap in a table cell

General TRichView support forum. Please post your questions here
Post Reply
fara2000
Posts: 42
Joined: Mon Sep 07, 2015 5:59 pm

Insert a bitmap in a table cell

Post 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;
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Insert a bitmap in a table cell

Post 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
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Insert a bitmap in a table cell

Post by Sergey Tkachenko »

Yes, it's correct.
Do not free the image after calling InsertPicture or AddPicture
fara2000
Posts: 42
Joined: Mon Sep 07, 2015 5:59 pm

Re: Insert a bitmap in a table cell

Post by fara2000 »

Thank you very much for tghe immediate response
Post Reply