Drag & Drop with TAdvMemo

This is probably a really simple question, but the documentation is lacking and I can't seem to figure it out...


How do I implement drag and drop with a TAdvMemo?  I have the AcceptFiles property set, as well as both of the OLEDropTarget properties (odtFile and odtText).  The component does not accept dropped files.

None of the OnDragDrop, OnFileDrop, or OnOleFileDrop events fire.

Like I said, I'm probably missing something very simple, just not sure what...

When I put a default TAdvMemo on the form with

AdvMemo.OleDropTarget := [odfFile] and handle the OnFileDrop event as:

procedure TForm1.AdvMemo1FileDrop(Sender: TObject; FileName: string;
  var DefaultHandler: Boolean);
begin
  showmessage(filename);
end;

this triggers when I drag a file from Windows Explorer on the TAdvMemo.

Hmm...  Not for me.  I even tried dropping a new control onto my form, and setting ONLY OleDropTarget.odfFile=TRUE in the IDE.  My OnFileDrop event does not fire.  Of note: the cursor changes to a little circle with a slash through it when I drag over this control or my original one?


My component is version 3.6.2.24 and is configured as follows:

object memQuery: TAdvMemo
  Left = 8
  Top = 8
  Width = 689
  Height = 217
  Cursor = crIBeam
  AcceptFiles = True
  ActiveLineSettings.ShowActiveLine = False
  ActiveLineSettings.ShowActiveLineIndicator = False
  AutoCompletion.Font.Charset = DEFAULT_CHARSET
  AutoCompletion.Font.Color = clWindowText
  AutoCompletion.Font.Height = -11
  AutoCompletion.Font.Name = 'Tahoma'
  AutoCompletion.Font.Style = []
  AutoCompletion.StartToken = '(.'
  AutoCorrect.Active = True
  AutoHintParameterPosition = hpBelowCode
  BookmarkGlyph.Data = {
    36050000424D3605000000000000360400002800000010000000100000000100
    0800000000000001000000000000000000000001000000000000000000000000
    80000080000000808000800000008000800080800000C0C0C000C0DCC000F0CA
    A6000020400000206000002080000020A0000020C0000020E000004000000040
    20000040400000406000004080000040A0000040C0000040E000006000000060
    20000060400000606000006080000060A0000060C0000060E000008000000080
    20000080400000806000008080000080A0000080C0000080E00000A0000000A0
    200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0
    200000C0400000C0600000C0800000C0A00000C0C00000C0E00000E0000000E0
    200000E0400000E0600000E0800000E0A00000E0C00000E0E000400000004000
    20004000400040006000400080004000A0004000C0004000E000402000004020
    20004020400040206000402080004020A0004020C0004020E000404000004040
    20004040400040406000404080004040A0004040C0004040E000406000004060
    20004060400040606000406080004060A0004060C0004060E000408000004080
    20004080400040806000408080004080A0004080C0004080E00040A0000040A0
    200040A0400040A0600040A0800040A0A00040A0C00040A0E00040C0000040C0
    200040C0400040C0600040C0800040C0A00040C0C00040C0E00040E0000040E0
    200040E0400040E0600040E0800040E0A00040E0C00040E0E000800000008000
    20008000400080006000800080008000A0008000C0008000E000802000008020
    20008020400080206000802080008020A0008020C0008020E000804000008040
    20008040400080406000804080008040A0008040C0008040E000806000008060
    20008060400080606000806080008060A0008060C0008060E000808000008080
    20008080400080806000808080008080A0008080C0008080E00080A0000080A0
    200080A0400080A0600080A0800080A0A00080A0C00080A0E00080C0000080C0
    200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0
    200080E0400080E0600080E0800080E0A00080E0C00080E0E000C0000000C000
    2000C0004000C0006000C0008000C000A000C000C000C000E000C0200000C020
    2000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
    2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C060
    2000C0604000C0606000C0608000C060A000C060C000C060E000C0800000C080
    2000C0804000C0806000C0808000C080A000C080C000C080E000C0A00000C0A0
    2000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C0
    2000C0C04000C0C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000
    FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FDFD25252525
    2525252525252525FDFDFD2E25FFFFFFFFFFFFFFFFFFFF25FDFDFD2525252525
    2525252525252525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25B7B7B7B7
    B7B7B7B7B7B72525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25BFB7BFBF
    B7B7B7B7B7B72525FDFD9A9ABFBFBFB7BFBFB7B7B7B72525FDFDFD25BFBFBFBF
    BFB7BFBFB7B72525FDFD9A9ABFBFBFB7BFBFBFB7BFB72525FDFDFD25BFBFBFBF
    BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFB7BFBFB7B72525FDFDFD25BFBFBFBF
    BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFBFBFBFBFB725FDFDFDFD2525252525
    25252525252525FDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFD}
  BorderStyle = bsSingle
  ClipboardFormats = [cfText]
  CodeFolding.Enabled = False
  CodeFolding.LineColor = clGray
  Ctl3D = False
  DelErase = True
  EnhancedHomeKey = False
  Gutter.Font.Charset = DEFAULT_CHARSET
  Gutter.Font.Color = clWindowText
  Gutter.Font.Height = -13
  Gutter.Font.Name = 'Courier New'
  Gutter.Font.Style = []
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -13
  Font.Name = 'COURIER NEW'
  Font.Style = []
  HiddenCaret = False
  Lines.Strings = (
    '')
  MarkerList.UseDefaultMarkerImageIndex = False
  MarkerList.DefaultMarkerImageIndex = -1
  MarkerList.ImageTransparentColor = 33554432
  OleDropTarget = [odtFile]
  PrintOptions.MarginLeft = 0
  PrintOptions.MarginRight = 0
  PrintOptions.MarginTop = 0
  PrintOptions.MarginBottom = 0
  PrintOptions.PageNr = False
  PrintOptions.PrintLineNumbers = False
  RightMarginColor = 14869218
  ScrollHint = False
  SelColor = clWhite
  SelBkColor = clNavy
  ShowRightMargin = True
  SmartTabs = False
  SyntaxStyles = stySQL
  TabOrder = 0
  TabStop = True
  TrimTrailingSpaces = True
  UILanguage.ScrollHint = 'Row'
  UILanguage.Undo = 'Undo'
  UILanguage.Redo = 'Redo'
  UILanguage.Copy = 'Copy'
  UILanguage.Cut = 'Cut'
  UILanguage.Paste = 'Paste'
  UILanguage.Delete = 'Delete'
  UILanguage.SelectAll = 'Select All'
  UrlStyle.TextColor = clBlue
  UrlStyle.BkColor = clWhite
  UrlStyle.Style = [fsUnderline]
  UseStyler = True
  Version = '3.6.2.24'
  WordWrap = wwNone
  OnDragDrop = memQueryDragDrop
  OnOleDropFile = memQueryOleDropFile
  OnFileDrop = memQueryFileDrop
end

You mix regular file drop and OLE drag & drop.
For regular file drop, you only need to set AcceptFiles= true and NOT odtFile in OleDropTarget 

OR
handle OnOleDropFile when odtFile is set in OleDropTarget 

Getting closer..  If I leave AcctptFile=TRUE and set the OLE options to FALSE, I get a little + cursor when dragging a file over the control, but my OnFileDrop event does not fire?

As it works fine here with the latest version v3.6.5.1, I'd suggest to check with the latest version first.
If the problem persists, please provide a sample source project with which we can reproduce the problem.
Thanks...  Perhaps you could tell me what the process is for upgrading?  I only purchased the component pack ~2 months ago.

To reproduce the problem, I created a new VCL Forms application, dropped a TAdvMemo control on it.  Set OleDropTarget.odtFile=TRUE and created and OnOldDropFile event handler that just calls ShowMessage(FileName);  I do not get a drop cursor and the event does not fire.

If upgrading fixes this issue, please do not invest any time in it.  Just let me know what I need to do to update.  Thanks very much for your help so far!

object mem1: TAdvMemo
  Left = 88
  Top = 16
  Width = 350
  Height = 250
  Cursor = crIBeam
  ActiveLineSettings.ShowActiveLine = False
  ActiveLineSettings.ShowActiveLineIndicator = False
  AutoCompletion.Font.Charset = DEFAULT_CHARSET
  AutoCompletion.Font.Color = clWindowText
  AutoCompletion.Font.Height = -11
  AutoCompletion.Font.Name = 'Tahoma'
  AutoCompletion.Font.Style = []
  AutoCompletion.StartToken = '(.'
  AutoCorrect.Active = True
  AutoHintParameterPosition = hpBelowCode
  BookmarkGlyph.Data = {
    36050000424D3605000000000000360400002800000010000000100000000100
    0800000000000001000000000000000000000001000000000000000000000000
    80000080000000808000800000008000800080800000C0C0C000C0DCC000F0CA
    A6000020400000206000002080000020A0000020C0000020E000004000000040
    20000040400000406000004080000040A0000040C0000040E000006000000060
    20000060400000606000006080000060A0000060C0000060E000008000000080
    20000080400000806000008080000080A0000080C0000080E00000A0000000A0
    200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0
    200000C0400000C0600000C0800000C0A00000C0C00000C0E00000E0000000E0
    200000E0400000E0600000E0800000E0A00000E0C00000E0E000400000004000
    20004000400040006000400080004000A0004000C0004000E000402000004020
    20004020400040206000402080004020A0004020C0004020E000404000004040
    20004040400040406000404080004040A0004040C0004040E000406000004060
    20004060400040606000406080004060A0004060C0004060E000408000004080
    20004080400040806000408080004080A0004080C0004080E00040A0000040A0
    200040A0400040A0600040A0800040A0A00040A0C00040A0E00040C0000040C0
    200040C0400040C0600040C0800040C0A00040C0C00040C0E00040E0000040E0
    200040E0400040E0600040E0800040E0A00040E0C00040E0E000800000008000
    20008000400080006000800080008000A0008000C0008000E000802000008020
    20008020400080206000802080008020A0008020C0008020E000804000008040
    20008040400080406000804080008040A0008040C0008040E000806000008060
    20008060400080606000806080008060A0008060C0008060E000808000008080
    20008080400080806000808080008080A0008080C0008080E00080A0000080A0
    200080A0400080A0600080A0800080A0A00080A0C00080A0E00080C0000080C0
    200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0
    200080E0400080E0600080E0800080E0A00080E0C00080E0E000C0000000C000
    2000C0004000C0006000C0008000C000A000C000C000C000E000C0200000C020
    2000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
    2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C060
    2000C0604000C0606000C0608000C060A000C060C000C060E000C0800000C080
    2000C0804000C0806000C0808000C080A000C080C000C080E000C0A00000C0A0
    2000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C0
    2000C0C04000C0C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000
    FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00FDFD25252525
    2525252525252525FDFDFD2E25FFFFFFFFFFFFFFFFFFFF25FDFDFD2525252525
    2525252525252525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25B7B7B7B7
    B7B7B7B7B7B72525FDFD9A9AB7B7B7B7B7B7B7B7B7B72525FDFDFD25BFB7BFBF
    B7B7B7B7B7B72525FDFD9A9ABFBFBFB7BFBFB7B7B7B72525FDFDFD25BFBFBFBF
    BFB7BFBFB7B72525FDFD9A9ABFBFBFB7BFBFBFB7BFB72525FDFDFD25BFBFBFBF
    BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFB7BFBFB7B72525FDFDFD25BFBFBFBF
    BFBFBFBFBFB72525FDFD9A9ABFBFBFBFBFBFBFBFBFB725FDFDFDFD2525252525
    25252525252525FDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFDFD}
  BorderStyle = bsSingle
  ClipboardFormats = [cfText]
  CodeFolding.Enabled = False
  CodeFolding.LineColor = clGray
  Ctl3D = False
  DelErase = True
  EnhancedHomeKey = False
  Gutter.Font.Charset = DEFAULT_CHARSET
  Gutter.Font.Color = clWindowText
  Gutter.Font.Height = -13
  Gutter.Font.Name = 'Courier New'
  Gutter.Font.Style = []
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clBlack
  Font.Height = -13
  Font.Name = 'COURIER NEW'
  Font.Style = []
  HiddenCaret = False
  Lines.Strings = (
    '')
  MarkerList.UseDefaultMarkerImageIndex = False
  MarkerList.DefaultMarkerImageIndex = -1
  MarkerList.ImageTransparentColor = -1
  OleDropTarget = [odtFile]
  PrintOptions.MarginLeft = 0
  PrintOptions.MarginRight = 0
  PrintOptions.MarginTop = 0
  PrintOptions.MarginBottom = 0
  PrintOptions.PageNr = False
  PrintOptions.PrintLineNumbers = False
  RightMarginColor = 14869218
  ScrollHint = False
  SelColor = clWhite
  SelBkColor = clNavy
  ShowRightMargin = True
  SmartTabs = False
  TabOrder = 0
  TabStop = True
  TrimTrailingSpaces = False
  UILanguage.ScrollHint = 'Row'
  UILanguage.Undo = 'Undo'
  UILanguage.Redo = 'Redo'
  UILanguage.Copy = 'Copy'
  UILanguage.Cut = 'Cut'
  UILanguage.Paste = 'Paste'
  UILanguage.Delete = 'Delete'
  UILanguage.SelectAll = 'Select All'
  UrlStyle.TextColor = clBlue
  UrlStyle.BkColor = clWhite
  UrlStyle.Style = [fsUnderline]
  UseStyler = True
  Version = '3.6.2.24'
  WordWrap = wwNone
  OnOleDropFile = mem1OleDropFile
end





If you purchased this only 2 months ago, please login on our website and go to Account / My Products from where you can download the latest TMS Component Pack update.

Good news: the update was painless and did not seem to break anything..  I now have TAdVMemo v3.6.5.1, same as you, but it still does not work.  If I have AcceptFile=TRUE I get a + drop cursor when I drag a file over the control, but the OnDropFile event does not fire.


If I turn off AcceptFile and set odfFile, I do not get a drop cursor (it stays the circle with the slash through it) and the On OleFileDrop event does not fire.

Sample project here: https://www.dropbox.com/sh/5kvjwxthox2h4wq/AAD3KfVmnUFa--hmioo2caCVa?dl=0

I open your project, compile and run. Then I drag a file from Windows Explorer on this TAdvMemo and I get a message showing the filename and the file opens in TAdvMemo.

So I guess we need to figure out why this does not work for me?


The EXE built from that project (which you should see in the Win32\release folder anyway) is here: https://www.dropbox.com/s/twdu6lg97z104y7/AdvMemoTest.exe?dl=0

Definitely not working for me.

UPDATE: When I run the EXE from outside the IDE it works.  I get the ShowMEssage() and it loads the file I dropped!?  


Why would this not work from inside the IDE, even with a release build?

For security reasons, we cannot run foreign EXEs here.
What Delphi version do you use to begin with?

I have no idea. My tests are directly from the IDE in debug mode.

Maybe you have some 3rd party add-ons installed in the IDE that interfere.

I am working with Delphi 10-Seattle...


Wither way as long as it works in the wild I will be fine...  Hopefully I never have to debug it :)

Thanks for your help!

Confirmed: Working properly from outside the IDE.  Very strange.  I have it set to AcceptFiles and they load as expected.


One last question: Is there an event that fires AFTER the file loads when dropped?  The OnFileDrop appears to resolve beforehand and I need to do some post-processing on dropped files.

Thanks.

Nevermind...  I just noticed the DefaultHandler parameter in the OnFileDrop event.  I set this to FALSE and am able to load the file and pre-process as required.


Thanks.