Link to home
Start Free TrialLog in
Avatar of Thomas Swaney
Thomas SwaneyFlag for United States of America

asked on

FoxyPreviewer VFP issue

I have a VFP 9 program.
I have several APP's that are called from the main program to create reports.
The form that I am working with is below. The Print and Preview work perfectly with the current situation but I am facing an issue when I try to created a PDF and email it using FoxyPreviewer.

Form.png

The APP's have a basic main.prg, a form and a report.
I have added the following code to the APP form but upon clicking on the control that will run this code in the APP that is called I get a popup dialog looking for something. The files of type has All Files(*.*) chosen in this dialog.

Open.png

If I hit cancel then I get the following dialog box.
Error.png

If I click okay it actually sends the email with only part of the report (letter) filled out.
correct-call_failed.pdf (If I print or preview this is what it looks like)
incorrect-call_failed.pdf (If I run the code to convert to a PDF and email this is what I get)

Here is the code that I have in the form, of course I have filled in the .cSMTPServer, .cEmailFrom, .cSMTPUserName and cSMTPPassword with the correct information:
SET PROCEDURE TO LOCFILE("FoxyPreviewer.App") ADDITIVE 
LOCAL loReport as "PreviewHelper" OF "FoxyPreviewer.Prg" 
loReport = CREATEOBJECT("PreviewHelper") 

WITH loReport as ReportHelper 

*!*'   REPORT FORM LOCFILE(_Samples + "\Solution\Reports\Percent.frx")  PREVIEW
*!*'   REPORT FORM LOCFILE(_Samples + "\Solution\Reports\Invoice.frx")  PREVIEW
*!*'   REPORT FORM LOCFILE(_Samples + "\Solution\Reports\Colors.frx")   PREVIEW
*!*'   REPORT FORM LOCFILE(_Samples + "\Solution\Reports\Wrapping.frx") PREVIEW

*!*   .AddReport(_Samples + "\Solution\Reports\percent.frx", "NODIALOG") 
.AddReport("C:\Project\CW\Reports\Internal_Forms\Call_Failed\call_failed.frx", "NODIALOG") 
.cDestFile      = "c:\foxtemps\call_failed.pdf"  && Use to create an output without previewing

.lAutoSendMail  = .T.
.lEmailAuto     = .T.   && Automatically generates the report output file
.cEmailType     = "PDF" && The file type to be used in Emails (PDF, RTF, HTML or XLS)

.cEmailTo       = thisform.txtemailAdd.value
.cSMTPServer    = ""
.cEmailFrom     = ""
.cEmailSubject  = "Subject test"

.nSMTPPort      = 25
.lSMTPUseSSL    = .T.
.cSMTPUserName  = ""
.cSMTPPassword  = ""

.lReadReceipt   = .T.
.lPriority      = .T.

.cAttachments   = GETFILE() && Comma delimited

*!*'   .cEmailCC
*!*'   .cEmailBCC
*!*'   .cEmailReplyTo

*!*' * Uncomment next lines to send HTML body
*!*' *.cHtmlBody = "<html><body><b>This is an HTML body<br>" + ;
*!*' *      "It'll be displayed by most email clients</b></body></html>"
*!*'
*!*' .cTextBody = _goHelper.cEmailBody
*!*' && "This is a text body." + CHR(13) + CHR(10) + ;
*!*' && "It'll be displayed if HTML body is not present or by text only email clients"

.cEmailBody = "<HTML><BR>Email Test with <b>FoxyPreviewer</b></HTML>"

*!*'         * Attachments are optional
*!*'         IF NOT EMPTY(_goHelper._cAttachment) && "myreport.pdf, myspreadsheet.xls"
*!*'            .cAttachment = _goHelper._cAttachment
*!*'         ELSE 
*!*'            .cAttachment = tcFile
*!*'         ENDIF

.RunReport() 
ENDWITH 
loReport = NULL 
*' RUN /N Explorer.Exe c:\Teste1.pdf 

*!*   RETURN

Open in new window


I have also attached the report format files call_failed.frt and call_failed.frx.
call_failed.FRT
call_failed.frx

There is another issue.
The main app lives in a folder and the app's live in subfolders under the main app folder.
As you can see below I have used the path to the FRX although in a live running app the file could not be located in this directory and normally I would not include the .frx files outside of compiling them within the .exe anyway which works great when just doing a preview or print from this form.

.AddReport("C:\Project\CW\Reports\Internal_Forms\Call_Failed\call_failed.frx", "NODIALOG")

Open in new window


Thanks for any help in advance.

Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Some images are missing in your question so I may just guess...
The dialog is caused by the GETFILE() function call. This function allows to select any file from your computer and sets this file as the e-mail attachment:
User generated image
Because I have no sample data and I don't know all conditions I cannot say why just the report heading is printed to PDF. Isn't the record pointer at EOF?
Avatar of Thomas Swaney

ASKER

Please see the images that I have added. 
Object is not contained in a form could be caused by THISFORM references used in the report fields. PDF creation moves the control outside the form so THISFORM cannot work.  Preview does not go out of the current form.

You may try following:
Replace all occurrences of THISFORM in the report by variable, e.g. poThisForm, and use this variable inside the report. Add the variable initialization into your code for all actions (Preview, Print, e-mail)
PRIVATE poThisForm
poThisForm = THISFORM
... here is the code to run the report ...
RELEASE poThisForm

Open in new window

If the PRIVATE variable does not help try to declare it as PUBLIC instead of PRIVATE but I believe it will be OK with private var.
Okay let me try that and I will let you know. Thank you. 
What do you suggest about the .frx issue? 
If the FRX and FRT is included in EXE then the path should be ignored at run-time. Just try to build the EXE with non-existing path.
I just tested this and it didn't work.
Here were my steps:
1. I removed the path to the FRX in the code in the APP.
2. I rebuilt the APP.  
3. I copied the FRT and FRX to my main folder directory.
4. I made sure that these files were in my main project.
4. I copied the new .exe and .app to my test directory.
5. I got the following error message. 

error.jpg  
Are you sure the FRX and FRT files are included in EXE? If yes then FoxyPreviewer needs them in a disk folder.
Both files were in my APP and EXE. I wish there was a way around this. I have about 59 reports that I will need to modify just because I am adding email capability and I really hate to have to copy the report files to my customers machines. I have FRX2ANY if there is a better way with it and I am using it currently in my main program for emailing reports/forms. 
I am using FoxyPreviewer in a different way and all my reports can stay in EXE but I am not generating PDF e-mails...

OTOH, you may include the reports into the EXE and copy them out at run-time (under different name).

If you would use PDF printer driver then you don't need any change in the reports you just have to find PDF printer driver which allows to set the output file programatically from VFP 9.
You could also look at XFRX which also supports PDF generation and e-mails sending from VFP 9.

Many alternate ways how to implement your new requirement exist.

Anyway, to use THISFORM reference inside the report is not recommended practice at all. Fixing all these reports just represents certain code cleanup.


So I did a short test with PDF creation and it really needs the report in folder on disk...
The work around was to copy the file included in EXE out to the disk:
COPY FILE _insideExe.frx TO d:\path\NewName.frx
COPY FILE _insideExe.frt TO d:\path\NewName.frt

Open in new window

and use it in FoxyPreviewer. You may use SYS(2023) and place the report file into temp folder and delete it afterwards...
Okay I am not finding a way without having the FRX and FRT files in the same folder as the EXE.

Please show me how you getting the FRX and FRT out of the EXE.
Use an example with the following files names please:
CW.EXE
CALL_FAIL.APP

I am not understanding if the _ in the above example means something special since it isn't working for me:
_insideExe.frx

I even tried to include the FRX and FRT files in the Other Files of the project but that doesn't work for me. 
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wait please, working on update...
OK, the code was updated, you may test it
I just forgot to mention: You may add path to the report file names in FILETOSTR() function call. It will allow to execute the report in dev environment.  Of course, file names (testiky.frx, testiky.frt) were used just for my testing and you may use your original report file names.

Thank you very much pcelba. I will take a look at this over the weekend. I have been swamped and haven't had a chance to test since my last message.
That works great!! Thank you VERY MUCH!!
I just wonder how calling =STRTOFILE(FILETOSTR("testiky.frx") knows to look in the .exe that it is running from? Is there any documentation on this somewhere that I can read?

Common rule says "The file included in EXE has precedence over the same file on disk". But this rule is not valid for COPY FILE command (and maybe more, I am not sure right now). This is not documented and the only possibility is to test it...
Thank you. It works and that is good enough for me. :)