I am currently working on sending print codes down to a receipt printer. My issue is chr(integer) is returning extra 0s only when converting values greater than 127.
chr(127) returns: #$7F
chr(128) returns: #$0080
chr(150) returns: #$009F
chr(160) returns: ‘ ‘ (just one space)
I am using the following code, modified a bit for readability. I need to convert a specific set of codes from decimal into hex. Any time there is a decimal value between 128 and 159 that specific set of code fails to execute properly on the printer. I have found that this is due to just that range of characters appending a 00 onto the front of the value.
Is there a way to prevent delphi’s chr function from adding in those extra leading 00s to values?
func Printer.GetPrintCodes(): string;
var
i: integer;
code: integer;
begin
for i := 1 to CodesLimit do
begin
code := GetCode(i);
if code <> 999 then
Result := Result + chr(code);
end;
Result = PAnsiChar(Result)
end;
GetCode returns the integer print code for that slot.
I have found if I just manually add in the hex value, something breaks when returning it as a PAnsiChar and have extra junk at the end.
Travis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1