Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamically changing Report colors
Message
De
15/06/2004 11:15:49
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro Beta
Titre:
Dynamically changing Report colors
Divers
Thread ID:
00913895
Message ID:
00913895
Vues:
50
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.
* get an instance of a ReportListener
olistener = CREATEOBJECT("MyTestListener")
* run a report referencing the configured listener 
REPORT FORM (_samples+"solution\reports\invoice.frx") ;
  OBJECT olistener RANGE 1,2

DEFINE CLASS MyTestListener AS ReportListener
  listenertype = 1  && PREVIEW

  FUNCTION EvaluateContents(nFRXRecno, oObjProperties) AS Boolean
	* see if we're on the invoice.unit_price_b field
	SET DATASESSION TO (THIS.FRXDataSession)
	GOTO nFRXRecno
	IF TRIM(Expr) == "invoice.unit_price_b"
		* red text
		oObjProperties.PenRed = 255
		oObjProperties.PenGreen = 0
		oObjProperties.PenBlue = 0
		* pale yellow background
		oObjProperties.FillRed = 255
		oObjProperties.FillGreen = 255
		oObjProperties.FillBlue = 0
		oObjProperties.FillAlpha = 128
		* flag that something changed
		oObjProperties.Reload = .t.
	ENDIF
	SET DATASESSION TO (THIS.CurrentDataSession)	
	RETURN .t.
  ENDFUNC
ENDDEFINE
David Stevenson, MCSD, 2-time VFP MVP / St. Petersburg, FL USA / david@topstrategies.com
Répondre
Fil
Voir

Click here to load this message in the networking platform