XWidgetSoft Forum
https://www.bbs.xwidget.com/

BUG: Functions cannot be assigned to events in code
https://www.bbs.xwidget.com/viewtopic.php?f=3&t=6850
Page 1 of 1

Author:  yereverluvinuncleber [ January 30th, 2018, 10:49 am ]
Post subject:  BUG: Functions cannot be assigned to events in code

An object event such as a dragdrop onto an image can be assigned Functions using the IDE that results in the following stub code:

Code:
function tapOnDragDrop(Sender,Data,Point)
{

}


and an entry in main.xul that actually associates the image event with the function:

Code:
<image name="tap"  onDragDrop="tapOnDragDrop"/>


Unfortunately, Xwidget does not allow you to associate a function to an object using code, it has to be done via the IDE. This sort of dynamic function assignment is not possible in Xwidget because the engine ignores any standard function definitions in code:

The following is a standard method of assigning a function in code using all variants of javascript.

Code:
lightTap.onMouseDown = function() {
.
.
.
}


In one of my programs I have a long bit of code duplicating twelve button images that could be concatenated to one function like this:

Code:
 if (playListText.length > 0) {
      for (var i in playListText) {
          (function(i) {
                 playListText[i].onDragDrop = function (event) {
                     dropPosition = i;
                     catchFileDrop(event, null);
                 }
          })(parseFloat(i));  //protect this value by setting it as value of a numeric variable in an immediately-called function
        }
 }


This code is perfectly valid javascript, it works in MS jscript upon which Xwidgets is based. It is just because xwidgets hijacks function definitions and insists they must be done manually through the IDE in order to be valid, that it no longer operates.

This code works in a browser and in the yahoo widget engine. Not in Xwidget.

The developer Tony should look at changing his engine to allow standard definitions in code. It can be done, it has been done. It is sad that Xwidgets is crippled in this way as it means standard javascript cannot be migrated to Xwidgets easily. It also results in kludgy code.



PS. Jim, add this please to the list of bugs.

Author:  yereverluvinuncleber [ February 17th, 2018, 1:30 am ]
Post subject:  Re: BUG: Functions cannot be assigned to events in code

Doing things the Xwidget way forces all object events and definitions into the main.xul file. This is an old-fashioned and very primitive way of defining objects and events.

The much more sensible thing would be to allow the same events to be defined in code. Done this way any widget code becomes much more transportable from one engine to another.

The yahoo widget engine defines all such events in the .KON file, the equivalent to Xwidget's main.xul file. The main advantage is that it also allows the same objects and events to be defined in code as does javascript for the web.

Code:
lightTap.onMouseDown = function() {
.
.
.
}

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/