PDA

Ver la Versión Completa : Enviar TXT como etiqueta ZEBRA con Delphi XE...


hgiacobone
15-06-2017, 20:40:25
Hola. Aqui llego con un tema algo raro.
Hemos mudado el codigo del viejo Delphi-7 hacia un Delphi-XE4 y, entre otras, la funcion de impresion sobre impresoras Zebra no ha funcionado nunca más.

Digamos, no produce ninguna salida. Aqui parte del código que es "standard" en varios foros:
function Write_RAW_StringToPrinter(PrinterName:String; comando:String): Boolean;
var
PrinterHandle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
if not WinSpool.OpenPrinter(PChar( PrinterName ), PrinterHandle, nil)
then raise exception.create(PrinterName+#13+'OpenPrinter error ' + IntToStr(GetLastError));

Try
with DocInfo1 do
begin
pDocName := PChar('Keuken Doc');
pOutputFile := nil;
pDataType := 'RAW';
end;
if StartDocPrinter(PrinterHandle, 1, @DocInfo1) <> 0 then
begin
StartPagePrinter(PrinterHandle) ;
////// EN ESTE PUNTO PARECE NO REALIZAR NADA, NI TAMPOCO DA ERROR ///////////
WritePrinter(PrinterHandle, PChar(comando) , Length( PChar(comando) ), N);
end;

Lo mismo en Delphi-7 anda perfecto.
Lo mismo en XE4, compilado en 32 bits o en 64bits no anda...:(
¿Alguna idea o sugerencia con esto?:confused:

_Leo
15-06-2017, 23:05:12
Hola, aunque Delphi no es lo mío, a ver si te funciona así:
function Write_RAW_StringToPrinter(PrinterName:String; comando:AnsiString): Boolean;
var
PrinterHandle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
Result := False;
if not WinApi.WinSpool.OpenPrinter(PChar(PrinterName), PrinterHandle, nil)
then raise exception.create(PrinterName+#13+'OpenPrinter error ' + IntToStr(GetLastError));

with DocInfo1 do
begin
pDocName := PChar('Keuken Doc');
pOutputFile := nil;
pDataType := 'RAW';
end;
if StartDocPrinter(PrinterHandle, 1, @DocInfo1) <> 0 then
begin
StartPagePrinter(PrinterHandle) ;
WritePrinter(PrinterHandle, PAnsiChar(comando), Length(comando), N);
EndPagePrinter(PrinterHandle);
EndDocPrinter(PrinterHandle);
ClosePrinter(PrinterHandle);
Result := True;
end;
end;

hgiacobone
16-06-2017, 21:18:37
Bueno amigos, luego de mucho andar, he aqui la solución.
La instrucción original, debe modificarse de esta forma:

function Write_RAW_StringToPrinter(PrinterName:String; comando:String): Boolean;
var
PrinterHandle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
begin
if not WinSpool.OpenPrinter(PAnsiChar( PrinterName ), PrinterHandle, nil)
then raise exception.create(PrinterName+#13+'OpenPrinter error ' + IntToStr(GetLastError));

Try
with DocInfo1 do
begin
pDocName := PWideChar('Mi nombre es Yako');
pOutputFile := nil;
pDataType := PWideChar('RAW');
end;
if StartDocPrinter(PrinterHandle, 1, @DocInfo1) <> 0 then
begin
StartPagePrinter(PrinterHandle) ;
WritePrinter(PrinterHandle , PAnsiChar( RawByteString(comando) ) , Length(comando) , N);
end;


...y asi recibe la cantidad de Bytes correctos. :cool: