Global Declarations Imprimer cette rubrique Page précédente Un niveau supérieur Page suivante

Accueil >  Programmers' Reference > Scripting Editor >

Global Declarations

The Global Declarations component is present by default in every Scripting Project (see screenshot below), and therefore does not have to be created. In order to add variables and functions to the Global Declarations script of a Scripting Project, you need to open the Global Declarations script and add the code fragment to the Global Declarations script. See Components of a Scripting Project and Creating a Scripting Project for more information.




To open the Global Declarations script of a Scripting Project, right-click the Global Declarations item in the Scripting Project Tree (screenshot above), and select Open. The Global Declarations script opens in the Main Window.


Note:        Every time a macro is executed or an event handler is called, global declarations are re-initialized.


Given below is an example function. Remember that creating a variable or function in the Global Declarations script makes this variable or function accessible to all Forms, Event Handlers, and Macros.



Example function

A function called RemoveAllNamespaces would have code like this:


function RemoveAllNamespaces(objXMLData)


 if(objXMLData == null)



 if(objXMLData.HasChildren)        {        

         var objChild;


         // spyXMLDataElement := 4

         objChild = objXMLData.GetFirstChild(4);


         while(objChild)        {



                         try        {

                                 var nPos,txtName;

                                 txtName = objChild.Name;


                                 if((nPos = txtName.indexOf(":")) >= 0)        {

                                         objChild.Name = txtName.substring(nPos+1);



         objChild = objXMLData.GetNextChild();


                         catch(Err)        {

                                 objChild = null;










It is possible to define local variables and helper functions within macros and event handlers. Example:


//return value: true allows editing

//return value: false disallows editing

var txtLocal;

function Helper()


 txtMessage = txtLocal;



function On_BeforeStartEditing(objXMLData)


 txtLocal = "On_BeforeStartEditing()";




Recursive functions are supported.


© 2018 Altova GmbH