Página 1 de 1

erro win32prn() no pdfcreator

Enviado: 01 Dez 2009 17:10
por lapinhazzz
Boa Noite,

Tenho aquela rotina que postaram aqui no forum que se chama impusb.prg que imprime em win32prn()
Só que a segunda página aparece-me um erro:

ERROR: syntaxerror
OFFENDING COMMAND: --nostringval--
STACK:

A rotina para iniciantes que eu tenho e modificada é esta

Código: Selecionar todos

*--------------------------------------------------------------------------------------
#define FORM_A4 9
#define RGB( nR,nG,nB ) ( nR + ( nG * 256 ) + ( nB * 256 * 256 ) )
#define PS_SOLID 0
#define BLACK RGB( 0x0 ,0x0 ,0x0 )
#define BLUE RGB( 0x0 ,0x0 ,0x85 )
#define GREEN RGB( 0x0 ,0x85,0x0 )
#define CYAN RGB( 0x0 ,0x85,0x85 )
#define RED RGB( 0x85,0x0 ,0x0 )
#define MAGENTA RGB( 0x85,0x0 ,0x85 )
#define BROWN RGB( 0x85,0x85,0x0 )
#define WHITE RGB( 0xC6,0xC6,0xC6 )
*
*--------------------------------------------------------------------------------------
FUNCTION Main()
   LOCAL nPrn:=1
   LOCAL aPrn:= GetPrinters()
   CLS
   sele 3
   use produtos
   skip
   IF EMPTY(aPrn)
      Alert("No printers installed - Cannot continue")
      QUIT
   ENDIF
   DO WHILE !EMPTY(nPrn)
      CLS
      @ 0,0 SAY 'Programa Fotoc¢pias - Escolha uma impressora. ESC' +;
         ' para sair.'
      @ 1,0 TO maxRow(),maxCol()
      nPrn:= ACHOICE(2,1,maxRow()-1,maxCol()-1,aPrn,.T.,,nPrn)
      IF !EMPTY(nPrn)
         PrnTest(aPrn[nPrn])
      ENDIF
   ENDDO
   *
   @ 22,00 say ""
RETURN(NIL)
*
*--------------------------------------------------------------------------------------
STATIC FUNCTION PrnTest(cPrinter)
   LOCAL oPrinter:= WIN32PRN():New(cPrinter), aFonts, x, nColFixed, nColTTF, ;
      nColCharSet, aForms
   oPrinter:Landscape:= .F.
   oPrinter:FormType := FORM_A4
   oPrinter:Copies := 1
   *
   c_string := "Foto-" + LTRIM(STR(YEAR(DATE()))) + "-" + STRZERO(MONTH(DATE()),2) +;
      "-" + LTRIM(STR(DAY(DATE()))) + "=" + TIME()
   *
   IF !oPrinter:Create()
      Alert("Cannot Create Printer")
   ELSE
      IF !oPrinter:startDoc( c_string )
         Alert("StartDoc() failed")
      ELSE
         nFont := 12
         oPrinter:SetFont('Courier New',12,{1,nFont}, 0, .F., .F.)

         FOR N = 1 TO 2
            oPrinter:NewLine()
         NEXT N
         *
         *-----------------------------------------------------------------------------

         *================================== Busca de informa‡äes =====================

         oPrinter:TextOut("Impressora: " + oPrinter:PrinterName + ' ' +;
            'MaxRow() = '+ltrim(STR(oPrinter:MaxRow(),4)) +;
            ' MaxCol() = '+ltrim(STR(oPrinter:MaxCol(),4)) , .t.)

         oPrinter:NewLine()
         oPrinter:SetFont('Courier New',12,{1,nFont}, 0, .F., .F.)

         oPrinter:Textout(STR(oprinter:LineHeight() ) + " -altura da linha",.t.)
         oPrinter:Textout(STR(oprinter:CharWidth() ) + " -largura da coluna",.T.)
         oPrinter:TextOut(STR(oPrinter:Prow() ) + " -N£mero da linha",.T.)
         oPrinter:TextOut(STR(oPrinter:GetCharWidth() ) + " -GetCharWidth",.T.)
         oPrinter:TextOut(STR(oPrinter:GetCharHeight() ) + " -GetCharHeigth",.T.)
         oPrinter:Textout(STR(oprinter:Prow() ) + " -Posi‡Æo atual da " +;
            "linha",.T.)
/*
Onde:
oPrinter:TextOut("Texto a ser impresso",.T.)
1-Texto;
2-Opcional: Avan‡a linha automaticamente (.T.) ou nÆo (.F.),
sendo (.F.) o seu valor Default, quando suprimido.
*/
         *======================= Aqui come‡a a impressÆo da 1¦ p gina ================



         oPrinter:TextAtFont(oPrinter:mm_to_posx(105),oPrinter:mm_to_posy(75), +;
            "Listagem de Fotocopias - Descricao e Precos","Courier New", +;
            16,,700,,.T.,,,,,2)


         oPrinter:NewLine()
         FOR nLinha = 1 TO 29
            oPrinter:SetPrc(oPrinter:Prow()+01, 20 )
            oPrinter:Textout(codigoprod+'   '+prod+'    '+'  '+str(precov)+;
               '  '+copias+'  '+cor,.f.)
            skip
         NEXT nLinha
      endi
   endi
return
Obrigado

lapinhazzz
:{

Re: erro win32prn() no pdfcreator

Enviado: 01 Dez 2009 20:13
por gvc
Esse erro é durante a compilação ou execução?
Vc conseguiu determinar se é em alguma linha do sistema? (runtime error)

Re: erro win32prn() no pdfcreator

Enviado: 02 Dez 2009 19:34
por Hasse
O erro está no final do código. Faltando:
oPrinter:EndDoc()
oPrinter:Destroy()


Depopis de devidamente modificado, testei o código abaixo e está funcionando.

Código: Selecionar todos

*--------------------------------------------------------------------------------------
#define FORM_A4 9
#define RGB( nR,nG,nB ) ( nR + ( nG * 256 ) + ( nB * 256 * 256 ) )
#define PS_SOLID 0
#define BLACK RGB( 0x0 ,0x0 ,0x0 )
#define BLUE RGB( 0x0 ,0x0 ,0x85 )
#define GREEN RGB( 0x0 ,0x85,0x0 )
#define CYAN RGB( 0x0 ,0x85,0x85 )
#define RED RGB( 0x85,0x0 ,0x0 )
#define MAGENTA RGB( 0x85,0x0 ,0x85 )
#define BROWN RGB( 0x85,0x85,0x0 )
#define WHITE RGB( 0xC6,0xC6,0xC6 )
*
*--------------------------------------------------------------------------------------
FUNCTION Main()
   LOCAL nPrn:=1
   LOCAL aPrn:= GetPrinters()
   CLS
   sele 3
   use produtos
   skip
   IF EMPTY(aPrn)
      Alert("No printers installed - Cannot continue")
      QUIT
   ENDIF
   DO WHILE !EMPTY(nPrn)
      CLS
      @ 0,0 SAY 'Programa Fotoc¢pias - Escolha uma impressora. ESC' +;
         ' para sair.'
      @ 1,0 TO maxRow(),maxCol()
      nPrn:= ACHOICE(2,1,maxRow()-1,maxCol()-1,aPrn,.T.,,nPrn)
      IF !EMPTY(nPrn)
         PrnTest(aPrn[nPrn])
      ENDIF
   ENDDO
   *
   @ 22,00 say ""
RETURN(NIL)
*
*--------------------------------------------------------------------------------------
STATIC FUNCTION PrnTest(cPrinter)
   LOCAL oPrinter:= WIN32PRN():New(cPrinter), aFonts, x, nColFixed, nColTTF, nColCharSet, aForms
   oPrinter:Landscape := .F.
   oPrinter:FormType  := FORM_A4
   oPrinter:Copies    := 1
   *
   c_string := "Foto-" + LTRIM(STR(YEAR(DATE()))) + "-" + STRZERO(MONTH(DATE()),2) +;
      "-" + LTRIM(STR(DAY(DATE()))) + "=" + TIME()
   *
   IF !oPrinter:Create()
      Alert("Cannot Create Printer")
   ELSE
      IF !oPrinter:startDoc( c_string )
         Alert("StartDoc() failed")
      ELSE
         nFont := 12
         oPrinter:SetFont('Courier New',12,{1,nFont}, 0, .F., .F.)

         FOR N = 1 TO 2
            oPrinter:NewLine()
         NEXT N
         *
         *-----------------------------------------------------------------------------

         *================================== Busca de informações =====================

         oPrinter:TextOut("Impressora: " + oPrinter:PrinterName + ' ' +;
            'MaxRow() = '+ltrim(STR(oPrinter:MaxRow(),4)) +;
            ' MaxCol() = '+ltrim(STR(oPrinter:MaxCol(),4)) , .t.)

         oPrinter:NewLine()
         oPrinter:SetFont('Courier New',12,{1,nFont}, 0, .F., .F.)

         oPrinter:Textout(STR(oprinter:LineHeight() ) + " -altura da linha",.t.)
         oPrinter:Textout(STR(oprinter:CharWidth() ) + " -largura da coluna",.T.)
         oPrinter:TextOut(STR(oPrinter:Prow() ) + " -N£mero da linha",.T.)
         oPrinter:TextOut(STR(oPrinter:GetCharWidth() ) + " -GetCharWidth",.T.)
         oPrinter:TextOut(STR(oPrinter:GetCharHeight() ) + " -GetCharHeigth",.T.)
         oPrinter:Textout(STR(oprinter:Prow() ) + " -Posi‡Æo atual da " +;
            "linha",.T.)
/*
Onde:
oPrinter:TextOut("Texto a ser impresso",.T.)
1-Texto;
2-Opcional: Avan‡a linha automaticamente (.T.) ou nÆo (.F.),
sendo (.F.) o seu valor Default, quando suprimido.
*/
         *======================= Aqui come‡a a impressÆo da 1¦ p gina ================



         oPrinter:TextAtFont(oPrinter:mm_to_posx(105),oPrinter:mm_to_posy(75), +;
            "Listagem de Fotocopias - Descricao e Precos","Courier New", +;
            16,,700,,.T.,,,,,2)


         oPrinter:NewLine()
         FOR nLinha = 1 TO 29
            oPrinter:SetPrc(oPrinter:Prow()+01, 20 )
            oPrinter:Textout(codigoprod+'   '+prod+'    '+'  '+str(precov)+;
               '  '+copias+'  '+cor,.f.)
            skip
         NEXT nLinha
      endi
   endi

oPrinter:EndDoc()
oPrinter:Destroy()

return
Só depois destas 2 funções é que o documento é impresso ou encaminhado ao PDFCreator (ou outro).