FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour rPreview does not close when app closes
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
rPreview does not close when app closes
Posted: Thu Feb 10, 2011 02:40 AM

Hi.

I noticed that with new rPreview, the main app may close while the preview will stay open (does not close with the app). Although it stays open it becomes .NOT. operable. Any solution?

Thank you,

Reinaldo.

Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 04:16 AM

Reinaldo

Can you post a little sample to show the error?

Thanks

Posts: 654
Joined: Fri Oct 21, 2005 05:54 AM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 08:29 AM
Hi Reinaldo,

The following code in METHOD Activate() CLASS TPreview is responsible for your pboblem.

Code (fw): Select all Collapse
IF ::oDevice:lPrvModal
    StopUntil( { || ::lExit } )
ENDIF


Please check wether ::lExit is assigned .T. or not.

Regards,

- Ramesh Babu P
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 12:03 PM

Please see

viewtopic.php?f=3t=20693p=110112hilit=rpreview#p110112

This issue is not from the new rpreview

&&&

Regards



G. N. Rao.

Hyderabad, India
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 01:06 PM

Rao; Hi. Appreciate your efforts. Don't take me wrong -this is not an attack. I don't know what you mean by "is not from the new preview". Once upon a time, it was not a problem. Now it is. Is it from new-little less new-new-newest-newer..... does not matter. It is still an issue. Actually, an unresolved issue.

Daniel; Hola, que tal?. If you really want a self contained small sample, I'll be glad to provide it. But you can reproduce this problem yourself with any fw app. Just open a preview window and then close the main app window. You will see. As Rao implies, it is a documented-unresolved problem. I'm thinking that hardly anybody is using [newer] rpreviews anymore. Could this be the case?

Ramesh; Thank you. I will try removing the clause. But then again, why is it there in the first place?

With kind regards to you all,

Reinaldo.

Posts: 428
Joined: Thu Oct 19, 2006 12:28 PM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 01:25 PM

This happened to me when using FWH 10.12, Backward rpreview.

Repexcel I used to export to Excel, and since it is impossible for this reason.

--------------------------

Saludos



Jose Luis
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 02:15 PM
Jose Luis /and all others;

I think that there are better ways to export a treport to Excel. The main caveat with the way fw is doing it, is that you MUST have Excel installed on the computer. Currently I'm able to export Treports to Excel without using ole, thus you don't need to have Excel installed. This opens the door to use freely distributed Open Office or simply allow the user to create an .xls to take somewhere.

Since the "newer" rpreview allows to add buttons with actions, I thought I should make an effort to stop using my own modified rpreview and to come to the main fw rpreview distribution. Perhaps I don't quite understand many things, but I've had to make almost the same changes to the "newer" rpreview. To start with, (1) the word factor overlaps with the buttons (there is already a thread on this subject and it looks ugly), (2) then I find that if the app is themed, new buttons and actions are ignored by this "newer" rpreview, (3) if you close the parent application, rpreview windows stay open and becomes a cpu hog.... So, I've decided to change rpreview again and (1) give it a better looking appearence by implementing a graded tbar with 32 x 32 bitmaps, (2) going back to the way I add custom buttons for custom actions, (3) getting rid of IsAppThemed() everywhere and (4) commenting out the eternal while loop that may cause the window to stay open after the main app has been closed.

The reason I'm sharing this is so that maybe, and if it makes sense, rpreview will have a more stable future.

Here is how I'm adding custom buttons:
Code (fw): Select all Collapse
*--------------------------------------------------------------------------------------
function AddExportBtns( oPreview, oBar, oReport )
local aRet
Local cpdfName

    cPdfName := alltrim( GetTempDir() + ;
        AllTrim( StrTran( StrTran( oPreview:oDevice:cDocument, "/", "-" ), " ", "_" ) ) ) + ".pdf"

    aRet := { { "Excel", "Export to Excel",;
            {|| oReport:SaveAs( "EXCEL" ) }, "Excel" },;
        { "Pdf", "Export to Pdf Document",;
            { || BuildPdf( oPreview:oDevice:aMeta, cpdfName, .f., .t. ) }, "Pdf" } }
            
Return aRet


Then on my tMReport class that inherits from treport and that is capable of producing a xls file without ole, I do this:

Code (fw): Select all Collapse
*--------------------------------------------------------------------------------------
METHOD New( aTitle, aHead, aFoot, aFont, lSummary, cRptFile, ;
               cResName, lPrinter, lScreen, cFile, oDevice, ;
               cName, cTFmt, cHFmt, cFFmt ) CLASS TMReport

   Local uReturn := Super:New( aTitle, aHead, aFoot, aFont, lSummary, cRptFile, ;
                               cResName, lPrinter, lScreen, cFile, oDevice, ;
                               cName, cTFmt, cHFmt, cFFmt )

   If Empty( uReturn ) // Error
      Return Nil
   EndIf

   //rPrevUserBtns is a new function in rPreview.prg
   RPrevUserBtns( { |oPreview, oBar| addExportBtns( oPreview, oBar, Self ) } )
    
   ::bPreview  := { |oDevice, oRpt| rPreview( oDevice, oRpt ) }

Return Self


Finally on rPreview fix buildButtonBar(). Notice it is much simpler:

Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

METHOD BuildButtonBar() CLASS TPreview

   local oThis := Self
    local oBtn
   local oReBar, oBar, oWndMain
   local l97Look  := ::oWndMain != nil .and. ::oWndMain:oBar != nil .and. ;
                     Len( ::oWndMain:oBar:aControls ) > 0 .and. ;
                     ::oWndMain:oBar:aControls[ 1 ]:l97Look
    local aPreviewBtns, aBtn

   DEFINE CURSOR ::oHand HAND

   if WndMain() != nil
      if WndMain():oBar != nil
         oBar = WndMain():oBar
         if oBar != nil .and. Upper( oBar:ClassName() ) == "TBAR" .and. oBar:l2007
            l2007 = .T.
         endif
      endif
   endif

   if !empty( bUserBtns )
        aPreviewBtns := Eval( bUserBtns, Self, oBar )
   endif

   oBar := TBar():New( ::oWnd, 50, 60, .F.,,, .T. )
    
   TBtnBmp():NewBar( "Top",,,,, {|| ::TopPage() }, .F., oBar, .F.,,;
        "First Page", .F.,,,, "First",,,,,,,,, .F. )
        
   TBtnBmp():NewBar( "Previous",,,,, { || ::PrevPage() }, .F., oBar, .F.,,;
        "Prev Page", .F.,,,, "Prev",,,,,,,,, .F. )

   TBtnBmp():NewBar( "Next",,,,, {|| ::NextPage()}, .F., oBar, .F.,,;
        "Next Page", .F.,,,, "Next",,,,,,,,, .F. )
        
   TBtnBmp():NewBar( "Bottom",,,,, {|| ::BottomPage() }, .F., oBar, .F.,,;
        "Last Page", .F.,,,, "Last",,,,,,,,, .F. )

   TBtnBmp():NewBar( "Zoom",,,,, {|| ::zoom() }, .T., oBar, .F.,, ;
        "Zoom", .F.,,,, "Zoom",,,,,,,,, .F. )

   TBtnBmp():NewBar( "Two_Pages",,,,, {||::TwoPages() }, .F., oBar, .F.,,;
        "View two pages side by side", .F.,,,,"Two Pages",,,,,,,,, .F. )
        
   TBtnBmp():NewBar( "Printer",,,,, {|| ::PrintPage() }, .F., oBar, .F.,, ;
        "Print", .F.,,,, "Print",,,,,,,,, .F. )

   if aPreviewBtns != Nil .and. valtype( aPreviewBtns ) = "A" .and. ;
                len( aPreviewBtns ) > 0

        FOR EACH aBtn IN aPreviewBtns
            TBtnBmp():NewBar( aBtn[ 1 ],,,,, aBtn[ 3 ], .F., oBar, .F.,, ;
                        aBtn[ 2 ], .F.,,,, aBtn[ 4 ],,,,,,,,, .F. )
        NEXT

   endif

   oBtn := TBtnBmp():NewBar( "Exit",,,,, {|| oThis:oWnd:end() }, .F., oBar, .F.,, ;
        "Exit", .F.,,,, "Exit",,,,,,,,, .F. )

   @ 7, oBtn:nRight + 5 SAY ::oSay PROMPT "Factor:" SIZE 45, 15 PIXEL OF oBar FONT ::oFont
    ::oSay:lTransparent = .T.

   @ 3, oBtn:nRight + 50 COMBOBOX ::oFactor VAR ::nZFactor ;
      ITEMS { "1", "2", "3", "4", "5", "6", "7", "8", "9" } ;
      OF oBar FONT ::oFont PIXEL SIZE 35,200 ;
      ON CHANGE oThis:SetFactor( oThis:nZFactor )

   if Len( ::oDevice:aMeta ) > 1
    @ 7, oBtn:nRight + 95 ;
            SAY ::oPage PROMPT TXT_PAGENUM + LTrim( Str( ::nPage, 4, 0 ) ) + " / " + ;
            LTrim( Str( Len( ::oDevice:aMeta ) ) ) ;
            SIZE 180, 15 PIXEL OF oBar FONT ::oFont
   else
      @ 7, oBtn:nRight + 95 ;
         SAY ::oPage PROMPT TXT_PAGENUM + LTrim( Str( ::nPage, 4, 0 ) ) ;
            SIZE 180, 15 PIXEL OF oBar FONT ::oFont
   endif
   
   ::oPage:lTransparent = .T.

//  AEval( oBar:aControls, { | o | o:oCursor := ::oHand } )

return nil



Regards,


Reinaldo.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: rPreview does not close when app closes
Posted: Thu Feb 10, 2011 06:38 PM
... and hi again;

I need help with one issue, though. Now I find that I can't just comment out the line with the StopUntil( { || ::lExit } ). Otherwise, my tReport object is destroyed and thus make it un-exportable to Excel.

Maybe someone has a better solution?

There is the code I refer to:
Code (fw): Select all Collapse
METHOD Activate() CLASS TPreview

   ACTIVATE WINDOW ::oWnd MAXIMIZED ;
      ON RESIZE    ::PaintMeta()                            ;
      ON UP        ::VScroll( GO_UP )             ;
      ON DOWN      ::VScroll( GO_DOWN )           ;
      ON PAGEUP    ::VScroll( GO_UP, GO_PAGE)     ;
      ON PAGEDOWN  ::VScroll( GO_DOWN, GO_PAGE)   ;
      ON LEFT      ::HScroll( GO_LEFT )           ;
      ON RIGHT     ::HScroll( GO_RIGHT )          ;
      ON PAGELEFT  ::HScroll( GO_LEFT, GO_PAGE )  ;
      ON PAGERIGHT ::HScroll( GO_RIGHT, GO_PAGE ) ;
      VALID        ( ::oWnd:oIcon := nil       ,;
                     ::oFont:End()             ,;
                     ::oMeta1:End()            ,;
                     ::oMeta2:End()            ,;
                     ::oDevice:End()           ,;
                     ::oHand:End()             ,;
                     ::oWnd := nil             ,;
                     ::lExit := .T.            ,;
                     .T. )

     if ::oDevice:lPrvModal
        StopUntil( { || ::lExit } )    //<------ Look here.
     endif


return nil



Thank you,


Reinaldo.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 12:12 AM

Reinaldo,

You could try, when defining the report, something like this:

wndMain():bValid := {|| oRpt:lEnd := .t., .t.}

This should end the preview when the main window is closed.

Regards,
James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 12:48 AM
Reinaldo

Try this way

open /source/function/msgrun.prg

change in function StopUntil()

Code (fw): Select all Collapse
DO WHILE !Eval( bBlock ) .and. WndMain() != NIL .and. IsWindow( WndMain():hWnd )
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 01:43 AM
Reinaldo

forget my last post

is more easy change window class
try changing this "IF"
Code (fw): Select all Collapse
   if ::hWnd != 0 .and. GetWndApp() == ::hWnd
      PostQuitMessage( 0 )
      Sysrefresh()
      QUIT
   endif
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 02:52 AM
James Bott wrote:Reinaldo,

You could try, when defining the report, something like this:

wndMain():bValid := {|| oRpt:lEnd := .t., .t.}

This should end the preview when the main window is closed.

Regards,
James

Adopting Mr. James suggestion, the METHOD Activate() of TPreview class can be revised as:
Code (fw): Select all Collapse
METHOD Activate() CLASS TPreview

   local bValidMain := If( ::oWndMain == nil, nil, ::oWndMain:bValid )

   ACTIVATE WINDOW ::oWnd MAXIMIZED ;
      ON RESIZE    ::PaintMeta()                  ;
      ON UP        ::VScroll( GO_UP )             ;
      ON DOWN      ::VScroll( GO_DOWN )           ;
      ON PAGEUP    ::VScroll( GO_UP, GO_PAGE)     ;
      ON PAGEDOWN  ::VScroll( GO_DOWN, GO_PAGE)   ;
      ON LEFT      ::HScroll( GO_LEFT )           ;
      ON RIGHT     ::HScroll( GO_RIGHT )          ;
      ON PAGELEFT  ::HScroll( GO_LEFT, GO_PAGE )  ;
      ON PAGERIGHT ::HScroll( GO_RIGHT, GO_PAGE ) ;
      VALID        ( ::oWnd:oIcon := nil       ,;
                     ::oFont:End()             ,;
                     ::oMeta1:End()            ,;
                     ::oMeta2:End()            ,;
                     ::oDevice:End()           ,;
                     ::oHand:End()             ,;
                     If( ::oWndMain == nil,, ::oWndMain:bValid := bValidMain ),;
                     ::oWnd := nil             ,;
                     If( IsAppThemed() .and. ! l2007, ::oImageList:End(),),;
                     ::lExit := .T.            ,;
                     .T. )

     if ::oWndMain != nil
        if bValidMain == nil
           ::oWndMain:bValid := { || ::lExit := .t. }
        else
           ::oWndMain:bValid := { || If( Eval( bValidMain ), ::lExit := .t., .f. ) }
        endif
     endif

     if ::oDevice:lPrvModal
        StopUntil( { || ::lExit } )
     endif

return nil

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

This seems to be working well.
Can this be tested and feedback provided?
Regards



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 07:29 AM
James Bott wrote:wndMain():bValid := {|| oRpt:lEnd := .t., .t.}


The last .t. is redundant. This is equivalent:

Code (fw): Select all Collapse
wndMain():bValid := {|| oRpt:lEnd := .t.}


EMG
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 03:10 PM
Hi and thank you everyone. This is good brainstorming.

I think the following code incorporates from all of your ideas. It seems to do the trick. Please advise on your opinion:

Change Method Activate() on rPreview to:
Code (fw): Select all Collapse
     if ::oDevice:lPrvModal
        StopUntil( { || ::lExit .or. WndMain() == Nil .or. !IsWindow( WndMain():hWnd ) } )
     endif



This closes all the open rpreview windows when the main app is closed. Am I missing/forgetting/ommiting something?


Reinaldo.
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: rPreview does not close when app closes
Posted: Fri Feb 11, 2011 03:42 PM

José Luis;

I wish to talk more about repexcel. I`m starting a new thread on the Spanish forum. Please look for it. Thank you.

Reinaldo.