Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
include variables
#1
is there a way to define a bunch of variables in a seperate variable sheet (macro) with 'sub-global' variables ?

i am working on a recent file function which reads from the registry
and the paths to the keys are really long and there will be also much variables ...
so i would like to put them in an extra sheet.
i could use str+ a= "something" but then a is a global variable.

some kind of include like in php would be nice.

thanks from a novice

8)
pi
#2
recent files
Code:
//mru_reader
str mru
str keypath = "Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\"
//ext will be filled by function
str ext = "txt"
str key_path.format("%s%s" keypath ext)
rget(mru "MRUList" key_path 0)
out mru
//my result -> gfedcbajih
int i=len(mru)
//result len = 10, can be used for rep
out i

now i need to know how to split/slice mru
so that i can get all the values.
Code:
str value splitted
//splitted is one of mru -> gfedcbajih
rget(value splitted key_path 0)
my guess is to split the mru string to an array and
to build then a menu from that.

btw. i prepared the whole posting in a ppro note, thats much
better then the phpBB interface Smile
pi
#3
well, glad are those who can read the help Confusedhock:

Code:
//mru_reader
str mru value
str keypath = "Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU\"
//ext will me filled by function
str ext = "txt"
str key_path.format("%s%s" keypath ext)
rget(mru "MRUList" key_path 0)
//my result -> gfedcbajih
int i=len(mru)
//result i = 10, can be used for rep
str s; int va
rep i
    s.get(mru va 1)
    va+1
    rget(value s key_path 0)
    out value

Big Grin
pi
#4
pi Wrote:is there a way to define a bunch of variables in a seperate variable sheet (macro) with 'sub-global' variables ?

after reading the code from Kuukunen i found the way ...

one macro -> myVars
Code:
def some_var "huhu"

use it in related macros
Code:
#compile "myVars"

right ?
pi
#5
I don't recommend def. def constants will be global anyway. If you change def's value, you may have problems, because if other macros are already compiled with old value, they probably will not be updated.

Solution1
Use global structure:
Code:
Code in entry macro:
type REGKEYS str'key1 str'key2 etc
REGKEYS+ _rk
_rk.key1="..."
_rk.key2="..."
etc

Here structure _rk is global variable (member strings will exist all time), but it is single name in global namespace.


Solution2
Create local structure in entry macro and pass pointer to it to called macros.

But if it is too complicated (eg, thread uses many functions, callback functions) then use Solution3.
Create local structure in entry macro and store pointer to it into thread-local variable. I'll show how to access it in all functions of that thread. This method is used in Dialog Editor.
Code:
Code in entry macro:
type REGKEYS str'key1 str'key2 etc
REGKEYS rk
rk.key1="..."
rk.key2="..."
etc
tls0=&rk  ;;tls0 - 9 are thread-local ("sub-global") int variables
______________
Code in function that is directly or indirectly called from entry macro:
REGKEYS& rk=tls0
now use rk:
out rk.key1

Here structure rk is local variable (member strings are released when macro ends). Only one extra statement in each function where it will be used.


Forum Jump:


Users browsing this thread: 1 Guest(s)