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.
File drag and drop and hypertext
-
- Site Admin
- Posts: 17565
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Use OnDropFile event:
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+
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;
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+