Solved

Printer problem with quick report.

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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