Page 1 of 1

Copy Images as a Text to Clipboard

Posted: Mon Nov 03, 2008 5:26 pm
by Jacek Puczynski
Hello I have a problem with my TRichView:

In the document there is a lot of text and small images.
Now, when user selects the text with the images for copy to clipboard images are ignored ( I use CopyText() method).
Now I would like to make the copying better and copy text with images like that
text text text <image Name> text text text
I use AddPictureEx with Name value that I want to be visible after copy.

How can I do it?

Thanks. Jacek.

Posted: Tue Nov 04, 2008 6:12 pm
by Sergey Tkachenko
Unfortunately, the current TRichView version does not allow this.
You can use a low level event OnSaveComponentToFile to modify how images are saved in text, but it will not affect methods for copying or saving selection, only methods for saving the complete text:

Code: Select all

uses CRVData, RVUni;
procedure TForm1.RichViewEdit1SaveItemToFile(Sender: TCustomRichView;
  const Path: String; RVData: TCustomRVData; ItemNo: Integer;
  SaveFormat: TRVSaveFormat; Unicode: Boolean;
  var OutStr: TRVRawByteString; var DoDefault: Boolean);
var s: String;
begin
  if (SaveFormat<>rvsfText) then
    exit;
  if (RVData.GetItemStyle(ItemNo)<>rvsPicture) and
     (RVData.GetItemStyle(ItemNo)<>rvsHotPicture) then
    exit;
  RVData.GetItemExtraStrProperty(ItemNo, rvespAlt, s);
  if s='' then
    s := 'image';
  s := '<'+s+'>';
  DoDefault := False;
  // for Delphi 4-2007
  if Unicode then
    OutStr := RVU_AnsiToUnicode(RVData.GetRVStyle.DefCodePage, s)
  else
    OutStr := s;
  {
  // for Delphi 2009
  if not Unicode then
    OutStr := RVU_UnicodeToAnsi(RVData.GetRVStyle.DefCodePage, RVU_GetRawUnicode(s))
  else
    OutStr := RVU_GetRawUnicode(s);
  }
end;

Posted: Tue Nov 04, 2008 9:21 pm
by Jacek Puczynski
Thank you for your answer.

Hope it will be consider as a new feature for next versions.

Regards, Jacek.