Solved

Printer problem with quick report.

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now