Opening a VPEPreviewDoc in one view and closing it in another
I am struggling with printing invoices with StarZens VPE classes and sending these as attachments to E-mails. The invoices are opened in a cszVpeReportView and from there a dbView is called within OnBeforeMail if the mails shall be sent with Chilkat. In this dbView, the user can make further changes in the E-mail and then either send it or cancel the operation. Now the previews are maintained after the mails are sent and have to be closed manually, but it would be much better if they were closed by the program when mails are sent successfully.
However, I haven’t found any hook in the calling cszVpeReportView that can be used for that. It seems as program execution never returns to that view. Normally I would have used OnVpeAfterMail, but that procedure is not executed when the VPE mail function isn’t used and that one only works on certain systems. If I put Send DoVpeCloseDoc in this view it works and (phDocument(Self)) has a value. But there is no good place to put that statement.
Therefore I tried to put it in the called view where the E-mail is sent. There, Send DoVpeCloseDoc gives an error “Invalid function call” and (phDocument(Self)) shows the same error in Watches.
Is there a solution to this problem? Can VPE documents only be closed in the view where they are opened?
Bengt
Re: Opening a VPEPreviewDoc in one view and closing it in another
Bengt
DoVpeCloseDoc should work all the time from anywhere.
Have never seen an Invalid function call error.
If you dont need the preview you dont have to show that either
We have a lot of very complex invoice report programs where for example all invoices to be printed are printed on paper, at the same time they are added to PDF documents, one for each customer with other files attached in between (signed documents, etc)
if you have a view called oMyFirstView and that view has a report called oMyReport you should be able to close the document with
[CODE]
Send DoVpeCloseDoc to (oMyReport(oMyFirstView(Self)))
[/CODE]
one thing to keep in mind, if you use the VpeReportView a vpe document/report will register itself with the view and will cause certain actions on the view. For example if the preview is embedded and you close the preview the vpe report object will cause the view to close as well
If you want to stop that behavior you can simply set the pbRegisterDocumentWithParent property to false
Re: Opening a VPEPreviewDoc in one view and closing it in another
[CODE]//Calling view;
Use SkickaEmail.dg
Activate_View Activate_oVPEDocPrintFaktMail for oVPEDocPrintFaktMail
Object oVPEDocPrintFaktMail is a cszVpeReportView
Object oVpeDocument is a cszVpeDocument
//Called View
Use VPEDocPrintFaktMail.pkg
Procedure Closing_View
Boolean bSent
Get pbSend to bSent
If (bSent) Send DoVpeCloseDoc to (oVpeDocument(oVPEDocPrintFaktMail(Self)))
Forward Send Closing_View
End_Procedure[/CODE]
Then the code above should work but when compiling it i get the error below on the DoVpeCloseDoc line (undefined symbol):
- Error 4328: C:\DF18proj\plv19\AppSrc\SkickaEmail.dg (ln 1919) Odefinierad symbol i argument OVPEDOCPRINTFAKTMAIL
Re: Opening a VPEPreviewDoc in one view and closing it in another
thats an undefined symbol in argument error on your object name [COLOR=#333333]OVPEDOCPRINTFAKTMAIL
either your view is not included or is included later
try a forward reference
Register_Object [/COLOR][COLOR=#333333]OVPEDOCPRINTFAKTMAIL
this is not an issue with VPE or VPE for VDF
[/COLOR]
Re: Opening a VPEPreviewDoc in one view and closing it in another
Thanks, now it works. It is obviously not always enough vith use statements in the beginning of the views. In certain cases, Register_Object seems to be needed. I also have it on a few other plases in the program.
Bengt
Re: Opening a VPEPreviewDoc in one view and closing it in another
if you have an object that is going to be defined/used later than the line you are referencing it in you need to use a forward reference (Register_Object)
generally a use statement will do
so you have firstview.vw
[CODE]
Object oMyFirstView is a dbView
Procedure TestInFirstView
..
End_Procedure
End_Object
[/CODE]
and secondview.vw
[CODE]
Object oSecondView is a dbView
Procedure TestInSecondView
..
End_Procedure
End_Object
[/CODE]
leaving discussions on proper encapsulation off the table for now lets say we want to call the first view from the second view
we will change the second view to
[CODE]
use firstview.vw
Object oSecondView is a dbView
Procedure TestInSecondView
Send TestInFirstView to oFirstView
End_Procedure
End_Object
[/CODE]
this will compile and run without issues
now lets add a call from the first view to the second view as well
lets modify firstview.vw as follows
so you have firstview.vw
[CODE]
use secondview.vw
Object oMyFirstView is a dbView
Procedure TestInFirstView
..
End_Procedure
Procedure AnotherTest
Send TestInSecondView to oSecondView
End_Procedure
End_Object
[/CODE]
thinking about what we did you would think this would end up in an issue for the compiler
compile starts compiling firstview.vw
finds line "use secondview.vw" and includes secondview.vw
finds line "use firstview.vw" and ?!@?!?
luckily the DF compiler, well actually the USE macro has a protection for this by not including a "USEd" file a second time and it will skip the use line at this time
so it keeps on compiling all the code in secondview.vw and then returns to firstview.vw to finish compiling
So in general a use should solve the issue.
But if you look back when it processes the secondview.vw file while it technically already included firstview.vw if only compiled one line and hasnt gotten to the object declaration of the view yet
Also there are some constructs that can get you in real trouble if you are placing a USE statement inside a view or dialog or report component (and i mean inside the view/report/dialog object)
If that component is deferred you can get into some real trouble