Solved

Printer problem with quick report.

Posted on 2001-08-31
2
246 Views
Last Modified: 2010-04-06
Any one has any idea on how to solve the problem on quick report preview if there is no printer installed in local machine or remote machine.  I face such error that if there is no printer installed in my machine, and when the system comes to " QuickRep1.Preview ", the error appears!

Anyone please help.. I do not really find my answer at qusoft website.
0
Comment
Question by:ivylnm
[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 Comments
 
LVL 10

Accepted Solution

by:
Jacco earned 100 total points
ID: 6447197
Hi yvilnm,

Also when previewing QuickReport uses the printer object to create its preview.

You can check if a default printer is installed and not let your report form start. I extracted and altered some code from the printers unit.

Regards Jacco

uses
  WinSpool, Printers;

type
  TPrinterDevice = class
    Driver, Device, Port: String;
//    constructor Create(ADriver, ADevice, APort: PChar);
//    function IsEqual(ADriver, ADevice, APort: PChar): Boolean;
  end;

function SetToDefaultPrinter: Boolean;
var
  I: Integer;
  ByteCnt, StructCnt: DWORD;
  DefaultPrinter: array[0..79] of Char;
  Cur, Device: PChar;
  PrinterInfo: PPrinterInfo5;

  function FetchStr(var Str: PChar): PChar;
  var
    P: PChar;
  begin
    Result := Str;
    if Str = nil then Exit;
    P := Str;
    while P^ = ' ' do Inc(P);
    Result := P;
    while (P^ <> #0) and (P^ <> ',') do Inc(P);
    if P^ = ',' then
    begin
      P^ := #0;
      Inc(P);
    end;
    Str := P;
  end;

begin
  Result := True;
  ByteCnt := 0;
  StructCnt := 0;
  if not EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, nil, 0, ByteCnt, StructCnt) and (GetLastError <> ERROR_INSUFFICIENT_BUFFER) then
  begin
    // With no printers installed, Win95/98 fails above with "Invalid filename".
    // NT succeeds and returns a StructCnt of zero.
    Result := False;
    Exit;
  end;
  PrinterInfo := AllocMem(ByteCnt);
  try
    EnumPrinters(PRINTER_ENUM_DEFAULT, nil, 5, PrinterInfo, ByteCnt, ByteCnt, StructCnt);
    if StructCnt > 0 then
      Device := PrinterInfo.pPrinterName
    else begin
      GetProfileString('windows', 'device', '', DefaultPrinter, SizeOf(DefaultPrinter) - 1);
      Cur := DefaultPrinter;
      Device := FetchStr(Cur);
    end;
    with Printer.Printers do
      for I := 0 to Count-1 do
      begin
        if TPrinterDevice(Objects[I]).Device = Device then
        begin
          Exit;
        end;
      end;
  finally
    FreeMem(PrinterInfo);
  end;
  Result := False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not SetToDefaultPrinter then
    Memo1.Lines.Add('no default printer found --> no quick report will run');
end;
0
 

Author Comment

by:ivylnm
ID: 6452010
Thanks! It really helps ya!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 106
Delphi and Access based Enumeration 9 89
Delphi, TImage, Png 2 53
idtcpserver and idtcpclient encryption using ssl 17 12
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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