Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Filter function problem
#7
Macro Macro243
Code:
Copy      Help
;GLOBAL VARIABLES

;Case A:
int+ g_globalVariable ;;declare a global variable. If already exists, do nothing.
g_globalVariable=100 ;;assign a value
;Case B:
int+ g_globalVariable=100 ;;declaration and assignment in single statement

;Cases A and B are equivalent.
;Case B is just a shorter way to declare and assign.
;int+ g_globalVariable does not change the value.
;g_globalVariable=100 is executed in both cases, every time.
;The variable has the value assigned last time, regardless whether it was case A or B.
;Global variables are shared by all functions. Currently QM does not have a local scope for global variables.
;__________________________________

;THREAD VARIABLES

;Case C:
int- g_gthreadVariable ;;declare a thread variable. If already exists, do nothing.
g_gthreadVariable=100 ;;assign a value
;Case D:
int- g_gthreadVariable=100 ;;declaration and assignment in single statement

;In case C, assignment is executed every time.
;In case D, assignment is executed once.
;If int- (like in the example), the variable is shared between all functions of current thread. Anyway, need to declare in all functions where used.
;If int--, the variable is not shared. If same declaration is in other function, it is other variable.

;__________________________________

;More info in QM Help topic "Variable storage and scope".

All filter functions run in one special thread. Therefore thread variables can be used to keep value available between filter function calls.
But if you run a function with mac, the function runs in own thread, therefore need to use global variables.


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)