Short: I heard that you should use STATIC variables instead
of PUBLICs at all times, but I can't figure out how to make
the switch.
Pull these variables in logical groups (e.g., all colors in
one place) into separate source files and declare them STATIC.
Then write a function or set of functions which allow you to get
(and optionally set) the values of these variables. For example,
COLORS1.PRG will return the current value of the cNormal variable,
and will also set the variable if you pass it a value.
// COLORS1.PRG
STATIC cNormal
FUNCTION setnorm (x)
LOCAL cRet := cNormal
IF x != NIL
cNormal := x
ENDIF
RETURN cRet
If you have more than a few of these variables to get and set this
may present a problem; the source and object code for these functions
will quickly grow out of hand! So let's take it one step further by
hiding this batch of functions with the preprocessor.
// COLORS2.PRG--Link this into your application.
// Colors: 1 Normal 2 Error Message 3 Prompt 4 F-key legend
STATIC acColor[4]
FUNCTION setstdcol (x, y)
LOCAL cRet := acColor[x]
IF y != NIL
acColor[x] := y
ENDIF
RETURN cRet
// APP.CH-- #include this in all your application's source files.
#xtranslate setnorm (<x>) => setstdcol (1, <x>)
#xtranslate seterr (<x>) => setstdcol (2, <x>)
#xtranslate setprompt (<x>) => setstdcol (3, <x>)
#xtranslate setfkey (<x>) => setstdcol (4, <x>)
With this set of directives and the single function setstdcol()
you can keep the size of your sources and EXE down. At the same
time the application programmer (you or someone else) can have a
stable interface to this array of values no matter how large the
application gets or how many new elements you want to add to the
array.