Solved

Detecting default printer !

Posted on 1997-05-08
5
263 Views
Last Modified: 2010-04-06
How can I detect if there is a default printer selected ?
I don't need to know if there is a printer installed just if it there is a DEFAULT printer selected.
0
Comment
Question by:sile
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
sperling earned 50 total points
ID: 1336010
This function will return the name of the default printer, or an empty string if there are no default.

uses
  Printers;

function DefaultPrinter : STRING;
begin
  Printer.PrinterIndex := -1;
  if (Printer.PrinterIndex < 0)
  or (Printer.PrinterIndex >= Printer.Printers.Count)
  then Result := ''
  else Result := Printer.Printers[Printer.PrinterIndex];
end;

Regards,

Erik.
0
 

Author Comment

by:sile
ID: 1336011
Now I have tried the code but it doesn't work if there is no printer installed ... In this case my app. terminates and I get an error message saying No default printer currently sellected ?
Can you make it work in this case ?

0
 
LVL 3

Expert Comment

by:sperling
ID: 1336012
Hmmm... Try this one.


function DefaultPrinter : STRING;
begin
  if (Printer=nil) or (Printer.Printers=nil)
  or (Printer.Printers.Count = 0)
  then begin
    Result := ''
  end else begin
    try
      Printer.PrinterIndex := -1;
      Result := Printer.Printers[Printer.PrinterIndex];
    except
      on Exception do Result := '';
    end;
  end;
end;


Regards,

Erik.
0
 

Author Comment

by:sile
ID: 1336013
Ok THANX it works now.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 4231086
Bought this Q...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now