WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Global Pointers

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Restriction on ptrGlobalDefine


Question:

The restriction on ptrGlobalDefine where it can only be used from the main program somewhat damages it's usefulness in certain circumstances.

I'm wondering if there was some fundamental limitation that caused this restriction? Here's the thing -- Because it can't be used from a UDF, it hinders it's usefulness:

Example: you make a package of UDFs (call it Pack), with a UDS initializer (call it Init). Init uses ptrGlobalDefine to set up a shared array or something. Works great, I've tried it, all udfs in Pack see the array. Big step forward for WinBatch, IMHO.

But what if you want to call and use Pack from another UDF (call it Fred)? That won't work, because Init won't be getting called from the main program. Boom.

Easy enough to fix I guess, by moving the Init call out of Fred into the main program. But the main program should not have to assist in internal details of Fred. It should simply pass in parameters and consume results.

Any chance the restriction might be removed? Certainly, the programmer would have to realize that the "Global" variable he is creating is only visible at the level where it was created and up. In exchange for this possible source of confusion, the function would be made considerably more useful.

Answer:

Solution is simply a new "getmyglobal" pointer udf that all the UDFS`call to share a`pointer to a persistent varible via the PtrPersistent function.

The ptrGlobalDefine is required in the top level just to "flag" possibl global variables that can be changed with no visible connection.

Use ptrPersistent from a single udf and share that pointer with all the other udfs.


Article ID:   W16984
File Created: 2007:07:03:14:27:28
Last Updated: 2007:07:03:14:27:28