Mega Code Archive

 
Categories / Delphi / Examples
 

Prndlgproblem

PrintDialog problem >> We are experiencing a really bad problem. We can't get either the PrintDialog or PrinterSetupDialog boxes to work more than a couple of times. We have both a menu choice and a speedbutton that runs the execute method of each dialog. After one or two times of executing neither one will work. When we issue execute, nothing happens. This happens on three different PCs all running Windows for Workgroups. Some patches to work around the problem: In DIALOGS.PAS, change { 1530 } hWndOwner := Application.Handle; { 1531 } if TaskModalDialog(@PrintDlg, PrintDlgRec) then { 1532 } SetPrinter(hDevMode, hDevNames) { 1533 } else to { 1530 } hWndOwner := Application.Handle; { 1531 } SetPrinter(hDevMode, hDevNames); { 1532 } if not TaskModalDialog(@PrintDlg, PrintDlgRec) then and { 1582 } if Result then { 1583 } begin { 1584 } SetPrinter(hDevMode, hDevNames); { 1585 } F := Flags; to { 1582 } SetPrinter(hDevMode, hDevNames); { 1583 } if Result then { 1584 } begin { 1585 } F := Flags; You also need to call the following routine once, before invoking either the print or printer setup dialogs: procedure InitPrinter; var Device, Driver, Port: array[0..79] of Char; DevMode: THandle; begin GetPrinter(Device, Driver, Port, DevMode); SetPrinter(Device, Driver, Port, DevMode); end; -Steve Schafer