Antonio: "BUG" in TPrinter

Antonio: "BUG" in TPrinter

Postby byte-one » Tue Jan 21, 2014 9:55 am

Antonio, i am using a printerobject with the direct pdf-output. Now i see, that the emf-files in the temp-directory are still present and should be deleted! If i will manually or programatically delete this files, i become a "Access Violation".
...and the temp-directory grows and grows...
A second question: After ENDPRINT the printobject shows with valtype(oPrint) still "O"???
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby Antonio Linares » Tue Jan 21, 2014 2:06 pm

Gunther,

1. the emf-files in the temp-directory are still present

Where is located your temp-directory ? What files are there ? Please show a test and the names of the files that you get. If you cant delete them it means that they are open (in use)

2. END... does not mean that the object is turned into nil. When you go out of the scope where it is defined, the garbage collector will do its work and will finally free it.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Tue Jan 21, 2014 5:04 pm

1. Antonio, when using normal Tprinter-object the EMFs are deleted! Only when i use the direct pdf-creation with clausula ..FILE "xyz.pdf" the files in Format z.b. "234571.emf" are not erased! The temp-directory are in normal windows location.
2. END.. Ok, i understand!!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby Antonio Linares » Tue Jan 21, 2014 10:47 pm

Gunter,

Are you calling ENDPRINT after sending the print to the PDF file ?

Class TPrinter Method End() is responsible for deleting the metafiles.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Wed Jan 22, 2014 8:10 am

Code: Select all  Expand view
function PrintEnd()
   if oPrinter:lMeta
      if Empty( oPrinter:cFile )
         oPrinter:Preview()
      elseif "pdf" $ Lower( oPrinter:cFile )
         FWSavePreviewToPDF( oPrinter, If( Lower( cFileExt( oPrinter:cFile ) ) == "pdf", ;
               oPrinter:cFile, nil ), oPrinter:lPreview )
      endif
   else
      oPrinter:End()
   endif
   oPrinter := nil
return nil


Antonio, you see, that end() only calling on normal prints! On preview, the preview itself deletes the EMFs, on FWSavePreviewToPDF(..) nobody deletes this files!
Should end() called in all cases?
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Wed Jan 22, 2014 8:49 am

Antonio, I found a solution:

1. In Emf2Jpeg() instead of CloseEnhMetafile() using DeleteEnhMetafile()! In this function should also inserted a sysrefresh(). Then i can produce hundreds of pages without Problems!
2. In FWSavePreviwToPDF() before returning oDevice:end() BUT only, when not called from TPreview as the preview deletes the EMFs!!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby Antonio Linares » Wed Jan 22, 2014 9:02 am

Gunther,

I guess you can also do:

ENDPRINT
oPrinter:End()

anyhow, please post here your exact code changes so we can review them and include them, many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41315
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Thu Jan 23, 2014 9:13 am

This is my code, I use. In poor Computers with only 1Gb memory it can bee, the program terminates without any message! Possibly from the FI functions with Memory?

Code: Select all  Expand view
//----------------------------------------------------------------------------//

function FWSavePreviewToPDF( oDevice, cPDF, lOpen, nQual )   // oDevice can be oPrinter or oPreview

   local cOrient, oPDF
   local hWnd , lPreview

   DEFAULT nQual := 0 , lPreview := .F.

   if oDevice:IsKindOf( "TPREVIEW" )
      hWnd     := oDevice:oWnd:hWnd
      oDevice  := oDevice:oDevice
      lPreview := .T.
   endif

   if LoadFreeImage() <= 32
      MsgAlert( "freeimage.dll not found" )
      return nil
   endif

   DEFAULT cPDF   := cGetFile( "PDF File (*.pdf)|*.pdf|", "Select PDF File to Save", ;
                               CurDir(), .t. )

   if ! Empty( cPDF )
      cPDF = cFileSetExt( cPDF, "pdf" )
      CursorWait()
      cOrient = If( oDevice:nHorzSize() > oDevice:nVertSize(), 'L', 'P' )
      oPdf = fwPdf():New( cPdf, cOrient, nQual )
      AEval( oDevice:aMeta, { | cMeta |( oPdf:AddMeta( cMeta )) } )
      oPdf:Close()
      CursorArrow()


      DEFAULT lOpen := MsgYesNo( "View " + cPDF + " (Y/N)?" )

      if lOpen
         ShellExecute( IfNil( hWnd, GetWndDefault() ), "open", cPDF )
      endif
   else
      cPDF  := nil
   endif

  if(!lPreview,oDevice:End(),)      //BYTE-ONE 2014

return cPDF

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

static function Emf2Jpeg( cEMF , nQual )

   local cJpeg    := cFileSetExt( cEMF, "jpg" )
   local hDC1, hDC, hDib, hDib2, hMem, hBmp, hOldBmp, hEMF
   local cBuf, oRect, lRet := .f.
   local nFormat

   cBuf         := MemoRead( cEMF )
   oRect        := TRect():New( 0, 0, Bin2L( SubStr( cBuf, 21, 4 ) ) / 2, ;
                                  Bin2L( SubStr( cBuf, 17, 4 ) ) / 2  )
   cBuf        := nil  // to release memory
   HB_GCAll(.T.)
   hEMF        := GetEnhMetaFile( cEMF )
   hDC1        := GetDC( GetDesktopWindow() )
   hDC         := CreateCompatibleDC( hDC1 )
   hBmp        := CreateCompatibleBitmap( hDC1, oRect:nWidth, oRect:nHeight )
   hOldBmp     := SelectObject( hDC, hBmp )
   FillRect( hDC, oRect:aRect, GetStockObject( 0 ) )
   PlayEMF( hDC, hEMF, oRect:cRect )
   DeleteEnhMetafile( hEMF )        //BYTE-ONE 2014
   hDib        := DibFromBitmap( hBmp )
   cBuf        := DibToStr( hDib )
   GloBalFree( hDib )
   SelectObject( hDC, hOldBmp )
   DeleteDC( hDC )
   DeleteDC( hDC1 )
   DeleteObject( hBmp )
   hMem        := FI_OpenMemory( cBuf, Len( cBuf ) )
   nFormat     := FI_GetFileTypeFromMemory( hMem, 0 )
   hDib        := FI_LoadFromMemory( nFormat, hMem, 0 )
   FI_CloseMemory( hMem )
   cBuf        := nil  // to release memory
   HB_GCAll(.T.)
   hDib2       := FICnv24( hDib )
   FIUnload( hDib )
   lRet        := FISave( 2, hDib2, cJpeg, nQual )
   FIUnload( hDib2 )
   cBuf        := If( lRet, MemoRead( cJpeg ), "" )
   FErase( cJpeg )
   sysrefresh()     //BYTE-ONE 2014

return cBuf

//----------------------------------------------------------------------------//
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby James Bott » Tue Jan 28, 2014 5:20 pm

Have you checked for memory leaks?
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Tue Jan 28, 2014 7:20 pm

Yes James, no leaks. Maybe the memory-functions from "freeimage" are responsible for this fault!?
We should change to file-functions, but i am not so versed with freeimage.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby James Bott » Tue Jan 28, 2014 7:56 pm

Günther,

Perhaps you need to use a general purpose memory leak detector program instead of the Fivewin functions. This might find memory leaks in freeimage.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Antonio: "BUG" in TPrinter

Postby James Bott » Tue Jan 28, 2014 8:37 pm

Maybe this old message will help.

James

From: Patrick Mast <patrick@winfakt.com>
Subject: Re: FW Win 2000
Date: Friday, January 05, 2001 2:08 AM

Uwe,

> Big Prob my Fw App crashes with a Gpf under Win 2000
> Any Tip for me ??
My app works great in Win2000.

Have you tried this:

Code: Select all  Expand view
// In the begin of your app:
InterruptRegister( { || ControlGPF() } )  // Setting our own GPF controller

//-----------
function ControlGPF() //SOCS
   CLOSE DATA
   MsgAlert( "A Windows GPF occured...")
   InterruptUnRegister()   // We release our GPF controller
   Eval( ErrorBlock(), _FWGenError( 5, "Undetermined GPF" ) )
Return nil
//---------
 

This way maybe you can see what line causes the GPF.

--
Regards,

Patrick Mast
http://www.Patrick.Be.kz
http://www.FiveWin.Be.kz
http://www.Harbour-Project.org
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Antonio: "BUG" in TPrinter

Postby nageswaragunupudi » Mon Feb 03, 2014 2:54 pm

Mr Gunther and Mr Antonio

I suggest modification of printend() function and no other changes anywhere else.

Proposed New function
Code: Select all  Expand view
function PrintEnd()

   if oPrinter:lMeta
      if Empty( oPrinter:cFile )
         oPrinter:Preview()
      elseif "pdf" $ Lower( oPrinter:cFile )
         FWSavePreviewToPDF( oPrinter, oPrinter:cFile, oPrinter:lPreview )
         oPrinter:End()
      endif
   else
      oPrinter:End()
   endif

   oPrinter := nil

return nil
 

Do you think this solves the issue?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Antonio: "BUG" in TPrinter

Postby byte-one » Mon Feb 03, 2014 9:41 pm

OK, but usíng CloseEnhMetaFile() frees not the emf-files to let them erasing!
We must use DeleteEnhMetafile( hEMF ) in the function Emf2Jpeg(...)!
Another negative issue from this function is the dependency from the resolution of the Printer-Driver. It should in all cases
the same!
I suggest further the option to use automatically (if available) a PDF-Printer-Driver (with a special name?).
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Re: Antonio: "BUG" in TPrinter

Postby nageswaragunupudi » Sat Feb 15, 2014 6:33 am

Implemented.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests