Change printer settings by code

edited 12:15PM in FastReport 3.0
I want to change printer settings by code.

Actually it is not a problem but it is a problem when I use Fast Report.

With this code I changed the printer tray which the printer must be used:
Procedure SelectPrinterBin( bin: Word);
 var
   Device, Driver, Port: array[0..80] of Char;
   DevMode: THandle;
   pDevmode: PDeviceMode;
 begin
   // Get printer device name etc.
   Printer.GetPrinter(Device, Driver, Port, DevMode);
   // force reload of DEVMODE
   Printer.SetPrinter(Device, Driver, Port, 0);
   // get DEVMODE handle
   Printer.GetPrinter(Device, Driver, Port, DevMode);
   If Devmode <> 0 Then Begin
     // lock it to get pointer to DEVMODE record
     pDevMode := GlobalLock( Devmode );
     If pDevmode <> Nil Then
     try
       With pDevmode^ Do Begin
         // modify paper size
         dmDefaultsource := bin;
         // tell printer driver that dmDefaultsource field contains
         // data it needs to inspect.
         dmFields := dmFields or DM_DEFAULTSOURCE;
       End;
    finally
      // unlock devmode handle.
      GlobalUnlock( Devmode );
    end;
   End; { If }
 end;


But when I have a Report and show a preview and then go to the print button, then I see that printer tray (=bin) is set to the default value and not to the value I set by my code (So Fast Report seems to overrule everytime my settings).

Does somebody know how I can change by code the printer settings and when I do a preview Fast Report gives the printer settings of me?

Comments

  • edited 12:15PM
    Nobody??

     frxReport1.LoadFromFile('c:\fastreport.fr3');
      TfrxReportPage(frxReport1.Pages[0]).Bin := cmbbx_Printer.ItemIndex;
      TfrxReportPage(frxReport1.Pages[0]).BinOtherPages := cmbbx_Printer.ItemIndex;
      Prn.PropertiesDlg;
      frxReport1.ShowReport;
    

    Prn.PropertiesDlg shows the changed tray

    Showreport ==> Print ==> Properties ==> show NOT the changed tray.

    So according to me it seems to be a bug.

    Please help me!
  • mvemve
    edited 12:15PM
    martinst wrote:
    I want to change printer settings by code.

    Actually it is not a problem but it is a problem when I use Fast Report.

    With this code I changed the printer tray which the printer must be used:

    [/code]


    But when I have a Report and show a preview and then go to the print button, then I see that printer tray (=bin) is set to the default value and not to the value I set by my code (So Fast Report seems to overrule everytime my settings).

    Does somebody know how I can change by code the printer settings and when I do a preview Fast Report gives the printer settings of me?
    Hi Martinst!

    Could you already solve this problem?

    I have almost the same one.
    I'd like to print the first 2 copies on paper that come from the first tray and the 3rd copy on paper comes from the 2nd tray.

    But I don't know how to change tray from code.

    Thanks!

  • edited 12:15PM
    Hi,
    I solved this problem like this.
    First put this oncreate of the form.

    cboprinters.Items.Assign(Printer.printers); (cboprinter is a combpbox)

    then Put this code to the OnChange of cbo printers:
    Frxreport1.PrintOptions.Printer :=cboprinters.Text;

    thats alll
  • mvemve
    edited 12:15PM
    Hi,
    I solved this problem like this.
    First put this oncreate of the form.

    cboprinters.Items.Assign(Printer.printers); (cboprinter is a combpbox)

    then Put this code to the OnChange of cbo printers:
    Frxreport1.PrintOptions.Printer :=cboprinters.Text;

    thats alll
    Hi!

    Yes, and this is changing the printer, isn't it? It works for me too, I can change the printer, but i'd like to change the PRINTER'S BIN!

    If i see well, the frxPrinter.Pas' SetPrintParams function is changing the bin, but it isn't works...

    Code: (ABin is the parameter of the procedure)

    ...

    if FBin <> -1 then
    ABin := FBin;
    FMode.dmDefaultSource := ABin;

    ...

    FDC := ResetDC(FDC, FMode^);

    ...

    The win32 developers reference says:
    dmDefaultSource Reserved; must be zero.

    ???

    Thanks for helping!
  • mvemve
    edited 12:15PM
    mve wrote:
    Hi!

    Yes, and this is changing the printer, isn't it? It works for me too, I can change the printer, but i'd like to change the PRINTER'S BIN!

    If i see well, the frxPrinter.Pas' SetPrintParams function is changing the bin, but it isn't works...

    Code: (ABin is the parameter of the procedure)

    ...

      if FBin <> -1 then
        ABin := FBin;
      FMode.dmDefaultSource := ABin;

    ...

      FDC := ResetDC(FDC, FMode^);

    ...

    The win32 developers reference says:
    dmDefaultSource      Reserved; must be zero.

    ???

    Thanks for helping!
    hm. noone? ;)

    Thanks!
  • mvemve
    edited 12:15PM
    hm. noone? ;)

    Thanks!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.