Problems with transporting printer settings using DEVMODE
Hi!
I have the feeling, that RB has great problems with assigning printer
settings from outer/other sources... I really tried a lot of variations,
and I got to the point that I think I wasted my money on this reporting
gadget!
procedure TForm1.Button2Click(Sender: TObject);
begin
GetMem(FDevice, 500);
GetMem(FDriver, 500);
GetMem(FPort, 500);
if PrintDialog1.Execute then
begin
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
if DeviceMode = 0 then
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
Memo1.Lines.Add('PrintDialog:' + FDevice);
DevMode := GlobalLock(DeviceMode);
ppReport1.Reset;
ppReport1.DeviceType := dtPrinter;
ppReport1.Printer.SetDevMode(DeviceMode);
ppReport1.Print;
GlobalUnlock(DeviceMode);
end;
FreeMem(FDevice, 500);
FreeMem(FDriver, 500);
FreeMem(FPort, 500);
end;
You won't guess what happens: Memo1 contains the name of the printer
selected in PrintDialog1, but our 'beloved' RB prints it to the default
printer.
I mean for RB there is THE ONE AND ONLY "DEFAULT" PRINTER!!!
I never read in my life so many useless, not functioning examples and
advices like in this newsgroup...
Have a nice day (hopefully with a another reporting tool)!
Zsolt Balanyi
I have the feeling, that RB has great problems with assigning printer
settings from outer/other sources... I really tried a lot of variations,
and I got to the point that I think I wasted my money on this reporting
gadget!
procedure TForm1.Button2Click(Sender: TObject);
begin
GetMem(FDevice, 500);
GetMem(FDriver, 500);
GetMem(FPort, 500);
if PrintDialog1.Execute then
begin
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
if DeviceMode = 0 then
Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
Memo1.Lines.Add('PrintDialog:' + FDevice);
DevMode := GlobalLock(DeviceMode);
ppReport1.Reset;
ppReport1.DeviceType := dtPrinter;
ppReport1.Printer.SetDevMode(DeviceMode);
ppReport1.Print;
GlobalUnlock(DeviceMode);
end;
FreeMem(FDevice, 500);
FreeMem(FDriver, 500);
FreeMem(FPort, 500);
end;
You won't guess what happens: Memo1 contains the name of the printer
selected in PrintDialog1, but our 'beloved' RB prints it to the default
printer.
I mean for RB there is THE ONE AND ONLY "DEFAULT" PRINTER!!!
I never read in my life so many useless, not functioning examples and
advices like in this newsgroup...
Have a nice day (hopefully with a another reporting tool)!
Zsolt Balanyi
This discussion has been closed.
Comments
Please read the newsgroup guidelines and conduct yourself accordingly. These
newsgroups are a place for problem solving and colloboration about building
world class reporting solutions.
ReportBuilder does not use the Delphi TPrinter class because it is poorly
designed and poorly implemented. Instead ReportBuilder defines its own set
of Printer classes (TppPrinter, TppPrintserSetup, etc).
Here is a simple solution to your example.
uses
ppPrintr;
// configure global printer to reflect report's printersetup
ppPrinter().PrinterSetup := ppReport1.PrinterSetup;
// show windows print dialog and update report.PrinterSetup as needed
if ppPrinter().ShowSetupDialog then
ppReport1().PrinterSetup := ppPrinter.PrinterSetup;
I see the following mistakes in your code
- you do not initialize the Delphi TPrinter with the Report's PrinterSetup
- Report.Printer is read-only - it is only useful for obtaing a Printer that
is configured with the Report.PrinterSetup information.
- you need to use ppPrinter and first update ppPrinter.PrinterName and then
the DevMode. The Windows DevMode is relevant for a specific printer, it does
not contain the printer name.
- once you have updated the ppPrinter PrinterName and DevMode, then you can
update Report.PrinterSetup with ppPrinter.PrinterSetup.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com