Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   Enviar TXT como etiqueta ZEBRA con Delphi XE... (https://www.clubdelphi.com/foros/showthread.php?t=91975)

hgiacobone 15-06-2017 20:40:25

Enviar TXT como etiqueta ZEBRA con Delphi XE...
 
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:
Código Delphi [-]
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í:
Código Delphi [-]
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

Tema Solucionado
 
Bueno amigos, luego de mucho andar, he aqui la solución.
La instrucción original, debe modificarse de esta forma:

Código Delphi [-]
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:


La franja horaria es GMT +2. Ahora son las 19:13:47.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi