This page contains answers to common questions handled by our support staff, along with some tips and tricks that we have found useful and presented here as questions.
Note: In these answers we will follow a few shorthand conventions for describing user-interface procedures. Key combinations will be presented like this: Ctrl+Alt+Delete, which means that you should press and hold down the Control key, the Alt key, and the Delete key at the same time. Menu selections will be presented like this: File->Open, which means that you should open the File menu, and then make the Open selection.
A General Comment: Some modern printer drivers do not support direct communication through the Windows Print Spooler. eg. UseSpooler := True; Compatibility can be checked by calling the public function AsciiPrinter1.DriverCompatible which returns True/False. Attempting to print a complete memo with UseSpooler true will raise an exception. The solution to this problem is to use a standard windows printer driver for your printer. eg. Generic/Text Only driver. Through using TAsciiprinter you are now controlling the printer. The functionality provided by a more advanced, incompatible driver is not required!
The TAsciiPrinter DCU files for Delphi 4 should be installed into Delphi 4 into a new package.
The following is an example on how to do this.
Select the File->New menu option from the Delphi 4 IDE. Then Click the New Package Icon, then select the OK button.
The Package Editor is now displayed as Package 1. Select the Add Icon to specify what components are contained in your new package. The Add Dialog is displayed. On the Add Unit page, click the browse button to specify and select the directory and file AsciPrnt.DCU. Click <OK> to after selecting the file, then click <OK> to Add the Unit. This should bring you back to the Package Editor. Click on the Compile icon to compile this new package. Acknowledge any warnings by clicking OK to confirm compile package, and click OK to Add VCLDB40. On successful compilation, you are returned to the package editor. You should see the AsciPrnt within the contains section. Select File->Save As menu option from the IDE. Enter a location and name for your new package.
You now have to install your new package by selecting the Component->Install Package menu option from the Delphi IDE. Select the Add button, then select the the name and location of the new package you just created.
TAsciiPrint has two ways of communicating with your printer, either by opening the port and spooling directly to it (thus bypassing the windows print spoolers) or by printing a job through the windows print spooler.
The TAsciiPrinter.UseSpooler property must be true to use the Windows Print Spooler, and is only used when printing complete TMemo's, TDBMemo's and TWPRichText objects, by using the PrintMemo method of TAsciiPrinter. Characters within each memo object are translated on-the-fly and are output as Ascii with embedded printer control codes for attributes, character pitch, and user defined character translation stuff, whilst still using the windows printer BeginDoc, EndPage, and EndDoc methods. This is probably the best, safest and secure way of using TAsciiPrinter.
Please note: Some modern printer drivers do not support direct communication through the Windows Print Spooler. eg. UseSpooler := True; Compatibility can be checked by calling the public function AsciiPrinter1.DriverCompatible which returns True/False. Attempting to print a complete memo with UseSpooler true will raise an exception. The solution to this problem is to use a standard windows printer driver for your printer. eg. Generic/Text Only driver. Through using TAsciiprinter you are now controlling the printer. The functionality provided by a more advanced, incompatible driver is not required!
Printing single lines of Text or Characters is always done by directly opening the port, and streaming Ascii data to it, then closing the port. No form feeds, printer setup, spooling, character translation is performed. Whether the printer prints the line or not depends on the printer and the printers internal buffer. Most DOT matrix printers, will print the line instantly, most page printers (lasers and injet printers), do not automatically print, as they usually wait for a form feed to be sent, or the buffer is full, or some other kind of automatic form feed after xx seconds setting. Dumb printers, which have to use the WPS(Windows Printing System), are relatively unreliable with this method as most of the printer control is with the WPS, however, they tend to have a PCL emulation mode can be used quite satisfactory with printing using the windows printer spooler as above, but not with direct spooling to port.
The way ports are used depend on the print method.
Direct Printing to Port.
Specifying LPT1, LPT2, COM1,2,3,4 or FILE is self explanatory when spooling direct to the port, providing TAsciiPrinter can open the port and find a printer there which is not a WPS printer only.
Specifying poCurrent or DEFAULT as the Demo suggests, uses the port of the current windows printer.
Use Windows Print Spooler.
Specifying LPT1, LPT2, COM1,2,3,4 looks through the current windows printers, and selects the first printer it finds using the required port, then use the windows printer spooler to that printer.
Specifying FILE is self explanatory.
Specifying poCurrent, use the windows print spooler of the current windows printer.
The type of printer you have and the emulation mode it is currently using (PCL, EPSON, etc) must be set for TAsciiPrinter to know the control codes to send to it, when printing a TMemo, to set the various character attributes and character pitch. These standard codes for each printer type available, can be setup by the user using the EditPrinterCodes method.
Unless told otherwise, (by sending a printer command at the beginning of a document), the Ascii text sent to the printer is printed using the current install/default font of the printer. Please refer to your printer command reference for information on changing the default font of the printer, either by control code or by printer hardware setup.
Users printing more than 80 characters per line may find that some text appears to drop off the right hand edge of the page. They should either reduce the pitch of the printer to 12 characters per inch, or send via character translation a command to the printer to change font (refer to printer command language reference manual).
Of course there is nothing stopping the user from ensuring that each line of a memo object does not contain more than 80 characters!
This also depends on the width of the paper, 80 characters is just a guide.