DropObject not working

  1. 2 weeks ago

    Niles M

    Feb 10 Pre-Release Testers

    Just trying to start out simple with Drop Object. Read what I could online but haven't been able to make it work.

    So, when a users drags a file onto a Bevel Button, I want to a message box the native path to the file.

    Here's what I've got in the Open EvenHandler for the BevelButton

    dim msifile as new filetype
    
    msifile.Extensions = "msi"
    
    me.AcceptFileDrop FileType(msifile)

    And here's what I have the the Drop Object Event Handler

    if obj.FolderItemAvailable then
      dim f as FolderItem = obj.FolderItem
      
      dim path as String = f.NativePath
      
      MsgBox path
    end

    Not only does that message box not come up, but I get a the circle with the line through it on the drag, showing it's not accepting the file. And yes, the file ends with .msi extension.

    Thoughts?

    Do you have a FileType Set in the project item list? If not, add one as Emile said earlier. In the FileType Set, set up an entry with the name 'MSI', the Display Name 'MSI', and the extension '.msi' (don't forget the dot if you are on Windows).

    In the Open event for the Bevelbutton, add the code

    Me.AcceptFileDrop ("MSI")

    Your code in the DropObject event should be okay.

    if obj.FolderItemAvailable then
      dim f as FolderItem = obj.FolderItem
      
      dim path as String = f.NativePath
      
      MsgBox path
    end
  2. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...
    Edited 2 weeks ago

    your filetype goes out of scope at the end of the open handler
    and that will make this not work

  3. Niles M

    Feb 10 Pre-Release Testers

    @Norman P you filetype goes out of scope at the end of the open handler
    and that will make this not work

    Meaning?

  4. brian f

    Feb 10 Pre-Release Testers, Xojo Pro Chilly California

    Make the filetype a property of the window or app so it keeps a reference to it

  5. Emile S

    Feb 10 Europe (France, Strasbourg)
    Edited 2 weeks ago

    Use Insert… Add a File Type (in the MenuBar). Sorry, I do not found the entry in the LR.

    and feed the window.

  6. Norman P

    Feb 10 Pre-Release Testers, Xojo Pro outside listening to the crick...

    @Niles M Meaning?

    meaning that you get the exact effect you are seeing
    your file type variable needs to exist somewhere else that it will not get cleaned up at the end of the open event
    like as a property on the window itself

  7. Emile S

    Feb 10 Europe (France, Strasbourg)

    At last, I think I get the right page:

    User’s Guide - File Type Sets

  8. Niles M

    Feb 10 Pre-Release Testers

    @Emile S At last, I think I get the right page:

    User’s Guide - File Type Sets

    Yeah, I already read that. Didn't help.

  9. Niles M

    Feb 10 Pre-Release Testers
    Edited 2 weeks ago

    OK, so I setup a property under the window called misfile. I set it to a "type" FyleType.

    I set the extension to msi in the code window.

    Now, when I run the app and open that window, I get a nilobjectexception on the code me.AcceptFileDrop FileType(msifile) in the open event handler.

  10. Emile S

    Feb 10 Europe (France, Strasbourg)

    @Niles M Yeah, I already read that. Didn't help.

    Read it once more. Not only this help (once you understand it), but this is the way to go.

    A File Type Set defined this way is availabela all round the project, not only here or there; it never goes out of scope.

    Now, if you prefer to do things differently, that is your software.

    Good luck.

  11. Niles M

    Feb 10 Pre-Release Testers

    @Emile S Read it once more. Not only this help (once you understand it), but this is the way to go.

    A File Type Set defined this way is availabela all round the project, not only here or there; it never goes out of scope.

    Now, if you prefer to do things differently, that is your software.

    Good luck.

    It's not helping in the example I'm discussing.

  12. Emile S

    Feb 10 Europe (France, Strasbourg)
    Edited 2 weeks ago
    dim msifile as new filetype

    Put this where you need it, not elsewhere. So it will be available when you need it and goes out of scope as soon as you stop need it.

    But if you need it at different places in your project…

  13. Dale A

    Feb 10 Answer San Diego, California, USA

    Do you have a FileType Set in the project item list? If not, add one as Emile said earlier. In the FileType Set, set up an entry with the name 'MSI', the Display Name 'MSI', and the extension '.msi' (don't forget the dot if you are on Windows).

    In the Open event for the Bevelbutton, add the code

    Me.AcceptFileDrop ("MSI")

    Your code in the DropObject event should be okay.

    if obj.FolderItemAvailable then
      dim f as FolderItem = obj.FolderItem
      
      dim path as String = f.NativePath
      
      MsgBox path
    end
  14. Niles M

    Feb 10 Pre-Release Testers

    @Dale A dim msifile as new filetype

    So, when you say "Name" MSI, do you mean the text field under name, or the ID name off to the right? Depending on which one I name MSI, I get two very different error.

    If the text field name is set to MSI, I get am "Item does not exist" error for "Me.AcceptFileDrop ("MSI")"

    If the ID name is set to MSI I get "CREATE.BevelButton1.Open, line 2
    Expected a value of type No Type, but found a static namespace reference to No Type.
    me.AcceptFileDrop FileType(MSI)
    "

  15. Niles M

    Feb 10 Pre-Release Testers

    @Dale A Do you have a FileType Set in the project item list? If not, add one as Emile said earlier. In the FileType Set, set up an entry with the name 'MSI', the Display Name 'MSI', and the extension '.msi' (don't forget the dot if you are on Windows).

    In the Open event for the Bevelbutton, add the code

    Me.AcceptFileDrop ("MSI")

    Your code in the DropObject event should be okay.
    if obj.FolderItemAvailable then dim f as FolderItem = obj.FolderItem dim path as String = f.NativePath MsgBox path end

    I got it. Bad typing on my part. Your example worked.

    Thank you Dale and everyone!

or Sign Up to reply!