Program crashing

Program crashing

Postby HunterEC » Tue Jun 28, 2011 7: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: Select all  Expand view
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.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Program crashing

Postby hmpaquito » 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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Program crashing

Postby ukoenig » 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.

Image

The Logo resized with Transparent-level :

Image

Code: Select all  Expand view

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 :lol:
Last edited by ukoenig on Wed Jun 29, 2011 1:18 pm, edited 3 times in total.
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Program crashing

Postby nageswaragunupudi » Wed Jun 29, 2011 1: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
User avatar
nageswaragunupudi
 
Posts: 10482
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Program crashing

Postby nageswaragunupudi » Thu Jun 30, 2011 6: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: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10482
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Program crashing

Postby HunterEC » 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.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Program crashing

Postby hmpaquito » Fri Jul 01, 2011 2:51 pm

HunterEC,

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

Bye
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Program crashing

Postby HunterEC » Sun Jul 03, 2011 5: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.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Program crashing

Postby hmpaquito » Sun Jul 03, 2011 6:51 am

HunterEC,

Ok.

I´m sorry about my bad humor.

Regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 24 guests