Print without displaying the form (is possible?)
I can print something without displaying the form?
In version 7 of RB, the following code worked correctly, but not in
version 15.04! Generates an Access Violation when going to destroy form.
Form2 := TForm2.Create(nil);
Form2.ppReport.ShowPrintDialog := False;
Form2.ppReport.ArchiveFileName := ExtractFilePath(ParamStr(0)) +
'teste.pdf';
Form2.ppReport.TextFileName := ppReport.ArchiveFileName;
Form2.ppReport.DeviceType := 'PDF';
Form2.ppReport.DefaultFileDeviceType := ppReport.DeviceType;
Form2.ppReport.ShowAutoSearchDialog := False;
Form2.ppReport.Print;
FreeAndNil(Form2); // <- Here Access Violation
Thanks
--
In version 7 of RB, the following code worked correctly, but not in
version 15.04! Generates an Access Violation when going to destroy form.
Form2 := TForm2.Create(nil);
Form2.ppReport.ShowPrintDialog := False;
Form2.ppReport.ArchiveFileName := ExtractFilePath(ParamStr(0)) +
'teste.pdf';
Form2.ppReport.TextFileName := ppReport.ArchiveFileName;
Form2.ppReport.DeviceType := 'PDF';
Form2.ppReport.DefaultFileDeviceType := ppReport.DeviceType;
Form2.ppReport.ShowAutoSearchDialog := False;
Form2.ppReport.Print;
FreeAndNil(Form2); // <- Here Access Violation
Thanks
--
This discussion has been closed.
Comments
I tested your exact code on my machine Delphi XE5 and RB 15.04 and it
created a PDF without errors.
Notes about your code:
1. You are setting the ArchiveFileName property to a value with the
".pdf" extension. This is not recommended due to the fact that archive
files are not PDF files and would not be useful with this extension.
2. I assume you have a report on TForm2 named "ppReport" and another
report on the main application form named "ppReport" as well? Otherwise
the code to assign the TextFileName and DefaultDeviceType would be invalid.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Actually some (few) times really not the problem, but if you click on the
button sometimes followed the error happen.
https://drive.google.com/file/d/0B6JcsVd0o8j_MVh3dnRaLUVxdVk/edit?usp=sharing
This error: "Project Project1.exe raised exception class EAccessViolation
with message 'Access violation at address 0083D316 in module
'Project1.exe'. Read of address 00000024'."
This callstak:
:75481d4d KERNELBASE.RaiseException + 0x48
:004092dc NotifyNonDelphiException + $1C
:7795f093 ntdll.RtlRaiseStatus + 0xa7
ppScreenDevice.TppScrollableScreenDevice.ehPageCache_GenerateCancel($2267608)
ppThreadedPageCache.TppThreadedPageCache.ehPageRequestThread_GenerateCancel($216A230)
ppThreadedPageCache.TppPageRequestThread.DoOnGenerateCancel
System.Classes.CheckSynchronize(???)
System.Classes.TThread.WaitFor
System.Classes.TThread.Destroy
ppThreadedPageCache.TppPageRequestThread.Destroy
System.TObject.Free
ppThreadedPageCache.TppThreadedPageCache.Destroy
System.TObject.Free
ppScreenDevice.TppScrollableScreenDevice.Destroy
System.TObject.Free
ppViewr.TppViewer.Destroy
Vcl.Controls.TWinControl.Destroy
Vcl.Forms.TScrollingWinControl.Destroy
Vcl.Forms.TCustomForm.Destroy
System.TObject.Free
Unit2.TForm2.BitBtn1Click($2205FA0)
Vcl.Controls.TControl.Click
Vcl.StdCtrls.TCustomButton.Click
Vcl.Buttons.TBitBtn.Click
Vcl.StdCtrls.TCustomButton.CNCommand(???)
Vcl.Controls.TControl.WndProc((48401, 6050, 2103202, 0, 6050, 0, (), 6050,
32, (), 0, 0, ()))
Vcl.Controls.TWinControl.WndProc((48401, 6050, 2103202, 0, 6050, 0, (),
6050, 32, (), 0, 0, ()))
Vcl.StdCtrls.TButtonControl.WndProc((48401, 6050, 2103202, 0, 6050, 0, (),
6050, 32, (), 0, 0, ()))
Vcl.Controls.TControl.Perform(???,???,2103202)
Vcl.Controls.DoControlMsg(???,(no value))
Vcl.Controls.TWinControl.WMCommand((273, (), 6050, 0, (), 2103202, 0))
Vcl.Forms.TCustomForm.WMCommand((273, (), 6050, 0, (), 2103202, 0))
Vcl.Controls.TControl.WndProc((273, 6050, 2103202, 0, 6050, 0, (), 6050,
32, (), 0, 0, ()))
Vcl.Controls.TWinControl.WndProc((273, 6050, 2103202, 0, 6050, 0, (),
6050, 32, (), 0, 0, ()))
Vcl.Forms.TCustomForm.WndProc((273, 6050, 2103202, 0, 6050, 0, (), 6050,
32, (), 0, 0, ()))
Vcl.Controls.TWinControl.MainWndProc(???)
System.Classes.StdWndProc(993032,273,6050,2103202)
:75b57834 user32.CallNextHookEx + 0x97
:75b57a9a ; C:\WINDOWS\SysWOW64\user32.dll
:75b57bed ; C:\WINDOWS\SysWOW64\user32.dll
:75b57d81 ; C:\WINDOWS\SysWOW64\user32.dll
:7795eed2 ntdll.KiUserCallbackDispatcher + 0x2e
:75b5d400 ; C:\WINDOWS\SysWOW64\user32.dll
:73d9a2e2 ;
C:\WINDOWS\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.17031_none_a9efdb8b01377ea7\comctl32.dll
:73d9a314 ;
C:\WINDOWS\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.17031_none_a9efdb8b01377ea7\comctl32.dll
:75b57834 user32.CallNextHookEx + 0x97
:75b57a9a ; C:\WINDOWS\SysWOW64\user32.dll
:75b5ce71 user32.CallWindowProcW + 0x8b
Vcl.Controls.TWinControl.DefaultHandler(???)
:00556f03 TWinControl.DefaultHandler + $EB
:00556df2 TWinControl.WndProc + $5CA
:00574d9d TButtonControl.WndProc + $71
:004d533e StdWndProc + $16
:75b57834 user32.CallNextHookEx + 0x97
:75b57a9a ; C:\WINDOWS\SysWOW64\user32.dll
:75b5988e ; C:\WINDOWS\SysWOW64\user32.dll
:75b598f1 user32.DispatchMessageW + 0x10
Thanks
Thanks for the example however it is much different than the code you
posted .
The issue is that you have the report connected to a TppViewer so when
you call Report.Print, you are exporting the report to PDF and showing
it inside the Viewer. Since the viewer uses a background thread to
create the report, you are then freeing the form before the report is
fully generated and getting an error.
To solve the problem, simply disconnect the Viewer from the report
before exporting to PDF.
ppReport.DeviceType := 'PDF';
ppViewer.Report := nil
ppReport.Print;
ppViewer.Report := ppReport;
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
\o/