2022年6月15日 星期三

操作Printers.Printer.PrintIndex 無法變更 QuickReport PrintSetup裡的輸出印表機!?

Uses Printers;
...
Printers.Printer.PrintIndex := 1;  //指定輸出的印表機索引,不會變更預設印表機
...

TPrintDialog會依據PrintIndex的變更指向對應的印表機,
QuickReport PrintSetup沒有因為PrintIndex變更指定輸出的印表機,維持指向預設印表機。


修正QuickReport QRPrnSu.pas文件

Ver. QuickRep506 
File : QRPrnSu.pas
Proceure : GetPrinter

原內容

{ TQRBasePrintDialog }
// HERE the important changes - see dialogs.pas from delphi vcl - source.
// note the Brackets and type casts! It's tricky :-)

procedure TQRBasePrintDialog.GetPrinter(var DeviceMode, DeviceNames: THandle);
var
  DevNames: PDevNames;
  Offset: PChar;
  size : integer;
begin
  FPrinter.GetPrinter(Device, Driver, Port, DeviceMode);
  if DeviceMode <> 0 then
  begin
    size:=SizeOf(TDevNames) +
          (StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3) *Sizeof(Char);
    //DeviceNames := GlobalAlloc(GHND,SizeOf(TDevNames) +
    //               (StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3) *Sizeof(Char));
    //DevNames := PDevNames(GlobalLock(DeviceNames));
    GetMem(DevNames, Size);
    try
      Offset := PChar(PByte(DevNames) + SizeOf(TDevnames));
      with DevNames^ do
      begin
        wDriverOffset := NativeInt(Offset) - NativeInt(DevNames);
        Offset := StrECopy(Offset, Driver) + 1;
        wDeviceOffset := NativeInt(Offset) - NativeInt(DevNames);
        Offset := StrECopy(Offset, Device) + 1;
        wOutputOffset := NativeInt(Offset) - NativeInt(DevNames);;
        StrCopy(Offset, Port);
      end;
    finally
      //GlobalUnlock(DeviceNames);
      FreeMem(DevNames, Size);
    end;
  end;
end;


參考備註指定的 Dialogs.pas 修正

{ TQRBasePrintDialog }
// HERE the important changes - see dialogs.pas from delphi vcl - source.
// note the Brackets and type casts! It's tricky :-)

procedure TQRBasePrintDialog.GetPrinter(var DeviceMode, DeviceNames: THandle);
var
  DevNames: PDevNames;
  Offset: PChar;
  size : integer;
begin
  FPrinter.GetPrinter(Device, Driver, Port, DeviceMode);
  if DeviceMode <> 0 then
  begin
    //size:=SizeOf(TDevNames) +
    //      (StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3) *Sizeof(Char);
    DeviceNames := GlobalAlloc(GHND, SizeOf(TDevNames) +
                   (StrLen(Device) + StrLen(Driver) + StrLen(Port) + 3) *Sizeof(Char));
    DevNames := PDevNames(GlobalLock(DeviceNames));
    //GetMem(DevNames, Size);
    try
      Offset := PChar(PByte(DevNames) + SizeOf(TDevnames));
      with DevNames^ do
      begin
        wDriverOffset := Offset - PChar(DevNames);
        Offset := StrECopy(Offset, Driver) + 1;
        wDeviceOffset := Offset - PChar(DevNames);
        Offset := StrECopy(Offset, Device) + 1;
        wOutputOffset := Offset - PChar(DevNames);;
        StrCopy(Offset, Port);
      end;
    finally
      GlobalUnlock(DeviceNames);
      //FreeMem(DevNames, Size);
    end;
  end;
end;

QRPrnSu.pas修正後儲存,重新編譯/安裝 QR506DesignDXE10.bpl、QR506RunDXE10.bpl