_O_Drag and Drop Properties in v18

I use the method DRAG AND DROP PROPERTIES a lot in my application to drag rows up and down in list boxes. This command is great because it is a single call with ON DROP and gives me a pointer to the source of the drag. To replace this code I have to enable On Begin Drag Over on all of my listBoxes and set a variable to confirm the drag is from the same object.

Is there an easier way to do this maybe?

Normally, you shouldn’t spend time in re-writing _o_ commands if they are still working. Deprecated means 4D is not invested in those commands because

  1. There is a better alternative, or
  2. The underlying technology is no longer maintained by Apple, Microsoft or another third party

First step is to stop using it for new development. Next is to fully understand the reason behind the deprecation. Then you can make an informed decision.

For instance, you probably know that DRAG AND DROP PROPERTIES behaviour is counter-intuitive when the source and target belong to a different process. This is implied in the recommendation:

Compatibility note: Since version 11 of 4D, it is recommended to manage drag and drop operations, especially interprocess ones, using the On Begin Drag Over event and the commands of the Pasteboard theme.


There are other cases where the new way is superior. If you feel that “(the old) command is great” then you probably have no reason to replace it.

Thanks for the clarification Miyako. I was always under the impression that deprecated calls would eventually be removed from the language and as such need to be replaced at some point.

deprecated commands will be removed sooner or later, while it sometimes takes many years.
as first results it means we think there are much better ways to solve something and they should not used for new development and whenever existing code is touched, it should be considered to rewrite them.

For Drag&Drop, I believe so since v11, meaning more than 10 years.

The old commands required that sender & receiver are hard linked. it only works if both are connected.
If you want to add a 3rd element in that game, both existing ones needs to be rewritten.
As result, using the old concept, only a small group of objects supported drag&drop.

If you would consider to use the “new” (v11) approach, the same code would support drag&drop from listbox1 to listbox1, from listbox1 to listbox2 and even to Excel or other external applications.
Same window or other windows. Same process or other processes.

A very different way of thinking. For any object, write the “drag” code. The object only needs to know how to expose his data.
For any other, write the “drop” code. The object only needs to know how to receive data or respond to drops.

Following this concept opens very new possiblities…

I agree that the new commands are better for true drag and drop. The only thing I need DRAG AND DROP PROPERTIES for is dragging items around (re-ordering) in the same listbox. I can use the new commands to do this but I would have to updated a few dozen forms.

Why not to think about

	: ($evt=On Row Moved)

? This append only for re-ordering in listbox. It will simplify your code a lot !
Ok, I can give you some generic code to reorganize, supposing id is field 1.

Method y_Fmove_LB


LISTBOX MOVED ROW NUMBER($ptr_LB->;$oldLine;$newLine)

READ WRITE($table->)
Case of 
	: ($newLine<$oldLine)  // De $newLine à $oldLine => recalcul ordre
		For ($i;$newLine;$oldLine)
			If (Locked($table->))
				SAVE RECORD($table->)
			End if 
		End for 
	: ($newLine>$oldLine)  // De $oldLine à $newLine => recalcul ordre
		For ($i;$oldLine;$newLine)
			If (Locked($table->))
				SAVE RECORD($table->)
			End if 
		End for 
End case 
x_closeTable ($table)

And the call On Row Moved

		If (y_Fmove_LB ($table;->[Banks_Buttons]noOrder;$ptr_LB;$ptr_LB_id;$ptr_LB_no))
			F_BANK_BTN_groutine ("LB_LOAD")  // Récup la liste comme avant
		End if 

$table is ->[myTable]
and $ptr_LB… are all pointer to listbox columns.

F_BANK_BTN_groutine (“LB_LOAD”)
Reload the listbox in case of an error (some records went locked during renumbering). A sort of undo…
Tell me if it helps !

[Edit] x_closeTable

READ ONLY($1->)```

But I have an issue, which is exactly opposite as yours :slight_smile:

When I drag and drop from a listbox, I need to detect and reject a begin of a drop if I release it in the same listbox ! As the listbox can be the source of a drag and a target of a drop, but not from itself.
The only way I found is :

		$ptr:=OBJECT Get pointer(Object named;"LB_Visu")
		_O_DRAG AND DROP PROPERTIES($srcObjet;$srcElément;$srcProcess)
		If ($srcObjet#$ptr)

Some one has a suggestion without using this deprecated command ?

Not sure if this is what you are looking for but I do this with a variable on the listbox method:

Case of 
	: (FORM Event=On Load)
	: (FORM Event=On Begin Drag Over)
		sourceName_t:="contacts_lb"  // listbox name
	: (FORM Event=On Drop)
		If (sourceName_t="contacts_lb")
			  // drag from same listbox so do nothing
			  // *** Do Drop Code
		End if 
End case 

Yes, nothing better…

1 on row moved isn’t available with collections or entities list box. So you must manage the reordering.
2 there is another thread on the same subject. And I made a little database where I refuse internal drag and drop.

Oh thanks Vincent, but the link is 4d.com

About which link are you talking ?

This is a link, supposed to an article about this. But the link is just 4d.com.

Oh the link is good now :slight_smile: So I found your original article. Thanks.