Pages: 1
Print
Author Topic: Global Function and variable  (Read 2524 times)
gcrews
Member

Posts: 265


« on: November 08, 2010, 12:47:41 PM »

Is there a way to use the same function between different macros and have a variable that keeps its value between macros?

The On_Application_Query_Service stuff in the programmer’s guid seems to be kind of what I’m looking for. The example has the flowing line:
Application.QueriedServiceImpl = getMyService();
Where do you define the getMyService() function though?  If I have a variable in a prototype class will it persist between service calls to it?
« Last Edit: November 08, 2010, 01:08:58 PM by gcrews » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2580



WWW
« Reply #1 on: November 08, 2010, 01:14:20 PM »

Although you can declare a function in any macro the event called On_Macro_File_Load is a good place to declare them (it is a clean place to do it and this event runs when an MCR is loaded, so the function will be there provided the MCR loaded).

To store values for document-level macros you can use these:

DocumentProperties (and its associated APIs "add", "item" and "count")

The actual API you use to get to DocumentProperties is ActiveDocument.CustomDocumentProperties.

For application-level macros you can use Application.CustomProperties.
Logged
gcrews
Member

Posts: 265


« Reply #2 on: November 08, 2010, 01:20:59 PM »

Ah I see now just found the doc "Variable scope in XMetaL Author". I tried a while back using a function between macros and it didn’t work and thought the macro code functions were completely separate. Thank you that makes complete sense now.
Logged
Pages: 1
Print
Jump to: