Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Imprimir en impresoras termicas en delphi 2010

Status
Not open for further replies.

carlosviac

Programmer
Jul 22, 2010
1
MX
Hola,
Estoy haciendo un programa para mandar imprimir una nota de venta en una impresora termica, este programa manda codigos de escape para el corte del papel y apertura de cajon, y en delphi 2007 funciona de maravilla, si este mismo programa lo ejecuto desde delphi 2010, no me imprime de manera correcta incluso los renglones de texto los imprime incompletos.
Para esto estoy utilizando el siguiente codigo de prueba (delphi 2007 OK, delphi 2010 MAL):

Alguna sugerencia del motivo de la falla?

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Printers, Dialogs, StdCtrls;

type
TPrnBuffRec = record
bufflength: Word;
Buff_1: array[0..255] of Char;
end;


TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function DirectToPrinter(S: string): Boolean;
var
Buff: TPrnBuffRec;
TestInt: Integer;
begin
TestInt := PassThrough;
if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) > 0 then
begin
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;

procedure PrintText(s: string);
var
PTBlock: TPassThroughData;
begin
PTBlock.nLen := Length(s);
StrPCopy(@PTBlock.Data, s);
Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil);
end;

procedure PrintOut;
var
i:Integer;
begin
Printer.BeginDoc;

for i := 0 to 2 do
begin
DirectToPrinter('This text');
DirectToPrinter(#10#13);
DirectToPrinter(#27#105); //Corte de papel
end;

Printer.EndDoc;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
PrintOut;
end;

end.
 
Google Translate said:
Hello,
I'm making a program to send print a bill of sale in a thermal printer, the program sends escape codes for cutting paper and opening of drawer, and in Delphi 2007 works great, if I run the same program from delphi 2010 I do not print correctly even the printed lines of text incomplete.
For this I'm using the following test code (OK delphi 2007, delphi 2010 MAL)

Any recommendations of the reason for the failure?

mal = bad.

The language used on this website is English, so excuse any error that is in this translation from Google Translate. There may be issue with this post for this reason. Hopefully someone may be able to shed some light on the given code, but the translation given seems reasonably good, so hopefully it can be of service.

Google Translate said:
El lenguaje utilizado en este sitio web es el Inglés, así que disculpen cualquier error que es en esta traducción de Google Translate. Puede haber problema con este post por esta razón. Esperemos que alguien puede ser capaz de arrojar alguna luz sobre el código asignado, pero la traducción dada parece bastante buena, así que espero que pueda ser de utilidad.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
With some research I've done, it seems one of the major differences of Delphi 2010 from Delphi 2007 is that there is full support for Unicode characters. The others will have to speak to how this will affect the code above, but my guess is that Delphi 2010 is explicitly considering character definitions to be Unicode and your printer does not know how to handle Unicode characters. Constrast this with Delphi 2007 which probably considers all characters to be ANSI by default.

I would first try defining all Char to be "AnsiChar" and all String to "AnsiString" if I were trying to fix this code.

(Again excuse the errors that Google Translate may produce)

Google Translate said:
Con un poco de investigación que he hecho, parece una de las principales diferencias de Delphi 2010, a partir de Delphi 2007 es que hay un apoyo completo para caracteres Unicode. Los demás tendrán que hablar de cómo afectará esto al código anterior, pero mi conjetura es que Delphi 2010 es considerar de forma explícita las definiciones de caracteres Unicode y que la impresora no sabe cómo manejar los caracteres Unicode. Contrastarlo esto con Delphi 2007, que considera probable que todos los caracteres que se ANSI de forma predeterminada.

En primer lugar, se intenta definir todos los Char ser "AnsiChar" y todas las cadenas a "AnsiString" si yo fuera tratando de arreglar el código.

(Una vez más excusa los errores que se pueden producir Google Translate)

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top