Variable storage and scope (2)

Beside normal QM variables, you also can also use other media to store data.

Environment variables

When QM starts, it receives copy of system environment variables. You also can create and use your own environment variables. Your environment variables exist until QM exits (differently than normal global variables, that are destroyed when loading other file or reloading current file). Environment variables are strings.

 

To get/set/delete environment variables, use functions GetEnvVar and SetEnvVar.

 

QM file commands, dll, menus, toolbars, etc automatically expand environment variables. See also: str.expandpath.

 

Warning: You cannot be sure that an environment variable does not exist when QM or exe is just started. Environment variables usually are inherited from the process that launched current process. Be careful with environment variables in exe. If the exe is launched from QM, it may inherit or not inherit QM's environment variables. For example, it will not inherit QM's environment variables if runs with different integrity level. Instead you can use window properties with _hwndqm window.

Window properties

To associate some values with a window, you can use window properties. A window property is some numeric value (it can be int, pointer or lpstr), which has some name and can be set/retrieved/deleted using functions SetProp, GetProp and RemoveProp. Examples:

 

RECT* r
r._new
SetProp(hwnd "ra" r)
 ...
r=+GetProp(hwnd "ra")
 ...
RemoveProp(hwnd "ra")
r._delete

 

Call RemoveProp when destroying the window, for example on WM_NCDESTROY message. Read more about these functions in MSDN library.

Registry

You can use functions rget and rset to save variables in the registry.

Memory in other process

You can use __ProcessMemory class to allocate, write and read memory in context of other process.

Dll variables

Some dlls export variables. You can declare such variable as dll function, but you cannot use it directly as variable. Instead, use it indirectly through reference or pointer variable. Example:

 

dll adll #_variable
int+& _var = &_variable
 now _var can be used as dll variable _variable