Page 1 of 1
File drag and drop and hypertext
Posted: Sun Aug 26, 2007 7:30 am
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.
Posted: Sun Aug 26, 2007 2:41 pm
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+