B4J Library jDragAndDrop2 - Drag and Drop

alirezahassan

Active Member
Licensed User
thank you dear @stevel05,
I solved my problem. The following code was originally my code.
old code:
Sub DropTarget_Text_DragDropped(e As DragEvent)
    Try
        Dim pathsss As String = File.GetFileParent(e.GetDragboard.GetFiles.Get(0))
        Dim namesss As String = File.GetName(e.GetDragboard.GetFiles.Get(0))
        TXT_Text.Visible = False
        IMG_Text.Visible = True
        Wait For (Codes.Compress(pathsss,namesss)) Complete (Completed As Image)
        IMG_Text.SetImage(Completed)
        Loadings.Loading_Show(MainForm)
-->  uploudFile(File.GetFileParent(e.GetDragboard.GetFiles.Get(0)),File.GetName(e.GetDragboard.GetFiles.Get(0)),"Text")
        e.SetDropCompleted(True)
    Catch
        Log(LastException)
    End Try
End Sub
I changed the above code
New code:
Sub DropTarget_Text_DragDropped(e As DragEvent)
    Try
        Dim pathsss As String = File.GetFileParent(e.GetDragboard.GetFiles.Get(0))
        Dim namesss As String = File.GetName(e.GetDragboard.GetFiles.Get(0))
        TXT_Text.Visible = False
        IMG_Text.Visible = True
        Wait For (Codes.Compress(pathsss,namesss)) Complete (Completed As Image)
        IMG_Text.SetImage(Completed)
        Loadings.Loading_Show(MainForm)
 --> uploudFile(pathsss,namesss,"Text")
        e.SetDropCompleted(True)
    Catch
        Log(LastException)
    End Try
End Sub
I realized that this error occurred after the (Wait For) code. After the (Wait For) code, the variable e was cleared! It is as if the inputs are empty after the (Wait For) code.
I defined two variables. And after the (Wait For) code, its value was not cleared. I think this is a bug @Erel.
Thanks for following up Mr. @stevel05
 

stevel05

Expert
Licensed User
Longtime User
Yes, you accept the dragged item in the _DragOver sub for each target, so you can use various methods to identify if you want to accept the drop for each target.
i.e. FileType, dragboard content type, or dataid (set in _Source_DragDetected sub) etc.

You just need to create a different DragAndDrop Class instance and call MakeDragTarget on it for each target and create the related subs. You don't need to call MakeDragSource for each class instance.
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Yes, I noticed your post and am in the process of changing it. I will only be publishing a b4xlib for this and not a compiled library. Fortunately it is an internal variable. I'll post it here as soon as I've updated it.
 

stevel05

Expert
Licensed User
Longtime User
OK, I've replaced the original zip with a B4xlib, I am in the process of setting up a new PC, so I hope I've picked the right project :

Replaced an internal global Initialized with IInitialized. I apologise If you were using the original compiled library, hopefully there aren't any breaking changes. I have tested it on a couple of my own projects. Let me know if you find any problems.
 

stevel05

Expert
Licensed User
Longtime User
I don't like either of them, neither blnInitialized nor IInitialized
No, but it's late and my brain couldn't think of anything else. Might have taken another week to come up with something.

There are a few version on different posts around the forum, I'll have to see if I can find them and remove the old ones.
 

stevel05

Expert
Licensed User
Longtime User
I like having B4xlib in the name so that I can identify them in the long list of libraries I have, and adding 1 character to a variable name is not really a whole point version change.