Jump to content
Fivewin Brasil

Erro irrecuperavel (sistema aborta) no retorno da classe Tprinter


silvanof

Recommended Posts

Prezados, sou novo aqui o fórum e preciso muito da ajudo de vcs.

 

Venho utilizando ha um bom tempo uma  classe para facilitar a confecção de relatórios através da classe nativa Tprinter. Até a versão 8 do Fivewin funcionava normalmente, depois que fiz upgrade para a versão 12 e 13 parou de funcionar. Da erro no retorno Self da classe Tprinter metodo New,(o sistema aborta sem acusar erro de execução),  quando chamada através da minha classe, se uso direto a classe Tprinter o erro não ocorre. Já tentei de tudo e não consigo resolver. As DLLs estão de acordo com a última versão. Segue minha classe pra vcs verem, inclusive ela facilita muito da vida de quem quer fazer relatórios.:

 

#include "FiveWin.ch"
#include "Print.ch"

//----------------------------------------------------------------------------//
// Classe criada para padronizar os relatorio feitos através da classe Print
STATIC lCabWordExcel := .T.
STATIC oDoc
STATIC cArqDoc
STATIC aColunas
STATIC nContador
//STATIC oRelatorio

CLASS TRelatorio
   DATA   oRelatorio
   DATA   oFonte
   DATA   oLogoRel
   DATA   oTexto
   DATA   nLin
   DATA   nCol
   DATA   nLinStep
   DATA   nColStep
   DATA   nPagina
   DATA   nLinTot
   DATA   nNumCol
   DATA   nNumLin
   DATA   nAltura
   DATA   nLargura
   DATA   nFontePadrao
   DATA   lCab
   DATA   lRod
   DATA   lPaisagem
   DATA   cTipo
   DATA   cTitulo
   DATA   cTitulo2
   DATA   cTitulo3
   DATA   cTitulo4
   DATA   cTitulo5
   DATA   cTitulo6
   DATA   cTituloEmp
   DATA   cTituloCNPJ
   DATA   cTituloIE
   DATA   cCabPagina
   DATA   cCabEmissao
   DATA   cCabPeriodo
   DATA   cPagina
   DATA   aTituloCab
   DATA   aTituloCab2
   DATA   aTituloCab3
   DATA   aCabAdicional
   DATA   bCondicao
   DATA   bContador

   METHOD New( cTitulo, lPaisagem, cTipo, lVisualizar, nFonte, lQuieto )  CONSTRUCTOR

   METHOD Cabecalho(nSaltoLinha)

   METHOD Rodape()

   METHOD SaltaLinha(nNumeroDeLinhas)

   METHOD SaltaPagina()

   METHOD IniciaPagina()

   METHOD FinalizaPagina()

   METHOD Escreva( cTexto, nColuna, nLinha, nTamanhoFonte, lBold, nCor )

   METHOD Caixa( nColunas, nColunaInicial, nColInicial, nLinInicial, nColFinal, nLinFinal, nCorDoFundo, nRecuo )

   METHOD Linha( nColunas, nColunaInicial, nColInicial, nLinInicial, nColFinal, nLinFinal )

   METHOD PosicionaLinha( nLinha )

   METHOD Alinhar( nAlinhamento )

   METHOD Fonte( oFonte, nTamanho )

   METHOD Cancelado()

   METHOD Zoom()

   METHOD End()


ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cTitulo, lPaisagem, cTipo, lVisualizar, nFonte, lQuieto ) CLASS TRelatorio
   LOCAL oDlgLogo
   local oX
   DEFAULT cTitulo := "Seu titulo"
   DEFAULT lPaisagem := .f.
   DEFAULT cTipo := "PRINT"
   DEFAULT lVisualizar := .T.
   DEFAULT nFonte := 8
   DEFAULT lQuieto := .F.

   ::cTitulo := cTitulo
   ::nFontePadrao := nFonte
   ::lPaisagem := lPaisagem
   ::cTipo := cTipo
   ::aTituloCab := {}
   ::aTituloCab2 := {}
   ::aTituloCab3 := {}
   ::aCabAdicional := {}
   ::bCondicao := {|| .f. }
   ::cTitulo2 := ''
   ::cTitulo3 := ''
   ::cTitulo4 := ''
   ::cTitulo5 := ''
   ::cTitulo6 := ''
   ::cTituloEmp := ''
   ::cTituloCNPJ := ''
   ::cTituloIE := ''
   ::oRelatorio:=''


   nContador := 0

   ? 'Metodo New - Classe Trelatorio' //,::oRelatorio,::cTitulo

   IF ::cTipo = "PRINT"

      if lVisualizar=nil
         lVisualizar:=.f.
      endif

      try

      // Invoca a classe TPrinter

      IF lVisualizar
         PRINT ::oRelatorio NAME ::cTitulo PREVIEW
      ELSE
         PRINT ::oRelatorio NAME ::cTitulo
      END

         CATCH oErr
            ? 'Erro no Print'
            MsgErro()
      end

      DEFINE FONT ::oFonte   NAME "Arial" SIZE 0, nFonte*-1  OF ::oRelatorio

      DEFINE DIALOG oDlgLogo // janela utilizada somente para evitar erro defcontrol para imprimir varios relatorios simultaneamente

      REDEFINE Image ::oLogoRel FILENAME "logorel.jpg" OF oDlgLogo

      IF ::lPaisagem
         ::nNumLin := 43.04932735
         ::nNumCol := 41.8125
         ::oRelatorio:SetLandscape()
      ELSE
         ::nNumLin := 60
         ::nNumCol := 30
      END
      ::nAltura := ::oRelatorio:nVertRes()
      ::nLargura := ::oRelatorio:nHorzRes()
      ::nLinStep := ::nAltura / ::nNumLin
      ::nColStep := ::nLargura / ::nNumCol
      ::nCol := ::nColStep
      ::nLin := ::nLinStep/2

      /*
      FOR nE:=-20 TO 50
         IF ! Empty(ProcName( nE ) )
            MsgAlert(Str(nE,10,0)+CRLF+ProcName(nE)+CRLF+ProcFile(nE))
         ENDIF
      NEXT
      */
      ::oRelatorio:cFunRel := ProcName(1)

   ELSEIF ::cTipo = "PDF"
      //? 'pdf'
      ::cTitulo := StrTran(::cTitulo,'/','_')
      ::cTitulo := StrTran(::cTitulo,':','_')
      IF lQuieto
         cArqDoc := cPath+'temp\'+::cTitulo+".pdf"
      ELSE
         cArqDoc := cGetFile32( ::cTitulo+".pdf", "Exportar para PDF", , , .t., , )
      END
      IF Empty(cArqDoc)
         RETURN self
      END
      SysRefresh()
      ::oRelatorio := tpdf():new(cArqDoc)
      ::oRelatorio:Pdfsetfont("Arial",,8)
      IF ::lPaisagem
         ::nAltura := 560 //1169
         ::nLargura := 700 //827
         ::nNumLin := 43.04932735
         ::nNumCol := 36 //41.8125
         ::oRelatorio:Pdfpageorient("L")
      ELSE
         ::nAltura := 825//1169
         ::nLargura := 480 //827
         ::nNumLin := 60
         ::nNumCol := 30
         ::oRelatorio:Pdfpageorient("P")
      END
      ::nLinStep := ::nAltura / ::nNumLin //60  // 800    1169
      ::nColStep := ::nLargura / ::nNumCol //30 //480    827
      ::nLin := ::nAltura
      ::nCol := ::nColStep

   ELSEIF ::cTipo = "WORD"

      TRY
         ::oRelatorio := GetActiveObject( "Word.Application" )
      CATCH
         TRY
            ::oRelatorio := CreateObject( "Word.Application" )
         CATCH
            MsgAlert( "Word não disponível. [" + Ole2TxtError()+ "]", 'Word não pode ser aberto!' )
            RETURN self
         END
      END

      ::cTitulo := StrTran(::cTitulo,'/','_')
      ::cTitulo := StrTran(::cTitulo,':','_')
      cArqDoc := cGetFile32( ::cTitulo, "Exportar para Word", , , .t., , )
      IF Empty(cArqDoc)
         ::oRelatorio := Nil
         RETURN self
      END

      ::oRelatorio:Documents:Add()
      oDoc := ::oRelatorio:Documents:Add()
      ::oTexto := ::oRelatorio:Selection()
      ::oTexto:Font:Name := "Arial"
      ::oTexto:Font:Size := 8

      IF ::lPaisagem
         ::nNumLin := 43.04932735
         ::nNumCol := 41.8125
//         ::oRelatorio:SetLandscape()
      ELSE
         ::nNumLin := 60
         ::nNumCol := 30
      END
      ::nAltura := 0
      ::nLargura := 0
      ::nLinStep := 1
      ::nColStep := 1
      ::nCol := 0
      ::nLin := 0
      ::cPagina := ""

   ELSEIF ::cTipo = "EXCEL"

     //MsgAlert('EXCEL')

      TRY
         ::oRelatorio := GetActiveObject( "Excel.Application" )
      CATCH
         TRY
            ::oRelatorio := CreateObject( "Excel.Application" )
         CATCH
            MsgAlert( "Excel não disponível. [" + Ole2TxtError()+ "]", 'Excel não pode ser aberto!' )
            RETURN self
         END
      END

      ::cTitulo := StrTran(::cTitulo,'/','_')
      ::cTitulo := StrTran(::cTitulo,':','_')
     // MsgAlert('abrir arquivo')
      cArqDoc := cGetFile32( ::cTitulo, "Exportar para Excel", , , .t., , )
     // MsgAlert(cArqDoc)
      IF Empty(cArqDoc)
         ::oRelatorio := Nil
         RETURN self
      END

      oDoc := ::oRelatorio:WorkBooks:Add()

      ::oTexto := ::oRelatorio:ActiveSheet()

      ::oTexto:Cells:Font:Name := "Arial"
      ::oTexto:Cells:Font:Size := 8

      IF ::lPaisagem
         ::nNumLin := 43.04932735
         ::nNumCol := 41.8125
//         ::oRelatorio:SetLandscape()
      ELSE
         ::nNumLin := 60
         ::nNumCol := 30
      END
      ::nAltura := 0
      ::nLargura := 0
      ::nLinStep := 1
      ::nColStep := 1
      ::nCol := 0
      ::nLin := 0
      ::cPagina := ""
      aColunas := {}

   END

   ::lCab:=.T.
   ::lRod:=.F.
   ::nPagina := 0
   CursorWait()

RETURN Self

//----------------------------------------------------------------------------//

METHOD End() CLASS TRelatorio

   IF ::nPagina = 0
      MsgAlert('Nenhum dado selecionado!')
      lgImpAnd := .F.
      RETURN nil
   END

   IF ::cTipo = "PRINT"
      IF ::nLin <= (::nNumLin-3) * ::nLinStep
         ::Rodape()
         ::FinalizaPagina()
      END
      ENDPRINT
      //PrintEnd()
      lgImpAnd := .F.

   ELSEIF ::cTipo = "PDF"
      ::nLin := 29
      IF ::nLin < 30
         ::Rodape()
         ::FinalizaPagina()
      END
      ::oRelatorio:pdfclose()
      //WinExec("C:\Arquivos de programas\Adobe\Acrobat 7.0\Reader\AcroRd32.exe c:\temp\Relação de Centro de Custos.pdf")

   ELSEIF ::cTipo = "WORD"

      //::oRelatorio:Visible := .T.
      //::oRelatorio:WindowState := 1  // Maximize

      //::oRelatorio:Save()//As('c:\temp\doc4.doc')
      TRY
         oDoc:SaveAs(cArqDoc)
         oDoc:Close()
      CATCH
         MsgAlert('Documento não pode ser salvo!'+CRLF+cArqDoc)
      END
      //::Relatorio:Quit()

   ELSEIF ::cTipo = "EXCEL"

      ::oTexto:Cells( 1, 1 ):Select()
      TRY
         oDoc:SaveAs(cArqDoc)
         oDoc:Close()
      CATCH
         MsgAlert('Documento não pode ser salvo!'+CRLF+cArqDoc)
      END

   END
   CursorArrow()

RETURN nil

//----------------------------------------------------------------------------//

METHOD Cabecalho(nSaltoLinha) CLASS TRelatorio
   LOCAL nE
   LOCAL nN
   LOCAL aE
   LOCAL oFont8,oFont8n,oFont9n,oFont10,oFont12n,oFontCab,oFontCabCo,oFont9
   LOCAL oJanela
   LOCAL oVisao

   ? 'Trelatorio - Cabecalho'

   IF ::lCab
      ::IniciaPagina()
      ::nPagina++

      IF ::cTipo = "PRINT"

         ::nLin := ::nLinStep/2

         DEFINE FONT oFont8   NAME "Arial" SIZE 0, -8   OF ::oRelatorio
         DEFINE FONT oFont8n  NAME "Arial" SIZE 0, -8   OF ::oRelatorio BOLD
         DEFINE FONT oFont9   NAME "Arial" SIZE 0, -9   OF ::oRelatorio
         DEFINE FONT oFont9n  NAME "Arial" SIZE 0, -9   OF ::oRelatorio BOLD
         DEFINE FONT oFont10  NAME "Arial" SIZE 0, -10  OF ::oRelatorio
         DEFINE FONT oFont12n NAME "Arial" SIZE 0, -12  OF ::oRelatorio BOLD

         DEFINE FONT oFontCab NAME "Arial" SIZE 0, ::nFontePadrao*-1 OF ::oRelatorio BOLD

         // Logo tipo
         ::oRelatorio:SayImage( ::nLin,::nCol,::oLogoRel, 2.5*(::oRelatorio:nLogPixely()/2.54), 1.7*(::oRelatorio:nLogPixelx()/2.54) )

         IF Empty(::cTituloEmp)
            ::oRelatorio:Say( ::nLin,::nCol*5,"EMPRESA:",oFont8n)
            ::oRelatorio:Say( ::nLin,::nCol*7.5,cgEmpresa,oFont9n)
         ELSE
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTituloEmp,oFont9n))/2, ::cTituloEmp, oFont9n)
         END
         IF ::cCabPagina = Nil
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,"PÃGINA:",oFont8n)
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*6,LTrim(Str(::nPagina,5,0)),oFont10)
         ELSE
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,::cCabPagina,oFont8n)
         END
         ::nLin += (::nLinStep/4)*3
         IF Empty(::cTituloCNPJ)
            ::oRelatorio:Say( ::nLin,::nCol*5,"CNPJ:",oFont8n)
            ::oRelatorio:Say( ::nLin,::nCol*7.5,Transform(cgCNPJ,'@R 99.999.999/9999-99'),oFont9)
         ELSE
//            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTituloCNPJ,oFont9n))/2, ::cTituloCNPJ, oFont9n)
            ::oRelatorio:Say( ::nLin,::nCol*5, ::cTituloCNPJ, oFont8n)
         END
         IF ::cCabEmissao = NIL
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,"EMISSÃO:",oFont8n)
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*5.5,DToC(Date())+" - "+Left(Time(),5),oFont9)
         ELSE
            ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,::cCabEmissao,oFont8n)
         END
         ::nLin += (::nLinStep/4)*3
         IF Empty(::cTituloIE)
            IF !Empty(cgIE)
               ::oRelatorio:Say( ::nLin,::nCol*5,"INSCRIÇÃO:",oFont8n)
               ::oRelatorio:Say( ::nLin,::nCol*7.5,cgIE,oFont9)
            END
         ELSE
//            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTituloIE,oFont9n))/2, ::cTituloIE, oFont9n)
            ::oRelatorio:Say( ::nLin,::nCOL*5, ::cTituloIE, oFont8n)
         END
    //    IF ::cCabPeriodo = NIL
    //        ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,"Período:",oFont8n)
    //        ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*6,MesExtenso(Month(Date()))+"/"+Str(Year(Date()),4,0),oFont10)
    //     ELSE
    //        ::oRelatorio:Say( ::nLin,::nLargura-::nColStep*8,::cCabPeriodo,oFont8n)
    //     END
         ::nLin += (::nLinStep/4)*3
         ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo,oFont12n))/2, ::cTitulo, oFont12n)
         ::nLin += ::nLinStep+::nLinStep/2
         IF !Empty(::cTitulo2)
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo2,oFont12n))/2, ::cTitulo2, oFont12n)
            ::nLin += ::nLinStep+::nLinStep/2
         END
         IF !Empty(::cTitulo3)
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo3,oFont12n))/2, ::cTitulo3, oFont12n)
            ::nLin += ::nLinStep+::nLinStep/2
         END
         IF !Empty(::cTitulo4)
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo4,oFont12n))/2, ::cTitulo4, oFont12n)
            ::nLin += ::nLinStep+::nLinStep/2
         END
         IF !Empty(::cTitulo5)
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo5,oFont12n))/2, ::cTitulo5, oFont12n)
            ::nLin += ::nLinStep+::nLinStep/2
         END
         IF !Empty(::cTitulo6)
            ::oRelatorio:Say( ::nLin,(::nLargura- ::oRelatorio:GetTextWidth(::cTitulo6,oFont12n))/2, ::cTitulo6, oFont12n)
            ::nLin += ::nLinStep+::nLinStep/2
         END

         // Cabecalho adicional
         IF Len(::aCabAdicional)>0
            FOR nE:=1 TO Len(::aCabAdicional)
               aE := ::aCabAdicional[nE]
               FOR nN:=1 TO Len(aE)
                  ::oRelatorio:Say( ::nLin,IIf(aE[nN][2]<50,::nColStep*aE[nN][2],aE[nN][2]),aE[nN][1], oFont8)
               NEXT
               ::nLin += ::nLinStep
            NEXT
         END

         ::oRelatorio:Line( ::nLin,::nCol,::nLin,::nLargura-::nColStep)
         ::nLin += ::nLinStep

//------- Cabecalho das COLUNAS, tem que seguir o tamanho das colunas p/não ficar esquisito

         // Cabecalho 1
         IF Len(::aTituloCab)>0
            FOR nE:=1 TO Len(::aTituloCab)
               IF Len(::aTituloCab[nE]) = 3
                  ::oRelatorio:nPad := ::aTituloCab[nE][3]
               END
               ::oRelatorio:Say( ::nLin,IIf(::aTituloCab[nE][2]<50,::nColStep*::aTituloCab[nE][2],::aTituloCab[nE][2]),::aTituloCab[nE][1], oFontCab)
               ::oRelatorio:nPad := 0
            NEXT
            ::nLin += ::nLinStep
            IF Len(::aTituloCab2)>0
               // Cabecalho 2
               FOR nE:=1 TO Len(::aTituloCab2)
                  IF Len(::aTituloCab2[nE]) = 3
                     ::oRelatorio:nPad := ::aTituloCab2[nE][3]
                  END
                  ::oRelatorio:Say( ::nLin,IIf(::aTituloCab2[nE][2]<50,::nColStep*::aTituloCab2[nE][2],::aTituloCab2[nE][2]),::aTituloCab2[nE][1], oFontCab)
                  ::oRelatorio:nPad := 0
               NEXT
               ::nLin += ::nLinStep
               // Cabecalho 3
               IF Len(::aTituloCab3)>0
                  FOR nE:=1 TO Len(::aTituloCab3)
                     IF Len(::aTituloCab3[nE]) = 3
                        ::oRelatorio:nPad := ::aTituloCab3[nE][3]
                     END
                     ::oRelatorio:Say( ::nLin,,::aTituloCab3[nE][1], oFontCab)
                     ::oRelatorio:nPad := 0
                  NEXT
                  ::nLin += ::nLinStep
               END
            END
         END

//         nSaltoLinha

      ELSEIF ::cTipo = "PDF"
                                                    // 470  150
         IF File("logorel.jpg")
            ::oRelatorio:PdfImage( "logorel.jpg", ::nAltura*2-40, ::nCol*2, 94, 45,,.5,.5 )
         END
         IF Empty(::cTituloEmp)
            ::oRelatorio:Pdfsetfont("ARIAL",1,8)
            ::oRelatorio:PdfAtSay( "EMPRESA:", ::nLin, ::nCol*5, .t. )
            ::oRelatorio:Pdfsetfont("ARIAL",,10)
            ::oRelatorio:PdfAtSay( cgEmpresa,::nLin,::nCol*8,.t.)
         ELSE
            ::oRelatorio:Pdfsetfont("ARIAL",1,8)
            ::oRelatorio:PdfAtSay( ::cTituloEmp,::nLin,::nCol*12, .t.)
         END
         IF ::cCabPagina = NIL
            ::oRelatorio:Pdfsetfont("ARIAL",1,8)
            ::oRelatorio:PdfAtSay( "PÃGINA.:",::nLin,::nLargura-::nColStep*4,.t.)
            ::oRelatorio:Pdfsetfont("ARIAL",,10)
            ::oRelatorio:PdfAtSay( LTrim(Str(::nPagina,5,0)),::nLin,::nLargura-::nColStep,.t.)
         ELSE
            ::oRelatorio:Pdfsetfont("ARIAL",,8)
            ::oRelatorio:PdfAtSay( ::cCabPagina,::nLin,::nLargura-::nColStep*4,.t.)
         END
         ::oRelatorio:Pdfsetfont("ARIAL",1,8)
         ::nLin -= (::nLinStep/4)*3
         IF Empty(::cTituloCNPJ)
            ::oRelatorio:PdfAtSay( "CNPJ",::nLin,::nCol*5,.t.)
            ::oRelatorio:Pdfsetfont("ARIAL",,10)
            ::oRelatorio:PdfAtSay( Transform(cgCNPJ,'@R 99.999.999/9999-99'),::nLin,::nCol*8,.t.)
         ELSE
            ::oRelatorio:PdfAtSay( ::cTituloCNPJ,::nLin,::nCol*5, .t.)
         END
         IF ::cCabEmissao = NIL
            ::oRelatorio:Pdfsetfont("ARIAL",1,8)
            ::oRelatorio:PdfAtSay( "EMISSÃO:",::nLin,::nLargura-::nColStep*4,.t.)
            ::oRelatorio:Pdfsetfont("ARIAL",,10)
            ::oRelatorio:PdfAtSay( DToC(Date())+" - "+Left(Time(),5),::nLin,::nLargura-::nColStep,.t.)
         ELSE
            ::oRelatorio:Pdfsetfont("ARIAL",,8)
            ::oRelatorio:PdfAtSay( ::cCabEmissao,::nLin,::nLargura-::nColStep*4,.t.)
         END
         ::oRelatorio:Pdfsetfont("ARIAL",1,8)
         ::nLin -= (::nLinStep/4)*3
         IF Empty(::cTituloIE)
            IF !Empty(cgIE)
               ::oRelatorio:PdfAtSay( "INSCRIÇÃO:",::nLin,::nCol*5,.t.)
               ::oRelatorio:Pdfsetfont("ARIAL",,10)
               ::oRelatorio:PdfAtSay( cgIE,::nLin,::nCol*8,.t.)
            END
         ELSE
            ::oRelatorio:PdfAtSay( ::cTituloIE,::nLin,::nCol*5, .t.)
         END
     //    IF ::cCabPeriodo = NIL
      //      ::oRelatorio:Pdfsetfont("ARIAL",1,8)
       //     ::oRelatorio:PdfAtSay( "Período:",::nLin,::nLargura-::nColStep*4,.t.)
       //     ::oRelatorio:Pdfsetfont("ARIAL",,10)
       //     ::oRelatorio:PdfAtSay( MesExtenso(Month(Date()))+"/"+Str(Year(Date()),4,0),::nLin,::nLargura-::nColStep,.t.)
        // ELSE
        //    ::oRelatorio:Pdfsetfont("ARIAL",,8)
        //    ::oRelatorio:PdfAtSay( ::cCabPeriodo,::nLin,::nLargura-::nColStep*4,.t.)
       //  END
         ::oRelatorio:Pdfsetfont("ARIAL",1,8)
         ::nLin -= (::nLinStep/3)*3
         ::oRelatorio:Pdfsetfont("ARIAL",1,12)
         ::oRelatorio:PdfAtSay( ::cTitulo,::nLin,::nCol*12, .t.)
         ::nLin -= ::nLinStep
         IF !Empty(::cTitulo2)
            ::oRelatorio:PdfAtSay( ::cTitulo2,::nLin,::nCol*12, .t.)
            ::nLin -= ::nLinStep
         END
         IF !Empty(::cTitulo3)
            ::oRelatorio:PdfAtSay( ::cTitulo3,::nLin,::nCol*12, .t.)
            ::nLin -= ::nLinStep
         END
         IF !Empty(::cTitulo4)
            ::oRelatorio:PdfAtSay( ::cTitulo4,::nLin,::nCol*12, .t.)
            ::nLin -= ::nLinStep
         END
         IF !Empty(::cTitulo5)
            ::oRelatorio:PdfAtSay( ::cTitulo5,::nLin,::nCol*12, .t.)
            ::nLin -= ::nLinStep
         END
         IF !Empty(::cTitulo6)
            ::oRelatorio:PdfAtSay( ::cTitulo6,::nLin,::nCol*12, .t.)
            ::nLin -= ::nLinStep
         END
         //::oRelatorio:PdfAtSay( ::cTitulo,::nLin,(::nLargura - ::oRelatorio:Pdf_Str_Width( ::cTitulo, Len(::cTitulo), "ARIAL", 12 ))/2, .t.)
         ::oRelatorio:Pdfsetfont("ARIAL",,8)
         //::nLin -= ::nLinStep+::nLinStep/2
         //::oRelatorio:PdfLineTo( ::nLin,::nCol*5)

         // Cabecalho adicional
         IF Len(::aCabAdicional)>0
            FOR nE:=1 TO Len(::aCabAdicional)
               aE := ::aCabAdicional[nE]
               FOR nN:=1 TO Len(aE)
                  ::oRelatorio:PdfAtSay( aE[nN][1],::nLin,IIf(aE[nN][2]<50,::nColStep*aE[nN][2],aE[nN][2]), .t.)
               NEXT
               ::nLin -= ::nLinStep
            NEXT
         END

         //------- Cabecalho das COLUNAS, tem que seguir o tamanho das colunas p/não ficar esquisito
              // Cabecalho 1
         IF Len(::aTituloCab)>0
            FOR nE:=1 TO Len(::aTituloCab)
              ::oRelatorio:Pdfsetfont("ARIAL",1,::nFontePadrao) // ALTERADO EM JUL/2012
               ::oRelatorio:PdfAtSay( ::aTituloCab[nE][1],::nLin,IIf(::aTituloCab[nE][2]<50,::nColStep*::aTituloCab[nE][2],::aTituloCab[nE][2]), .t.)
            NEXT
            ::nLin -= ::nLinStep
         END
         IF Len(::aTituloCab2)>0
            FOR nE:=1 TO Len(::aTituloCab2)
               ::oRelatorio:Pdfsetfont("ARIAL",1,::nFontePadrao)
               ::oRelatorio:PdfAtSay( ::aTituloCab2[nE][1],::nLin,IIf(::aTituloCab2[nE][2]<50,::nColStep*::aTituloCab2[nE][2],::aTituloCab2[nE][2]), .t.)
            NEXT
            ::nLin -= ::nLinStep
         END
         IF Len(::aTituloCab3)>0
            FOR nE:=1 TO Len(::aTituloCab3)
               ::oRelatorio:Pdfsetfont("ARIAL",1,::nFontePadrao)
               ::oRelatorio:PdfAtSay( ::aTituloCab3[nE][1],::nLin,IIf(::aTituloCab3[nE][2]<50,::nColStep*::aTituloCab3[nE][2],::aTituloCab3[nE][2]), .t.)
            NEXT
            ::nLin -= ::nLinStep
         END
         //------------------------------------------------------------------------------------------
      ELSEIF ::cTipo = "WORD"

         IF lCabWordExcel

            //------------------------------------------------------------------------------
            // Cabecalho
            oJanela := ::oRelatorio:Get( "ActiveWindow" )
            oVisao  := oJanela:Get( "View" )
            oVisao:Set( "SeekView", 9 )
            ::oTexto:Font:Name := "Arial"
            ::oTexto:Font:Size := 10
            IF Empty(::cTituloEmp)
               ::oTexto:Text := "EMPRESA: "
               ::oTexto:Text += cgEmpresa+Chr(9)+Chr(9)
            ELSE
               ::oTexto:Text := ::cTituloEmp
            END
            IF ::cCabPagina = NIL
               ::oTexto:Text += "PÃGINA.: "+CRLF // falta pagina
               //::oTexto:Text += "Página: "+Chr(19)+' PAGE '+Chr(20)+'1'+Chr(21)+' '+CRLF // falta pagina
            ELSE
               ::oTexto:Text += ::cCabPagina+CRLF // falta pagina
            END
            IF Empty(::cTituloCNPJ)
               ::oTexto:Text += "CNPJ: "
               ::oTexto:Text += Transform(cgCNPJ,'@R 99.999.999/9999-99')+Chr(9)+Chr(9)
            ELSE
               ::oTexto:Text := ::cTituloCNPJ
            END
            IF ::cCabEmissao = NIL
               ::oTexto:Text += "EMISSÃO: "+DToC(Date())+" - "+Left(Time(),5)+CRLF
            ELSE
               ::oTexto:Text += ::cCabEmissao+CRLF
            END
            IF Empty(::cTituloIE)
               IF !Empty(cgIE)
                  ::oTexto:Text += "INSCRIÇÃO: "
                  ::oTexto:Text += cgIE+Chr(9)+Chr(9)
               END
            ELSE
               ::oTexto:Text := ::cTituloIE
            END
            IF ::cCabPeriodo = NIL
               ::oTexto:Text += "PERÃODO: "+MesExtenso(Month(Date()))+"/"+Str(Year(Date()),4,0)+CRLF
            ELSE
               ::oTexto:Text += ::cCabPeriodo+CRLF
            END
            ::oTexto:Text += Chr(9)+::cTitulo+CRLF
            IF !Empty(::cTitulo2)
               ::oTexto:Text += Chr(9)+::cTitulo2+CRLF
            END
            IF !Empty(::cTitulo3)
               ::oTexto:Text += Chr(9)+::cTitulo3+CRLF
            END
            IF !Empty(::cTitulo4)
               ::oTexto:Text += Chr(9)+::cTitulo4+CRLF
            END
            IF !Empty(::cTitulo5)
               ::oTexto:Text += Chr(9)+::cTitulo5+CRLF
            END
            IF !Empty(::cTitulo6)
               ::oTexto:Text += Chr(9)+::cTitulo6+CRLF
            END
            ::oTexto:Text += CRLF
            FOR nE:=1 TO Len(::aTituloCab)
               ::oTexto:Text += ::aTituloCab[nE][1]+"  "
            NEXT
            ::oTexto:Text += CRLF

            //------------------------------------------------------------------------------
            // Rodape
            oVisao:Set( "SeekView", 10 )
            ::oTexto:Font:Name := "Arial"
            ::oTexto:Font:Size := 8
            ::oTexto:Text := "AWS ("+cgVersao+") USUÃRIO: "+cgUsuario + CRLF

            //------------------------------------------------------------------------------
            // Corpo do relatorio
            oVisao:Set( "SeekView", 0 )

            lCabWordExcel := .F.

         END

      ELSEIF ::cTipo = "EXCEL"

         IF lCabWordExcel
            //------------------------------------------------------------------------------
            // Cabecalho
            FOR nE:=1 TO Len(::aTituloCab)
               ::oTexto:Cells(1,nE):Value := ::aTituloCab[nE][1]
               ::oTexto:Columns( nE ):AutoFit()
            NEXT
            lCabWordExcel := .F.

         END

      END

      ::lCab:=.F.
      ::lRod := .T.
   END

RETURN SELF

//----------------------------------------------------------------------------//

METHOD Rodape() CLASS TRelatorio

   IF ::lRod
      IF ::cTipo = "PRINT"
         ::nLin := ::nLinStep/2
         ::oRelatorio:Say( ::nLinStep*(::nNumLin-1)+::nLinStep/3,::nLargura-::nColStep*9,"AWS ("+cgVersao+") usuário: "+cgUsuario, ::oFonte)

      ELSEIF ::cTipo = "PDF"
         ::nLin := ::nAltura
         ::oRelatorio:PdfAtSay( "AWS ("+cgVersao+") usuário: "+cgUsuario, 5, ::nCol*20, .t. )

      ELSEIF ::cTipo = "WORD"
         // o rodape do word é construido junto com o cabecalho

      ELSEIF ::cTipo = "EXCEL"
         // o rodape no excel não é impresso

      END

      ::lRod := .F.
   END

RETURN Self


//----------------------------------------------------------------------------//

METHOD SaltaLinha(nNumeroDeLinhas) CLASS TRelatorio
   LOCAL nE
   LOCAL cMasc
   DEFAULT nNumeroDeLinhas := 1

   IF ::cTipo = "PRINT"
      ::nLin += ::nLinStep*nNumeroDeLinhas
      IF ::nLin > (::nNumLin-3) * ::nLinStep .or. Eval(::bCondicao)
         ::Rodape()
         ::FinalizaPagina()
         ::lCab:=.T.
         ::Cabecalho()
      ENDIF

   ELSEIF ::cTipo = "PDF"
      ::nLin -= ::nLinStep*nNumeroDeLinhas
      IF ::nLin < 30  .or. Eval(::bCondicao)
         ::Rodape()
         ::FinalizaPagina()
         ::lCab:=.T.
         ::Cabecalho()
      ENDIF

   ELSEIF ::cTipo = "WORD"
      ::nLin += ::nLinStep*nNumeroDeLinhas
      ::cPagina += CRLF
      IF ::nLin > ::nNumLin-3 .or. Eval(::bCondicao)
         ::Rodape()
         ::FinalizaPagina()
         ::lCab:=.T.
         ::nLin := 0
         ::Cabecalho()
      END

   ELSEIF ::cTipo = "EXCEL"
      ::nLin += ::nLinStep*nNumeroDeLinhas
      FOR nE:=1 TO Len(aColunas)
         IF ValType(aColunas[nE])='N'
            cMasc:='@E 999999999999999'
            IF aColunas[nE]-Int(aColunas[nE])>0
               cMasc:='@E 999999999999999.999999'
            END
            ::oTexto:Cells( ::nLin+1, nE ):Value := Transform(aColunas[nE],cMasc)
         ELSE
            ::oTexto:Cells( ::nLin+1, nE ):Value := aColunas[nE]
         END
         ::oTexto:Columns( nE ):AutoFit()
      NEXT
      aColunas := {}

      //IF ::nLin > ::nNumLin-3 .or. Eval(::bCondicao)
      //   ::Rodape()
      //   ::FinalizaPagina()
      //   ::lCab:=.T.
      //   ::Cabecalho()
      //END

   END

   IF ::bContador = Nil
      oWnd:oMsgBar:SetMsg(Str(++nContador,10,0))
   ELSE
      oWnd:oMsgBar:SetMsg(Eval(::bContador))
   END
   SysRefresh()

RETURN nil

//------------------------------------------------------------------------------

METHOD SaltaPagina() CLASS TRelatorio

   IF ::cTipo = "PRINT"
      ::Rodape()
      ::FinalizaPagina()
      ::lCab:=.T.
      ::Cabecalho()

   ELSEIF ::cTipo = "PDF"
      ::Rodape()
      ::FinalizaPagina()
      ::lCab:=.T.
      ::Cabecalho()

   ELSEIF ::cTipo = "WORD"
      ::Rodape()
      ::FinalizaPagina()
      ::lCab:=.T.
      ::nLin := 0
      ::Cabecalho()

   ELSEIF ::cTipo = "EXCEL"

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD PosicionaLinha( nLinha ) CLASS TRelatorio

   IF ::cTipo = "PRINT"
      ::nLin := ::nLinStep*nLinha

   ELSEIF ::cTipo = "PDF"
      ::nLin := ::nAltura - ::nLinStep*nLinha

   ELSEIF ::cTipo = "WORD"
      ::nLin := ::nLinStep*nLinha

   ELSEIF ::cTipo = "EXCEL"

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD IniciaPagina() CLASS TRelatorio

   ? 'IniciaPagina()'

   IF ::cTipo = "PRINT"
      PAGE

   ELSEIF ::cTipo = "PDF"
      ::oRelatorio:PdfNewPage("A4")

   ELSEIF ::cTipo = "WORD"

   ELSEIF ::cTipo = "EXCEL"

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD FinalizaPagina() CLASS TRelatorio

   IF ::cTipo = "PRINT"
      ENDPAGE
   ELSEIF ::cTipo = "PDF"
      ::oRelatorio:PdfClosePage()

   ELSEIF ::cTipo = "WORD"
      ::oTexto:Text := ::oTexto:Text + ::cPagina
      ::cPagina := ""
      ::oTexto:EndKey()
      ::oTexto:InsertBreak()

   ELSEIF ::cTipo = "EXCEL"

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD Escreva( cTexto, nColuna, nLinha, nTamanhoFonte, lBold, nCor ) CLASS TRelatorio
   LOCAL oFonte
   DEFAULT cTexto := "",;
           nColuna := 1,;
           nLinha := ::nLin,;
           nTamanhoFonte := ::nFontePadrao,;
           lBold := .F.,;
           nCor := CLR_BLACK
   //? ctexto,lbold


   IF ::cTipo = "PRINT"
      IF nTamanhoFonte = nil
         oFonte := ::oFonte
      ELSE
         IF lBold
            DEFINE FONT oFonte  NAME "Arial" SIZE 0, nTamanhoFonte*(-1) OF ::oRelatorio BOLD
         ELSE
            DEFINE FONT oFonte  NAME "Arial" SIZE 0, nTamanhoFonte*(-1) OF ::oRelatorio
         END
      END

      ::oRelatorio:Say( nLinha, ::nCol*nColuna, cTexto, oFonte, , nCor )

   ELSEIF ::cTipo = "PDF"
      IF lBold
         ::oRelatorio:Pdfsetfont("TIMES",1,nTamanhoFonte-1)  // DIMINUI 1 NO TAMANHO DA FONTE P/TIRAR DIFERENCA DE ESPAÇAMENTO P/RELATORIO P/IMPRESSORA - JUL/2012
      ELSE
         ::oRelatorio:Pdfsetfont("TIMES",,nTamanhoFonte-1)   // DIMINUI 1 NO TAMANHO DA FONTE P/TIRAR DIFERENCA DE ESPAÇAMENTO P/RELATORIO P/IMPRESSORA - JUL/2012
      ENDIF

      ::oRelatorio:PdfAtSay( cTexto, nLinha, ::nCol*nColuna, .F. )
     // ::oRelatorio:Pdfsetfont("ARIAL",,8)

   ELSEIF ::cTipo = "WORD"
      ::cPagina := ::cPagina + " " + cTexto

   ELSEIF ::cTipo = "EXCEL"
      AAdd( aColunas, cTexto )

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD Caixa( nColunas, nColInicial, nLinInicial, nColFinal, nLinFinal, nCorDoFundo, nRecuo ) CLASS TRelatorio

   LOCAL oPen1
   LOCAL nI
   LOCAL nColF
   LOCAL nColI

   DEFAULT nColunas := 0,;
           nColInicial := 0,;
           nLinInicial := ::nLin,;
           nColFinal := ::nCol+::nColStep,;
           nLinFinal := ::nLin+::nLinStep,;
           nRecuo := 0

   IF ::cTipo = "PRINT"

      IF nColunas = 0
         nColInicial := ::nCol
         ::oRelatorio:Box( nLinInicial-nRecuo, nColInicial-nRecuo, nLinFinal-nRecuo, nColFinal-nRecuo )
         nColI := nColInicial-nRecuo
         nColF := nColFinal-nRecuo
      ELSE
         ::oRelatorio:Box( nLinInicial-nRecuo, ::nCol+::nColStep*nColInicial-nRecuo, nLinFinal-nRecuo, ::nCol+::nColStep*(nColunas+nColInicial)-nRecuo )
         nColI := ::nCol+::nColStep*nColInicial-nRecuo
         nColF := ::nCol+::nColStep*(nColunas+nColInicial)-nRecuo
      END

      IF nCorDoFundo != Nil
         DEFINE PEN oPen1 COLOR nCorDoFundo OF ::oRelatorio
         FOR nI := 6 to nLinFinal-nLinInicial-1
            ::oRelatorio:Line( nLinInicial+nI-nRecuo, nColI+5, nLinInicial+nI-nRecuo, nColF-2, oPen1 )
         NEXT
      END

   END

RETURN nil

//----------------------------------------------------------------------------//

METHOD Linha( nColunas, nColInicial, nLinInicial, nColFinal, nLinFinal ) CLASS TRelatorio

   DEFAULT nColunas := 0,;
           nColInicial := 0,;
           nLinInicial := ::nLin,;
           nColFinal := ::nCol+::nColStep,;
           nLinFinal := ::nLin

   IF ::cTipo = "PRINT"

      IF nColunas = 0
         nColInicial := ::nCol
         ::oRelatorio:Line( nLinInicial, nColInicial, nLinFinal, nColFinal )
      ELSE
         ::oRelatorio:Line( nLinInicial, ::nCol+::nColStep*nColInicial, nLinFinal, ::nCol+::nColStep*(nColunas+nColInicial) )
      END

   END

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Fonte( oFonte, nTamanho ) CLASS TRelatorio
   LOCAL oNovaFonte
   IF ::cTipo = "PRINT"
      IF oFonte!=NIL
         ::oFonte := oFonte
      END
      IF nTamanho !=NIL
         DEFINE FONT oNovaFonte NAME ::oFonte:cFaceName SIZE 0, nTamanho*-1  OF ::oRelatorio
         ::oFonte := oNovaFonte
      END
   END

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Alinhar( nAlinhamento ) CLASS TRelatorio
   // 0 = Esquerda
   // 1 = Direita
   // 2 = Centro

   IF ::cTipo = "PRINT"
      ::oRelatorio:nPad := nAlinhamento
   END

RETURN NIL

//----------------------------------------------------------------------------//

METHOD Cancelado() CLASS TRelatorio
   LOCAL lCancelado := .F.
   //? 'Cancelado'
   IF ValType(::oRelatorio)='U'
      lCancelado := .T.
   END

RETURN lCancelado

//----------------------------------------------------------------------------//

METHOD Zoom() CLASS TRelatorio

   IF ::cTipo = "PRINT"
      IF ::oRelatorio:lIniZoom
         ::oRelatorio:lIniZoom := .F.
      ELSE
         ::oRelatorio:lIniZoom := .T.
      END
   END

RETURN NIL

//----------------------------------------------------------------------------//

 

CLASSE TPRINTER COM ALGUNS PONTOS DE CHECAGEM

METHOD New( cDocument, lUser, lMeta, cModel, lModal, lSelection ) CLASS TPrinter

   local aOffset
   local cPrinter

   DEFAULT cDocument  := "FiveWin Report" ,;
       lUser := .f., lMeta := .f., lModal := .f., lSelection := .f.

   ? 'Metodo New - Classe Tprinter','lUser',lUser,'lMeta',lMeta,'cModel',cModel

   if lUser
      ::hDC := GetPrintDC( GetActiveWindow(), lSelection, PrnGetPagNums() )
      if ::hDC != 0
         cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()
      endif
   elseif cModel == nil
      //? 'cModel=empty()'
      ::hDC  := GetPrintDefault( GetActiveWindow() )
      //?  '::hDc',::hDc
      if ::hDC != 0
         cModel = ::GetModel() + "," + ::GetDriver
() + "," + ::GetPort()
      endif
      //? 'cModel',cModel
   else
      cPrinter := GetProfString( "windows", "device" , "" )
      WriteProfString( "windows", "device", cModel )
      SysRefresh()
      PrinterInit()
      ::hDC := GetPrintDefault( GetActiveWindow() )
      SysRefresh()
      WriteProfString( "windows", "device", cPrinter  )
      // PrinterInit()
      // DeleteDC( ::hDC )
      // ::hDC = PrinterDCfromName( cModel )
   endif

    //? '1'

   if ::hDC != 0
      aOffset    = PrnOffset( ::hDC )
      ::nXOffset = aOffset[ 1 ]
      ::nYOffset = aOffset[ 2 ]
      ::nOrient  = ::GetOrientation()

   //? '2'

   elseif ComDlgXErr() != 0
      MsgStop( "There are no printers installed!"  + CRLF + ;
               "Please exit this application and install a printer." )
      ::nXOffset = 0
      ::nYOffset = 0
   //? '3'
   else
      ::nXOffset = 0
      ::nYOffset = 0
      ::nOrient  = DMORIENT_PORTRAIT
   //? '4'
   endif


   //? '5'

   ::cDocument = cDocument
   ::cModel    = cModel
   ::nPage     = 0
   ::nPad      = 0
   ::lMeta     = lMeta
   ::lStarted  = .F.
   ::lModified = .F.
   ::lPrvModal = lModal

   // ? '6'

   if !lMeta
      ::hDcOut = ::hDC
      //? 'lMeta - .f.',lMeta
   else
     //? 'lMeta - .t.',lMeta
      ::aMeta  = {}
      ::cDir   = GetEnv( "TEMP" )

      //? '7'

      if Empty( ::cDir )
         ::cDir = GetEnv( "TMP" )
      endif

      //? 'cDir',::cDir

      if Right( ::cDir, 1 ) == "\"
         ::cDir = SubStr( ::cDir, 1, Len( ::cDir ) - 1 )
      endif

      if ! Empty( ::cDir )
         if ! lIsDir( ::cDir )
            ::cDir = GetWinDir()
         endif
      else
         ::cDir := GetWinDir()
      endif
   endif

   ? 'Saindo do New da Classe TPrinter'
   ? 'Self',valtype(Self)
return Self  -- >NESTE PONTO DA O ERRO

 

 

 

Silvano Bispo Faria

AWS Sistemas Empresariais

(15)3202-4498

FWH 13.02/xHabour.com/Pelles/xMate

Link to comment
Share on other sites

CLASSE TPRINTER COM ALGUNS PONTOS DE CHECAGEM


METHOD New( cDocument, lUser, lMeta, cModel, lModal, lSelection ) CLASS TPrinter


 


Isto já não existe na CLASSE TPRINTER?  Voce declara de novo?? E se voce modificar direto na TPRINTER, o que acontece?

Link to comment
Share on other sites

Ola Kapiaba,

 

Isto é um trecho da classe própria classe Tprinter só pra ilustrar onde está dando o erro, no caso a parte que está em vermelho, mais especificametne return Self da classe. Coloquei alguns pontos de checagem na classe só para rastrerar o erro. O problema é que o erro acontece qdo ela é chamada pela classe TRelatório que fiz, pra facilitar o uso da TPrinter.

 

Att.

 

Silvano

Link to comment
Share on other sites

Boa tarde Silvano

 

Já tentou usar a função PrintBegin() no lugar dos comandos ?

 

No caso, ao invéz de usar:

 

IF lVisualizar
   PRINT ::oRelatorio NAME ::cTitulo PREVIEW
ELSE
    PRINT ::oRelatorio NAME ::cTitulo
END

 

ficaria: PrintBegin( ::cTitulo,.T.,lVisualiza,nil,.T. ) 

 

ou algo parecido, dê uma olhada nos parâmetros desta função(nativa da tPrinter )

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...