rPreview does not close when app closes

User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

rPreview does not close when app closes

Post by reinaldocrespo »

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.
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: rPreview does not close when app closes

Post by Daniel Garcia-Gil »

Reinaldo

Can you post a little sample to show the error?

Thanks
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
RAMESHBABU
Posts: 626
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: rPreview does not close when app closes

Post by RAMESHBABU »

Hi Reinaldo,

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

Code: Select all | Expand



IF ::oDevice:lPrvModal
    StopUntil( { || ::lExit } )
ENDIF

 


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

Regards,

- Ramesh Babu P
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: rPreview does not close when app closes

Post by nageswaragunupudi »

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

This issue is not from the new rpreview
Regards

G. N. Rao.
Hyderabad, India
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: rPreview does not close when app closes

Post by reinaldocrespo »

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.
JoseLuis
Posts: 428
Joined: Thu Oct 19, 2006 12:28 pm
Location: Toledo

Re: rPreview does not close when app closes

Post by JoseLuis »

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
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: rPreview does not close when app closes

Post by reinaldocrespo »

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: Select all | Expand


*--------------------------------------------------------------------------------------
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: Select all | Expand

*--------------------------------------------------------------------------------------
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: Select all | Expand


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

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.
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: rPreview does not close when app closes

Post by reinaldocrespo »

... 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: Select all | Expand


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.
User avatar
James Bott
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: rPreview does not close when app closes

Post by James Bott »

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
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: rPreview does not close when app closes

Post by Daniel Garcia-Gil »

Reinaldo

Try this way

open /source/function/msgrun.prg

change in function StopUntil()

Code: Select all | Expand

DO WHILE !Eval( bBlock ) .and. WndMain() != NIL .and. IsWindow( WndMain():hWnd )
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: rPreview does not close when app closes

Post by Daniel Garcia-Gil »

Reinaldo

forget my last post

is more easy change window class
try changing this "IF"

Code: Select all | Expand


   if ::hWnd != 0 .and. GetWndApp() == ::hWnd
      PostQuitMessage( 0 )
      Sysrefresh()
      QUIT
   endif
 
our best documentation is the source code
Isla de Margarita Venezuela.
danielgarciagil@gmail.com
http://tdolphin.blogspot.com/
https://www.dropbox.com/referrals/NTI5N ... rc=global9
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: rPreview does not close when app closes

Post by nageswaragunupudi »

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: Select all | Expand

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
User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

Re: rPreview does not close when app closes

Post by Enrico Maria Giordano »

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


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

Code: Select all | Expand

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


EMG
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: rPreview does not close when app closes

Post by reinaldocrespo »

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: Select all | Expand


     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.
User avatar
reinaldocrespo
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: rPreview does not close when app closes

Post by reinaldocrespo »

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.
Post Reply