OnImportPicture

General TRichView support forum. Please post your questions here
Post Reply
ravn
Posts: 8
Joined: Wed Jan 21, 2015 6:08 pm

OnImportPicture

Post by ravn »

Why won't this work.
If I use format I don't get the error message but filename is still empty.

Graphic := RVGraphicHandler.LoadFromStream(Stream);
Rve.SetCurrentItemExtraStrProperty(rvespImageFileName,RVU_AnsiToUnicode(CP_ACP,'test.png'),True);
// I Get error her: EListError with message 'List index out of bounds (-1)'.


Thanks in advance
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: OnImportPicture

Post by Sergey Tkachenko »

1. SetCurrent*** methods work with the item at the caret position.
The caret position is defined only when the editor is formatted, so formatting is necessary before calling this method.

2. SetCurrentItemExtraStrProperty works only if the current item supports the specified property, otherwise it does nothing. For rvespImageFileName, the item must be a picture.

3. Delphi automatically converts string literals to Unicode when necessary, so you can simply write
Rve.SetCurrentItemExtraStrProperty(rvespImageFileName, 'test.png' ,True);

4. You create a graphic but do not insert it. If you want to insert a picture at the caret position and assign its file name, write

Code: Select all

Graphic := RVGraphicHandler.LoadFromStream(Stream);
if Graphic = nil then
  exit;
if Rve.InsertPicture('', Graphic, rvvaBaseline) then
  Rve.SetCurrentItemExtraStrProperty(rvespImageFileName, 'test.png', True);
However, the code above contains two editing operations (insertion and assigning a file name), so they can be undone by the user in two steps.
Solution:

Code: Select all

Graphic := RVGraphicHandler.LoadFromStream(Stream);
if Graphic = nil then
  exit;
rve.TopLevelEditor.BeginUndoGroup(rvutInsert);
rve.TopLevelEditor.SetUndoGroupMode(True);
if Rve.InsertPicture('', Graphic, rvvaBaseline) then
  Rve.SetCurrentItemExtraStrProperty(rvespImageFileName, 'test.png', True);
rve.TopLevelEditor.SetUndoGroupMode(False);
Post Reply