Solved

Detecting default printer !

Posted on 1997-05-08
5
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 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