Project

General

Profile

Up

_OBJsetCBfromOld

Change the current callback by a new one.
Same thing for the user parameter.

Prototype :

fun [u0 u1 u1 u2 I] I

  • u0 : a Scol object
  • u1 : the current callback (by example : @myOldCallbackForThisEvent)
  • u1 : the new callback to set, can be nil to ignore this event (by example : @myNewCallbackForThisEvent).
  • u2 : the new user parameter to set
  • I : a flag : 0 to set callback AND user parameter, 1 to set the callback only, 2 to set the user parameter only. Default : 0.

Return : I 0. It returns nil if error.

Error :

  • EOK if success.
  • EARGNIL if the given object is nil.
  • ENOFOUND if a required internal object is not found, maybe a system object already deleted.

See also :

Example :

typeof win = ObjWin;;

fun cb_destroy2 (o, u)=
	_fooId u*2;;	// Console : 22
	
fun cb_destroy (o, u)=
	_fooId u;;	// Console : 7
	
fun main ()=
	_showconsole;
	// ...
	set win = _CRwindow _channel nil 200 250 400 500 WN_NORMAL "A";
	_fooId _OBJsetCB win 7 @cb_destroy 7 0; // or _CBwinDestroy win @cb_destroy 7;
	// ...
	_fooId _OBJsetCBfromOld win @cb_destroy @cb_destroy2 11 0;
	// ...
	0;;

Note :

This functions sets only the first occurence found

For be safer, the old and the new callback must have the same prototype. Else, the VM will crash. In the future, we may authorize another prototype. In this case, this will have no effect on the previous Scol written source code.

Thus, the old and new user parameters must have the same type. In the future, this behavior could be modified by us. If any, it will be no effect for existing source code.

The old link and the old user parameter are lost. If any, you can store them before change by calling _OBJgetCB. This change is done immediately until another call, if any.

Of course, the developer should directly call the reflex definition function (for example _CBwinDestroy in the example above). _OBJsetCBfromOld is another way to set multiple CB or what he/she wants !