#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    12
    Rep Power
    0

    Set Printer for application


    Does anyone know how to write the code to set a particular printer as default, but only for the applications run-time life. i.e your normal default printer will be as usual when you exit the running application.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    1. In the uses section, add Printers to the list. This will enable you to use a globally declared object called Printer.
    2. In your code, add the following:
    Code:
    procedure TForm1.FormCreate(Sender: TObject);
    var
     nInd : integer;
    begin
      nInd := Printer.Printers.IndexOf('HP 500-XL');
      if nInd >= 0 then 
        Printer.PrinterIndex := nInd;
    
      // Now set the PaperSize property to any value (even an invalid one will do!). Without this, you may
      // get access errors when you open the Print dialog box
      // See http://community.borland.com/article/0,1410,15603,00.html for how to do this, if you get access errors.
    Hope this helps
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo

IMN logo majestic logo threadwatch logo seochat tools logo