Solved

How to find legal 'PrintPort'

Posted on 1997-04-17
6
165 Views
Last Modified: 2010-04-04
Hello, I want to transfer an already preformatted PRN file (all printcodes are already in the file, so no printchars should be added) to the 'currently chosen printer'. The problem I encounter is that only printers that are connected to a (LPT) port are working fine, because I tried it the 'usual' (?) Turbo pascal way, by assiging the printerport (AssignFile(deviceptr, CharP(PrinterPort))

The problem is that when a Printer is not connected via a LPT Port but directly to a Print Queue, this will not work, because you cannot  'open the queue'.

Is there a better way to redirect the preformatted files to the printdevice?

Thanx in advance!
0
Comment
Question by:yogibear
  • 3
  • 3
6 Comments
 

Author Comment

by:yogibear
Comment Utility
Edited text of question
0
 
LVL 1

Accepted Solution

by:
slp earned 100 total points
Comment Utility
This situation is not going to improve in 32bit Windows environments, because, AFAIK, they won't let you open the port as a file at all.  The only solution that I can think that might work would be to access the printer via the Windows driver and use the Escape() API call with the PASSTHROUGH option, thus sending the contents of the file directly to the printer.  If this sounds like an option, let me know and I can go into more detail.

SLP

0
 

Author Comment

by:yogibear
Comment Utility
Well... OK, This might work out....,
Please send in some details :)

Thanx up to now!
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:slp
Comment Utility
Delphi provides a Printer object that you can access when you include the "Printers" unit in your uses clause.  This object has a canvas, and the handle to that canvas is the printer's DC.  This handle can be used in the Escape() API call.  So something like the following ought to work (note that I'm doing no special error checking):

uses
  Printers ;

var
  PrnFile : file ;
  Buffer : array [0..1023] of byte ;
  RetVal : integer ;
begin
  AssignFile( PrnFile, 'MYFILE.PRN' ) ;
  Reset( PrnFile ) ;
  repeat
    BlockRead( PrnFile, Buffer, SizeOf( Buffer ), RetVal ) ;
    Escape( Printer.Canvas.Handle, PASSTHROUGH,
      SizeOf( Buffer ), @Buffer, nil ) ;
  until RetVal < SizeOf( Buffer ) ;
  Close( PrnFile ) ;
end ;  

Using Delphi File Streams rather than Pascal untyped files would also be an option, or whatever means you're used to for reading binary files.

HTH

slp


0
 

Author Comment

by:yogibear
Comment Utility
Seems AllRight, I'll try this!

BTW, In the comment I read I only valued this question 10 points by mistake. I wanted to value this 100pts? Is there a way to give 'slp' the missing 90 points?
0
 
LVL 1

Expert Comment

by:slp
Comment Utility
Thanks for the offer of the extra points, I'm kind of new here myself, so I don't know who or how to contact someone for "system services" yet, seems like this is mostly automated.

SLP

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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