FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Program crashing
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM

Program crashing

Posted: Tue Jun 28, 2011 07:40 AM
In this code, the program crashes with the following error:
1. When oWnd:end executes, it crashes with an error: Error/BASE 1004 Class 'NIL' has no exported method: END

Code (fw): Select all Collapse
STATIC oWnd

PROCEDURE Main (cSales)
   LOCAL oIcon, oWindow, oBitMap, oBru, oMenu, nChoice, nI, nIndex, cOption, ;
            cOpts


   * environment
   SETCANCEL(.F.)
   SET _3DLOOK ON
   SET CENTURY ON
   SET CONFIRM OFF
   SET DELETED ON
   SET EPOCH TO 2000
   SET ESCAPE ON
   SET WRAP ON

//   RDDSETDEFAULT("DBFCDX")
   request SIX
   rddRegister( "SIX", 1 )
   rddsetdefault( "SIX" )
    SET FILETYPE TO CDX

    DEFINE BRUSH oBru DISK "logobmp.bmp"
    DEFINE ICON oIcon DISK "logobmp.bmp"

    DEFINE WINDOW oWindow FROM 13,45 TO 51,169 ;
         TITLE "Sample Window";
         BRUSH oBru MENU MainMenu (@oWindow, @oMenu, @nChoice)  ;
         ICON oIcon

    SET MESSAGE OF oWindow TO "Oprima Alt-Letra Subrayada" CLOCK DATE KEYBOARD

    DEFINE BITMAP oBitMap DISK "logobmp.bmp" OF oWindow

   oWnd := oWindow

    oWindow:Center()

   ACTIVATE WINDOW oWindow

   CLOSE DATABASES
RETURN


STATIC PROCEDURE MainMenu (oWindow, oMenu, nChoice)
  SETKEY(ASC("X"), {|| IIF( GetKeyState( ACC_ALT ), EVAL({|| IIF(ALERT( ;
          "¿ Terminar Si/No ?", {"Si", "No"}, "Salir del Programa", 2) == 1, ;
            oWindow:End(), NIL)}), NIL)})

   MENU oMenu
        MENUITEM "&File"      MESSAGE "Utilidades sobre archivos, Terminar"
        MENU
            MENUITEM "&Salir Alt-X" ;
                ACTION IIF(ALERT("¿ Terminar Si/No ?", {"Si", "No"}, ;
                                 "Salir del Programa", 2) == 1, oWindow:End(), NIL);
                MESSAGE "Salir del programa"
        ENDMENU

        MENUITEM "&Mantenimiento"  MESSAGE "Datos sobre Clientes"
         MENU
            MENUITEM "&Sample"          MESSAGE "Mantenimiento a Inventario" ;
                    ACTION Mant(@oWindow)
            MENUITEM "&Records"          MESSAGE "Ver La Base De Datos" ;
                    ACTION DispRecs()
        ENDMENU
    ENDMENU
RETURN
* EOP: MainMenu

Thank you guys.
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Program crashing

Posted: Wed Jun 29, 2011 11:31 AM
Hunter,

Try that:

...
MainMenu (@oWindow, @oMenu, @nChoice, {|| oWindow })

...

STATIC PROCEDURE MainMenu (oWindow, oMenu, nChoice, bWindow)


SETKEY(ASC("X"), {|| IIF( GetKeyState( ACC_ALT ), EVAL({|| IIF(ALERT( ;
"¿ Terminar Si/No ?", {"Si", "No"}, "Salir del Programa", 2) == 1, ;
Eval(bWindow):End(), NIL)}), NIL)})

...
Regards
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: Program crashing

Posted: Wed Jun 29, 2011 12:49 PM
I did some changes, as well I added a Logo-function, because You want to display a Logo.
You can call the Function anywhere You like.
It supports Format-detection, Logo-resizing and Transparent-level
The menu-exit works.



The Logo resized with Transparent-level :



Code (fw): Select all Collapse
STATIC oWnd, c_Path 

FUNCTION Main ()
LOCAL oIcon, oBru, oMenu, nChoice := 1, nI, nIndex, cOption, cOpts

* environment
SETCANCEL(.F.)
SET _3DLOOK ON
SET CENTURY ON
SET CONFIRM OFF
SET DELETED ON
SET EPOCH TO 2000
SET ESCAPE ON
SET WRAP ON
SetBalloon( .T. ) // Balloon shape required for tooltips
c_Path := CURDRIVE() + ":\" + GETCURDIR()

DEFINE BRUSH oBru DISK c_path + "\Bitmaps\Paper.Bmp"
DEFINE ICON oIcon DISK c_path + "\Bitmaps\case.bmp"

DEFINE WINDOW oWnd FROM 10, 10 TO 500, 800 PIXEL ;
TITLE "Sample Window";
BRUSH oBru MENU MainMenu (oMenu, nChoice) ICON oIcon

SET MESSAGE OF oWnd TO "Oprima Alt-Letra Subrayada" CLOCK DATE KEYBOARD

// Transparent 255 = full transparent

ACTIVATE WINDOW oWnd ;
ON INIT oWnd:Center() ;
ON PAINT  NEW_LOGO1(hDC, 255, 0.5, 30, 400, "Logo.bmp" )  

oBru:End()
oIcon:End()

RETURN

// ------------------ LOGO -----------

FUNCTION NEW_LOGO1(hDC, nTransp, nResize, nTop, nLeft, cLogo)
LOCAL oLogo, oTmp, hBmpO, nLW, nLH 

// get original Image-size
// ---------------------------
DEFINE IMAGE oTmp FILENAME c_path + "\Bitmaps\" + cLogo 
nLW := oTmp:nWidth()
nLH := oTmp:nHeight()
oTmp:End()

// Load and detect Alpha-image
// ----------------------------------
oLogo := FILoadImg( c_path + "\Bitmaps\" + cLogo )
lAlpha := HasAlpha( oLogo )

// Resize = 0, displays original Logo-size
// ---------------------------------------------
IF nResize <> 0
    hBmpO := oLogo
    oLogo := ResizeImg( hBmpO, nLW * nResize, nLH  * nResize ) 
    DeleteObject( hBmpO )
ENDIF

IF lAlpha = .T.
    ABPaint( hDC, nLeft, nTop, oLogo, nTransp )
ELSE
    IF nTransp = 255 // supports JPG-format full Color
        DrawBitmap( hDC, oLogo, nTop, nLeft )
    ELSE
        ABPaint( hDC, nLeft, nTop, oLogo, nTransp )
    ENDIF
ENDIF

RETURN( NIL )


Best Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Program crashing

Posted: Wed Jun 29, 2011 01:14 PM

The function MainMenu executes prior to creation of the main window. Therefore the parameter oWindow received by MainMenu() function is NIL and you are calling oWindow:End() results in calling NIL:End().

Instead of using oWindow:End(), use WndMain():End()

Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Program crashing

Posted: Thu Jun 30, 2011 06:39 AM
You better implement Alt-X behavior through ACCELERATOR clause of menu item, than by set key.

MainMenu() should be a function returning Menu Object.

This is a simplified code implementing what you wanted. You can later add language specific code and code for logos and bmps.
Code (fw): Select all Collapse
#include "FiveWin.Ch"

REQUEST DBFCDX

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

PROCEDURE Main (cSales)

   local oWnd

   * environment
   SETCANCEL(.F.)
   SET CENTURY ON
   SET DELETED ON
   SET EPOCH TO 2000
   SET ESCAPE ON

   RDDSETDEFAULT("DBFCDX")


    DEFINE WINDOW oWnd FROM 13,45 TO 51,169 ;
         TITLE "Sample Window";
         MENU MainMenu()

    SET MESSAGE OF oWnd TO "Oprima Alt-Letra Subrayada" CLOCK DATE KEYBOARD

   ACTIVATE WINDOW oWnd ON INIT oWnd:Center() ;
      VALID ( MsgYesNo( "Terminate (Y/N) ?" ) )

   CLOSE DATABASES

RETURN


STATIC FUNCTION MainMenu()

   local oMenu

   MENU oMenu
        MENUITEM "&File"      MESSAGE "Utilidades sobre archivos, Terminar"
        MENU
            MENUITEM "&Salir Alt-X" ;
            ACTION WndMain():End() ;
            MESSAGE "Salir del programa" ;
            ACCELERATOR ACC_ALT, ASC( "X" )
        ENDMENU

        MENUITEM "&Mantenimiento"  MESSAGE "Datos sobre Clientes"
         MENU
            MENUITEM "&Sample"          MESSAGE "Mantenimiento a Inventario" ;
                    ACTION MsgInfo( "xyz" )
            MENUITEM "&Records"          MESSAGE "Ver La Base De Datos" ;
                    ACTION MsgInfo( "DispRecs" )
        ENDMENU
    ENDMENU

RETURN oMenu

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

This is a working code. You may compile and test it. Then you can add your specific features.
Regards



G. N. Rao.

Hyderabad, India
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM

Re: Program crashing

Posted: Fri Jul 01, 2011 12:23 PM

Rao, Uwe:

Thank you very much for your answers. Learning through leaps and bounds, leaving old Clipper behind. :oops:

Rao:

I sent you an email to your gmail account.

Uwe:

How can your logo function work with a logo that is not in a file, I guess, in a resource ? What I don't want is end users messing with the icons and bitmaps. Thank you.

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Program crashing

Posted: Fri Jul 01, 2011 02:51 PM

HunterEC,

Thank you very much for your recognition to me.
In other problem I help to you.

Bye

Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM

Re: Program crashing

Posted: Sun Jul 03, 2011 05:17 AM

Hmpaquito:

My friend, my apologies, I forgot your post. I'm very sorry. Thank you very much for your help my friend. Your help was very valuable, it was late at night when I posted, I was dead tired.

Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM

Re: Program crashing

Posted: Sun Jul 03, 2011 06:51 AM

HunterEC,

Ok.

I´m sorry about my bad humor.

Regards

Continue the discussion