0

I am writing an Delphi 2009 program that sends the escape command to the label printer for printing barcode. Refer to Sending printer specific commands, I can use Windows.Escape() to do the job. But my question is our database stores UTF8 data(for storing different languages), may I ask if Windows.Escape() accepts UTF8 data?

Thanks

*I discovered that Escape accept PAnsiChar... enter image description here

rardark
  • 41
  • 5

1 Answers1

1

When using PASSTHROUGH, as the linked code does, the Escape API accepts raw 8 bit data which is not processed in any way by Escape. The data is passed directly to the device.

You can learn about the Escape function from its documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/dd162701.aspx

If the printer understands UTF-8, then your approach should work. But, if the printer does not understand UTF-8 it will fail. In other words this is not really a question about Escape, but rather a question about your printer. You will need to consult its documentation.

Reading between the lines of your question, it seems that you are letting the encoding used in your database drive your thinking regarding printing. That seems to me to be mistaken. There's no connection between your database and the printer. Whether or not your printer understands UTF-8 is unrelated to your database text encoding. You need to first work out what encoding the printer needs. If it is not the same as used by the database, then you will need to convert. Converting from one encoding to another is usually straightforward.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thanks for you reply! But I discovered that Escape accept PAnsiChar in Delphi 2009 (https://i.stack.imgur.com/6jOwP.jpg). Can it still accept UTF8 data? – rardark Jun 19 '17 at 09:23
  • `PAnsiChar` is a pointer to a null terminated array of 8 bit characters. How they are encoded is a separate issue. Delphi, just like C++ doesn't have separate character types for different 8 bit encodings. ANSI and UTF-8 are held in `char` in C++. Mapped to Delphi, C++ `char` becomes Delphi `AnsiChar`. So yes, you can pass an array of UTF-8 encoded 8 bit `AnsiChar` elements. What happens next is down to the printer. Do you have any evidence that it will understand UTF-8 encoded data? – David Heffernan Jun 19 '17 at 09:26
  • Having mentioned null-terminated character arrays, not that `Escape` accepts an argument specifying the byte length. That is required because the data need not be text. Strictly speaking this function should probably accept a byte array, but is the way it is for historical reasons. – David Heffernan Jun 19 '17 at 09:38
  • The specification of the printer states it supports unicode. I think I should have a test first and I will get back to you soon. Thanks for your detail invaluable explanation and time! – rardark Jun 19 '17 at 10:00
  • I think we are done here. The details of your printer are outside the scope of the question that was asked. – David Heffernan Jun 19 '17 at 10:11
  • Thank you very much. I will post another question if I encounter problems! – rardark Jun 20 '17 at 07:40