?
Solved

Detecting default printer !

Posted on 1997-05-08
5
Medium Priority
?
286 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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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