While answering someone's question on ProFox earlier today, I put together a simple sample of changing colors on a report in the EvaluateContents method of ReportListener.
The Release Notes have a sample "EvaluateContents.htm" that changes colors, but that is not based on which field or expression is being evaluated. ReportListener gives us access to a FRXDataSession and tells us the nFRXRecno being evaluated, so we should be able to drill down into the FRX to see the exact Expression and conditionally use that info.
Here is an example that checks the FRX under the hood from the EvaluateContents method, determines if we have a certain field being evaluated, then changes its font color to red and background to pale yellow. This sample code works, but I don't know if I'm following the best approach or opening up a can of worms. I'm hoping for confirmation or correction from anyone in the know (there are a few of those hanging out here these days).
PLEASE don't take this as a best practice, but take it for what it is: a first lame attempt. :-)
Put this code into a PRG and run it. Click OK on the date selector that comes up, then you'll get a preview window with 2 pages of invoices. NOTE: This sample report has not yet been adjusted for the new report engine, so some fields overflow and end up as "*****". This is a known problem, already reported to the team.
olistener = CREATEOBJECT("MyTestListener")
REPORT FORM (_samples+"solution\reports\invoice.frx") ;
OBJECT olistener RANGE 1,2
DEFINE CLASS MyTestListener AS ReportListener
listenertype = 1
FUNCTION EvaluateContents(nFRXRecno, oObjProperties) AS Boolean
SET DATASESSION TO (THIS.FRXDataSession)
GOTO nFRXRecno
IF TRIM(Expr) == "invoice.unit_price_b"
oObjProperties.PenRed = 255
oObjProperties.PenGreen = 0
oObjProperties.PenBlue = 0
oObjProperties.FillRed = 255
oObjProperties.FillGreen = 255
oObjProperties.FillBlue = 0
oObjProperties.FillAlpha = 128
oObjProperties.Reload = .t.
ENDIF
SET DATASESSION TO (THIS.CurrentDataSession)
RETURN .t.
ENDFUNC
ENDDEFINE