Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your current code is sending data to the printer in the wrong format due to changes between Ansi and Unicode characters. The printer you're using is evidently able to tolerate some amount of error, which is why some of your commands worked, but there's a limit.</p> <p>In your version of Delphi, <code>Char</code> is equivalent to <code>WideChar</code>, so change your <code>Char</code> code to use <code>AnsiChar</code> instead, so you can send one-byte characters, as the printer expects. Your <code>PrintRawData</code> function was fine before. Your change is wrong. The printer does not expect to receive two-byte Unicode characters, but that's what your change amounts to.</p> <p>After restoring the original <code>PrintRawData</code> code, change your <code>SendStr</code> function to this:</p> <pre><code>procedure TMainWindow.SendStr(const Text: string); var data: AnsiString; begin data := Text; if (PrintRawData(printHandle, PAnsiChar(data), Length(data)) &lt; 0) then begin ShowMessage('PrintRawData Failed'); EndRawPrintPage(printHandle); EndRawPrintJob(printHandle); end; end; </code></pre> <p>I made the following changes to the code:</p> <ol> <li>Replace the <code>Char</code> array with an <code>AnsiString</code>.</li> <li>Instead of growing the data array one character at a time with a loop, do the Unicode-to-Ansi conversion with a single assignment statement and let the RTL take care of the conversion.</li> <li>Type-cast the data string to <code>PAnsiChar</code> for passing to <code>PrintRawData</code>.</li> <li>Pass string parameters as const unless you need to modify their contents.</li> <li>No need for an explicit <code>exit</code> statement when the function is already finished.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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