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
Solved

Printer problem with quick report.

Posted on 2001-08-31
2
243 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
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

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
Magic Software info 18 138
creating threads in delphi 1 132
Delphi Seattle StructureView color 1 14
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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