Solved

Printer problem with quick report.

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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