Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>TPassThrough should be declared like this :</p> <pre><code>type TPassThrough = packed record nLen : SmallInt; SData : Array[0..255] of AnsiChar; end; </code></pre> <p>You might be using a modern Delphi (2009 or newer) or forgotten the packed directive.</p> <p>See also this SO question for a <a href="https://stackoverflow.com/a/5937427/576719">correct-way-to-send-commands-directly-to-printer</a>.</p> <p>At <a href="http://www.swissdelphicenter.ch/torry/showcode.php?id=716" rel="nofollow noreferrer">Torry's</a> there is an example snippet (written by Fatih Ölçer): Remark : Modified for use with Unicode Delphi versions as well.</p> <pre><code>{ By using the Windows API Escape() function, your application can pass data directly to the printer. If the printer driver supports the PASSTHROUGH printer escape, you can use the Escape() function and the PASSTHROUGH printer escape to send native printer language codes to the printer driver. If the printer driver does not support the PASSTHROUGH printer escape, you must use the DeviceCapabilities() and ExtDevMode() functions instead. Mit der Windows API Funktion Escape() kann man Daten direkt zum Drucker schicken. Wenn der Drucker Treiber dies nicht unterstützt, müssen die DeviceCapabilities() und ExtDevMode() Funktionen verwendet werden. } // DOS like printing using Passthrough command // you should use "printer.begindoc" and "printer.enddoc" type TPrnBuffRec = packed record bufflength: Word; Buff_1: array[0..255] of AnsiChar; end; function DirectToPrinter(S: AnsiString; NextLine: Boolean): Boolean; var Buff: TPrnBuffRec; TestInt: Integer; begin TestInt := PassThrough; if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) &gt; 0 then begin if NextLine then S := S + #13 + #10; StrPCopy(Buff.Buff_1, S); Buff.bufflength := StrLen(Buff.Buff_1); Escape(Printer.Canvas.Handle, Passthrough, 0, @buff, nil); Result := True; end else Result := False; end; // this code works if the printer supports escape commands // you can get special esc codes from printer's manual // example: printer.BeginDoc; try DirectToPrinter('This text '); finally printer.EndDoc; end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload