A colleague using VFP7 asked recently about removing those pesky printer references in reports. Of course, you have a way to manually remove them in VFP8 and VFP9 (report menu-printer environment and also for VFP9 report properties).
In case you still maintain projects in VFP7 and/or upgrade report files into projects using versions 8 or 9, trying to remove those printer references (if any) automatically won't hurt your project after all. The best known option for this is to put some code in your project hook class 'beforebuild' method.
Most Fox people know that they can associate a ProjectHook visual class with their projects using the Project Menu options available; Since I couldn't send to my colleague the visual class as a file (it was an internet newsgroup), I thought of a way to do this programatically so here's another way to do it, probably useful in case you had your classes defined in a prg. The downside is that the ProjectHook reference does not persist when you close the project.
This code takes care of creating the class file and adding at least one file to the project in order to build it as an APP, needles to say these are things needed for this example only, in a real life scenario those 2 would be existing files.
#include foxpro.h
clear
IF FILE("foo.prg")
DELETE FILE FOO.PRG
ENDIF
IF FILE("MyClasses.PRG")
DELETE FILE MyClasses.PRG
ENDIF
IF FILE("MyProject.pjx")
DELETE FILE MyProject.*
ENDIF
LOCAL lcMyProjectHookVar
TEXT TO lcMyProjectHookVar noshow
**************************************************
*-- Class: myphook (c:\noninteractive\annunciacurrent\phookexample.vcx)
*-- ParentClass: projecthook
*-- BaseClass: projecthook
*-- Time Stamp: 02/17/06 03:49:02 PM
*
DEFINE CLASS myphook AS projecthook
Height = 22
Width = 23
Name = "myphook"
*-- Cleans Fields EXPR, TAG, TAG2 Contents On First Record Of Report File
PROCEDURE cleanreportprinterreferences
PRIVATE a
WITH _vfp.ActiveProject.Files
FOR a=1 TO .Count
IF UPPER(JUSTEXT(.Item(a).Name))="FRX"
USE .Item(a).Name EXCLUSIVE
REPLACE expr WITH "", tag WITH "",tag2 WITH ""
PACK
USE IN JUSTSTEM(.Item(a).Name)
ENDIF
NEXT
ENDWITH
ENDPROC
PROCEDURE BeforeBuild
LPARAMETERS cOutputName, nBuildAction, lRebuildAll, lShowErrors, lBuildNewGuids
WAIT WINDOW "Hello World from BEFOREBUILD" TIMEOUT 5
THIS.CleanReportPrinterReferences()
ENDPROC
ENDDEFINE
*
*-- EndDefine: myphook
**************************************************endtet
ENDTEXT
STRTOFILE(lcMyProjectHookVar ,"MyClasses.PRG",0)
STRTOFILE("* Main Program PlaceHolder","FOO.PRG",0)
SET PROCEDURE TO MyClasses.PRG
MODIFY PROJECT MyProject NOWAIT noshow
_VFP.ActiveProject.ProjectHook = NewObject('MyPHook')
IF VARTYPE(_VFP.ActiveProject.ProjectHook)=="O"
?DATETIME(),": ProjectHook Created Succesfully"
ELSE
?DATETIME(),": WARNING->ProjectHook NOT Created Succesfully"
ENDIF
IF FILE("FOO.PRG")
_VFP.ActiveProject.Files.Add("FOO.PRG")
?DATETIME(),": FOO.PRG added to the project, BUILD about to run."
IF _VFP.ActiveProject.Build(JUSTSTEM(_VFP.ActiveProject.Name), BUILDACTION_BUILDAPP )
?DATETIME(),": BUILD WAS SUCCESSFUL!"
ELSE
?DATETIME(),": WARNING->BUILD WAS UNSUCCESSFUL"
ENDIF
ELSE
?DATETIME(),": WARNING->Could not add a file to the project, BUILD not run."
ENDIF
_vfp.ActiveProject.Visible=.t.