PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label pascal. Show all posts
Showing posts with label pascal. Show all posts

Friday, September 16, 2022

[FIXED] How to print CODE128 barcode to POS Thermal printer properly using Delphi?

 September 16, 2022     barcode, delphi, epson, pascal, printing     No comments   

Issue

I am trying to print code128 barcode directly to POS printer using this code:

DirectToPrinter(chr(29)+chr(107)+chr(72)+Chr(123)+Chr(65)+'8600123456789', true);

According to the documentation here: https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=128, I have included { (123) and character for code A (65), but I wonder why I am getting only digits printed out but no lines.

Any idea?

By the way, I am using EPSON TM88V POS Thermal Printer.

nction tform1.DirectToPrinter(S: AnsiString; NextLine: Boolean): Boolean;
var
  Buff: TPrnBuffRec;
  TestInt: Integer;
  i: integer;
   Device: PChar;
  Driver: PChar;
  Port: PChar;
begin
  TestInt := PassThrough;
  if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) > 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;


Solution

This issue is solved (kudos to Tom) by adding the number of characters chr(13) and replacing chr(72) to chr(73), like this:

DirectToPrinter( chr(29)+chr(107)+chr(73)+chr(13)+chr(123)+Chr(65)+'8600123456789', true ); 


Answered By - Vladimir
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, August 5, 2022

[FIXED] How to make my FreePascal app exit with a specific code if a certain exception is thrown?

 August 05, 2022     exception, exit-code, freepascal, pascal     No comments   

Issue

My program has an ESyntaxError class that I use like this:

raise ESyntaxError.Create(Message)

And I have that ESyntaxError class just defined like this:

ESyntaxError = class(Exception)

I observe that if that ESyntaxError.Create(Message) code has been called, my program’s exit code gets set to 1. But what I would like to have it set to instead in this case is 65.

I have tried just doing this:

ExitCode := 65;
raise ESyntaxError.Create(Message);

...But with that my app still just exits with 1, not 65—I guess because the built-in Exception class always resets ExitCode to 1? (Don’t know for sure that’s the case and have seen nothing in the Exception docs explicitly stating that, but I infer that from the behavior I’ve observed here).

Or if I want to end up with the program having a non-1/non-0 exit status, should I perhaps be handling this in some other way than basing it on Exception?


Solution

This works: you can wrap main routine in try-except block, then assign ExitCode for specific types of exceptions

program project1;

uses
  SysUtils;

type
  EMy = class(Exception);

procedure run;
begin
  raise EMy.Create('lel');
end;

begin
  try
    run;
  except
    on e: EMy do
    begin
      ExitCode := 65;
    end;
  end;
end.


Answered By - hinst
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing