Page 1 of 1

Does RichView had any interface to insert picture?

Posted: Wed Sep 28, 2005 9:02 am
by Guest
I want a richedit inherit richview ,or richview has the richedit's property,how can i do that? And the most important is that when i complete,i want get all the picture's source path, how can i do that?

Posted: Wed Sep 28, 2005 9:30 am
by Sergey Tkachenko
Inserting picture? It's simple:

Code: Select all

var bmp: TBitmap;

bmp := TBitmap.Create;
bmp.LoadFromFile('c:\pic.bmp');
RichViewEdit1.InsertPicture('', bmp, rvvaBaseline);
About storing picture file name, there are two ways to do it.
The simplest way is to store it in the "item name" - text value associated in TRichView with any picture:

Code: Select all

bmp := TBitmap.Create;
bmp.LoadFromFile('c:\pic.bmp');
RichViewEdit1.InsertPicture('c:\pic.bmp', bmp, rvvaBaseline);

// reading name from the picture at the position of caret
FileName := RichViewEdit1.GetCurrentItemText;
But the recommended way for storing image file name is a special "file name" item property. It was specially designed for storing image file names.

Code: Select all

bmp := TBitmap.Create;
bmp.LoadFromFile('c:\pic.bmp');

RichViewEdit1.TopLevelEditor.BeginUndoGroup(rvutInsert);
RichViewEdit1.TopLevelEditor.SetUndoGroupMode(True);
try
  if RichViewEdit1.InsertPicture('', bmp, rvvaBaseline) then
    RichViewEdit1.SetCurrentItemExtraStrProperty(rvespImageFileName, 'c:\pic.bmp', True);
finally
  RichViewEdit1.TopLevelEditor.SetUndoGroupMode(False);
end;

// reading file name from the picture at the position of caret
RichViewEdit1.GetCurrentItemText(rvespImageFileName, FileName);