Solved

How to find legal 'PrintPort'

Posted on 1997-04-17
6
172 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
[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
  • 3
  • 3
6 Comments
 

Author Comment

by:yogibear
ID: 1335420
Edited text of question
0
 
LVL 1

Accepted Solution

by:
slp earned 100 total points
ID: 1335421
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
ID: 1335422
Well... OK, This might work out....,
Please send in some details :)

Thanx up to now!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:slp
ID: 1335423
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
ID: 1335424
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
ID: 1335425
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 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