File drag and drop and hypertext

General TRichView support forum. Please post your questions here
Post Reply
JSH2
Posts: 7
Joined: Sat Apr 21, 2007 12:27 pm

File drag and drop and hypertext

Post by JSH2 »

When I drag and drop a file from a explorer to a RichViewEdit, I would like to insert the file name on the RichViewEdit and make a hypertext to link the file location.
How could I do?
Help me, please.

Thank you in advance.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use OnDropFile event:

Code: Select all

procedure TForm3.RichViewEdit1DropFiles(Sender: TCustomRichViewEdit;
  Files: TStrings; var FileAction: TRVDropFileAction;
  var DoDefault: Boolean);
var i, StyleNo, OldStyleNo: Integer;
begin
  OldStyleNo := Sender.CurTextStyleNo;
  StyleNo :=
    rvActionsResource.rvActionInsertHyperlink1.GetHyperlinkStyleNo(Sender, OldStyleNo);
  for i := 0 to Files.Count-1 do begin
    if i>0 then
      Sender.InsertText(#13);
    Sender.CurTextStyleNo := StyleNo;
    Sender.InsertStringTag(Files[i], Files[i]);
    // for older versions of TRichView: Sender.InsertStringTag(Files[i], Integer(StrNew(PChar(Files[i]))));
  end;
  Sender.CurTextStyleNo := OldStyleNo;
  FileAction := rvdfLink;
  DoDefault := False;
end;
In this code, TrvActionInsertHyperlink.GetHyperlinkStyleNo is used to get index of hypertext style. You can create your own function instead.
This example assumes that rvoTagsArePChars is in Options (because file names are stored in tags)

---

Update 2011-Oct-22: updated for compatibility with TRichView 13.3+
Post Reply