Janko -
When creating code blocks in a FOR..NEXT loop that are bound to the value of k, you must "anchor" each value of k. Chris showed you that this anchoring can be done with a macro, however macro expressions require that all elements are public functions and public or private variables.
Anchoring using a Macro:
Code: Select all
bColor := &("{|| if(val(DC_GetColArray(2,oBrowse)) <val(DC_GetColArray("+str(k,2)+" ,oBrowse)) ,,{GRA_CLR_WHITE,GRA_CLR_DARKBLUE} )}")
This macro technique would require that oBrowse must be a private or public variable. It cannot be local. It would also fail because the color definitions cannot be resolved by the macro compiler and converted to numeric values. Macro compiling in a loop is not advised.
A better technique is to anchor each value of k by using "detached locals". This is accomplished with a call to a function that will build the code block. All resolutions of variables, functions and defines will be accomplished by the XPP compiler rather than the macro compiler and will allow k and oBrowse to be declared as LOCAL.
Anchoring using detached locals:
Code: Select all
bColor := ColorAnchor(k,oBrowse)
STATIC FUNCTION ColorAnchor(k,oBrowse)
RETURN {|| if(val(DC_GetColArray(2,oBrowse)) <val(DC_GetColArray(k ,oBrowse)) ,,{GRA_CLR_WHITE,GRA_CLR_DARKBLUE} )}
Also, you don't need to use the EVAL clause in your DCBROWSECOL command. Simply the COLOR bColor clause will work.
Macros have some advantages in Xbase++, but not in this case. They require that every element of the expression exist in the "symbol table". To be added to the symbol table, they must be private or public. They cannot be static or local. DC_GetColArray() is a public function, so that is not a problem. If you use the anchoring technique I advise, then any element of the expression can be static, local, public or private. Even function calls can be to static functions. This allows you to safely encapsulate your variables and functions. The XPP compiler can warn you if you make a coding error and will not allow the .EXE to be created. The macro is compiled at "runtime" and therefore coding errors are often discovered by the user of the program not the programmer. This is a bad idea.