[futurebasic] Failed Assertion

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Brian Heibert <heibert@...>
Date: Fri, 4 Jan 2008 19:11:55 -0500
>
> I am using FutureBASIC 4, Release 4
> 4.4.1 with FBtoC 1.0
> and in my program I am getting this failed assertion
Failed Assertion:
fn IsWRefConFBHandle (wRefCon)
at line 951 in RTM APPEARANCE.INCL


>
> I get the failed assertion if I click on the About MyCal menu item  
> a second time after then
>
>
>
> I can't seem to find where the error is here is the code
>
> Any Ideas?
>
> Brian
>
> /*
>  Al's FB nib Windows Sample
> FutureBASIC source code
> by Al Staffieri Jr. - 6/27/07
>
> Revised 8/14/07
>
> Uses some functions created by Bernie Wylde
> Also thanks to Brian Stevens
>
>
>
> CREATING A NEW NIB FILE
> - Launch Interface Builder, select Carbon > Window in the Starting
> Point window and click New.
> - A default window will be created. Select it and, in the Window
> Inspector palette, uncheck 'Standard Handler' & "Compositing'.
> - Set an ID number for all controls you put into the window.
> - ID s must be numbered from 1 to as many controls as there are
> - make sure the nib file is in the same folder as your Fb file.
> Thanks to Bernie
>
> */
>
>
>
> include "Tlbx IBCarbonRuntime.incl"
> include "Tlbx HIView.incl"
> include "Tlbx ControlDefinitions.incl"
>
>
>
> '~GLOBALS
>
> BEGIN GLOBALS
>
> ' name of nib file
> DIM gNibFileName$
> gNibFileName$ = "MyCal"
>
> ' a var to know when to quit running.
> DIM gProgramEnds
> gProgramEnds = 0
>
>
> ' Prefs window button states
>
>
> END GLOBALS
>
>
> '~FUNCTIONS
>
> local mode
> local fn MakeIntoFBWindow( w as WindowRef, wNum as long )// bw
> dim wRefCon as ^^FBwindowDescription
> dim as Str255 m
> dim as WindowClass @ wc
> dim as WindowAttributes @ wa
> dim as OSErr e
>
> e = 3
> long if ( fn GetWRefCon( w ) == 0 )// not FB window already
> e--
> long if ( fn FBGetWndPointer( wNum ) == 0 )// wNum unused
> e--
> wRefCon = fn NewHandleClear( sizeof( FBwindowDescription ) )
> long if ( wRefCon )
> e--
> wRefCon..FBwRef = wNum
> if ( fn GetWindowClass( w, wc ) != _noErr ) then wc =   
> _kDocumentWindowClass
> wRefCon..FBwWindowClass = wc
> if ( fn GetWindowAttributes( w, wa ) == _noErr ) then  
> wRefCon..FBwAttributes = wa
> wRefCon..FBidealSizeX = _maxInt/2
> wRefCon..FBidealSizeY = _maxInt/2
> fn AddFBWindowToList( w )
> SetWRefCon( w, wRefCon )
> fn InitFBClipRgn( w )
> end if
> end if
> end if
> long if ( e )
> if ( fn IsValidWindowPtr( w ) ) then DisposeWindow( w )
> m = "MakeIntoFBWindow failed for window" + str$( wNum ) + "." + chr$ 
> (13)
> select e
> case 3 : m += "Window already exists."
> case 2 : m += "Already FB window."
> case 1 : m += "NewHandleClear returned 0."
> end select
> stop m
> end if
> end fn
>
>
> '~'1
>
>
> local mode
> local fn MakeIntoFBButton( c as ControlRef, btnNum as long )//  
> Robert P
> dim cRefCon as ^^FBcontrolDescription
> dim as WindowRef w
> dim as Str255 m
> dim as OSErr e
>
> e = 4
> w = fn GetControlOwner( c )
> long if ( w )
> e--
> long if ( fn GetCRefCon( c ) == 0 )// not FB button already
> e--
> long if ( fn FindFBBtnControl( w, btnNum ) == 0 )// btnNum unused
> e--
> cRefCon = fn NewHandleClear( sizeof( FBcontrolDescription ) )
> long if ( cRefCon )
> e--
> cRefCon..FBcontrolRef = btnNum
> cRefCon..FBcontrolClass = _buttonControlClass
> cRefCon..FBcntrlSubclass = _buttonSubclass
> call SetControlReference( c, cRefCon )
> fn AddFBControlToList( fn GetWRefCon( w ), c, cRefCon )
> end if
> end if
> end if
> end if
> long if ( e )
> if ( fn IsValidControlHandle( c ) ) then call DisposeControl( c )
> m = "MakeIntoFBButton failed for button" + str$( btnNum ) + "." +  
> chr$( 13 )
> select e
> case 4 : m += "No window."
> case 3 : m += "Control is already FB button."
> case 2 : m += "Button already exists."
> case 1 : m += "NewHandleClear returned 0."
> end select
> stop m
> end if
> end fn
>
>
> local fn WindowGetContentView( w as WindowRef )
> '~'1
> dim as HIViewRef  @ contentView : contentView = 0
> dim as OSStatus     ignore
>
> ignore = fn HIViewFindByID( fn HIViewGetRoot( w ),  
> kHIViewWindowContentID.signature, kHIViewWindowContentID.id,  
> @contentView )
> end fn = contentView
>
>
> local mode
> local fn AllControlsToFBButtons( c as ControlRef )
> '~'1
> dim as ControlID      cID
> dim as ControlRef   @ sub
> dim as UInt16       @ count
>
> long if ( fn CountSubControls( c, @count ) == _noErr )
> while ( count )
> long if ( fn GetIndexedSubControl( c, count, @sub ) == _noErr )
> long if ( fn GetControlID( sub, @cID ) == _noErr )
> if ( cID.id ) then fn MakeIntoFBButton( sub, cID.id )
> fn AllControlsToFBButtons( sub )
> end if
> end if
> count--
> wend
> end if
> end fn
>
>
> '~'1
>
>
> local fn BuildWindowFromNib(WindowNumber, WindowName$)
> dim as IBNibRef @ nib
> dim as WindowRef @ w
> dim as OSStatus err
>
> LONG IF WINDOW(-windowNumber) = 0 ' window doesn't exist
> long if ( fn CreateNibReference( fn CFSTR( gNibFileName$ ), @nib )  
> == _noErr )
> long if ( fn CreateWindowFromNib( nib, fn CFSTR( WindowName$ ),  
> @w ) ==  _noErr )
> fn MakeIntoFBWindow( w, WindowNumber)
> fn AllControlsToFBButtons( fn WindowGetContentView( w ) )
> end if
> DisposeNibReference( nib )
> end if
> END IF
>
> window -WindowNumber// make FB window output window
> ' you can do some specific window stuff here before the window is  
> shown
> /*SELECT CASE WindowNumber
> CASE 1001
> CASE 1002
> END SELECT*/
> window WindowNumber// show window
> end fn
>
>
> '~'1
>
>
> local fn createMenus
> APPLE MENU "About MyCal..."
> edit menu 2
> end fn
>
>
>
> /*
> FOR USE WITH NIB MENUS (Not used here)
> local fn createMenus
> dim as IBNibRef @ nib
>
> long if ( fn CreateNibReference( fn CFSTR( gNibFileName$ ), @nib )  
> == _noErr )
> long if ( fn SetMenuBarFromNib( nib, fn CFSTR( "MenuBar" ) ) ==  
> _noErr )
> menu 1, 7, 1, "Quit/Q"// for FB's ridiculous quit handling
> end if
> end if
> end fn*/
>
>
> '~'1
>
>
> /*LOCAL FN testit(windowNumber, buttonID)
> WINDOW 1
> CLS
> PRINT
> LONG IF windowNumber = 1001
> IF buttonID = 1 THEN PRINT "OK"
> IF buttonID = 2 THEN PRINT "Cancel"
> PRINT "Checkbox 1 = " prefOptions.checkOne
> PRINT "Checkbox 2 = " prefOptions.checkTwo
> PRINT "Checkbox 3 = " prefOptions.checkThree
> PRINT "Radio Group = " prefOptions.radioGroup
> PRINT "Popup menu item = " prefOptions.PopMenu
> XELSE
> IF buttonID = 1 THEN PRINT "Find"
> IF buttonID = 2 THEN PRINT "Change"
> IF buttonID = 3 THEN PRINT "Cancel"
> PRINT "Change All = " findOptions.changeAll
> PRINT "Whole word = " findOptions.WholeWord
> PRINT "case = " findOptions.caseSensitive
> PRINT "Find String = " findOptions.findStr$
> PRINT "Replace string = " findOptions.replaceStr$
> END IF
> END FN*/
>
>
>
>
> '~MENUS
>
>
> local fn doMenu
> DIM menNum, menID
> menNum = menu(0)
> menID = menu(1)
> select case menNum
> case 254 ' <--- APPLE MENU
> fn BuildWindowFromNib(1000, "About")
> case 1 ' <--- FILE MENU
> select case menID
> ' file handling menu items not used for this demo
> CASE 7' Quit
> gProgramEnds = -1
> case else
> end select
> CASE 3
> ' Options Menu
> SELECT CASE MenID
> CASE 1
> //fn BuildWindowFromNib(1001, "Prefs")
> CASE 2
> //fn BuildWindowFromNib(1002, "Find/Replace")
> END SELECT
> case else
> end select
> menu
> end fn
>
>
>
>
> '~BUTTON CLICKS
>
>
> /*LOCAL FN PrefOptionsButtons(buttonid)
> ' buttonid is the button number that was pressed.
> ' We only need to check for push buttons.
> ' All other buttons/controls are handled automatically from the nib
> SELECT CASE buttonid
> CASE 1
> ' OK - get all options
> prefOptions.checkOne = BUTTON(3)
> prefOptions.checkTwo = BUTTON(4)
> prefOptions.checkThree = BUTTON(5)
> prefOptions.radioGroup = BUTTON(6)
> prefOptions.PopMenu = BUTTON(7)
> WINDOW -1001
> FN testit(1001, buttonid)
> CASE 2
> ' Cancel - reset old options
> appearance button 3,, prefOptions.checkOne
> appearance button 4,, prefOptions.checkTwo
> appearance button 5,, prefOptions.checkThree
> appearance button 6,, prefOptions.radioGroup
> appearance button 7,, prefOptions.PopMenu
> WINDOW -1001
> FN testit(1001, buttonid)
> END SELECT
> END FN
>
>
> '~'1
>
>
> LOCAL FN FindReplaceButtons(buttonid)
> ' buttonid is the button number that was pressed.
> ' We only need to check for push buttons.
> ' All other buttons/controls are handled automatically from the nib
> SELECT CASE buttonid
> CASE 1 ,2
> ' Find, Change buttons - get current options
> findOptions.changeAll = BUTTON(4)
> findOptions.WholeWord = BUTTON(5)
> findOptions.caseSensitive = BUTTON(6)
> findOptions.findStr$ = FN BUTTONTEXTSTRING$(7)
> findOptions.replaceStr$ = FN BUTTONTEXTSTRING$(8)
> IF buttonID = 1 THEN findOptions.replaceStr$ = ""
> window - 1002
> FN testIt (1002, buttonid)
> CASE 3
> ' Cancel Button - reset old options
> window - 1002
> appearance button 4,, findOptions.changeAll
> appearance button 5,, findOptions.WholeWord
> appearance button 6,, findOptions.caseSensitive
> Def SetButtonTextString (7, findOptions.findStr$)
> Def SetButtonTextString (8, findOptions.replaceStr$)
> FN testIt (1002, buttonid)
> END SELECT
> END FN*/
>
>
> '~'1
>
>
> local FN doButton(buttonid)
> ' buttonid is the button number that was pressed.
> ' Check which window the user was in with WINDOW(0)
> SELECT CASE WINDOW(0)
> CASE 1
> ' main window
>
> gProgramEnds=_zTrue
> CASE 1000
> ' About window. Only 1 button so just close window.
> WINDOW CLOSE 1000
> CASE 1001
> END SELECT
>
> end fn
>
>
>
> '~DIALOG (HANDLEEVENTS) FUNCTION
>
> local fn doDialog
> DIM dlogEvnt, dlogID
>  dlogEvnt = DIALOG(0)
>  dlogID  = DIALOG(dlogEvnt)
>
>  SELECT dlogEvnt'first figure out what event it was
> '------------- Window events --- (id =  window ID) -----------------
> CASE _wndClick'window clicked
> CASE _wndClose'window closed
> CASE _wndRefresh'window needs refreshing
> CASE _wndActivate'window activated or deactivated
>
> 'CASE _wndZoomIn'zoom in event (zoom box clicked)
> 'CASE _wndZoomOut'zoom out event
>
> '------------- Button events --- (id =  button ID) ----------------
> CASE _btnClick'button clicked (id = button id)
> // FN doButton(dlogID)
>
>
> '------------- Edit field events (id =  edit field ID) ------------
> CASE _efClick'edit field click
>
> CASE _pfClick ' appearance picture field click
>
> CASE _efReturn'return key in _NoCR type efs
>
> CASE _efTab'tab key pressed
> 'TEKEY$ = CHR$(9)
> 'CASE _efShiftTab'shift tab key pressed
> 'CASE _efClear'clear key pressed
> 'CASE _efLeftArrow'left arrow key pressed
> 'CASE _efRightArrow
> 'CASE _efUpArrow
> 'CASE _efDownArrow
>
> '------------- Key press events (id =  ASCII of key pressed) -----
> CASE _evKey'not with edit fields (see TEKEY$)
> 'IF dlogID = 13 THEN BEEP ' RETURN key pressed
>
> '------------- User defined events -----------------------------
> 'CASE _userDialog'id = user defined id (see EVENT&)
>
> '------------- Cursor events -------------------------------------
> CASE _cursEvent'id = 0    not over app wndw
> 'id = +num over window number id
> CASE _cursOver'id = 0    not over anything
> 'id = -num id of efld or pfld it's over
> 'id = +num id of button cursor over
> '         ------------- MultiFinder/System 7.0 events ----------------
> CASE _mfEvent
>  SELECT CASE dlogID'check kind of mf event occurred
> CASE _mfResume'appl switching to foreground
> CASE _mfSuspend'appl switching to background
> CASE _mfClipboard'clip changed while suspended
> CASE _mfMouse'mouse moved out of its region
>  END SELECT
>
> '         ------------- Preview events ---------------
> 'CASE _preview
> '
> 'SELECT dlogID
> 'CASE _preMenuClick'menu about to be pulled down
> 'CASE _preWndGrow'window about to resized
> 'CASE _preWndZoomIn'about to be zoomed
> 'CASE _preWndZoomOut'about to be zoomed out
> 'CASE _wndMoved'window has been moved
> 'CASE _wndSized'window size has changed
> ''CASE _efChanged'data changed in edit field
> 'CASE _wndDocWillMove'window about to be moved
> 'END SELECT
> '
>  END SELECT
> '
> END FN
>
>
>
>
>
>
>
> '~MAIN
>
> ' check for OS 10.1 or later
> IF SYSTEM(_sysVers) < 1010 THEN STOP "requires OS X 10.1 or better."
>
> ' create our menus
> FN createMenus
>
>
>
> ' ----- ON EVENT HANDLERS -----
>
>
> on menu fn doMenu ' branch to doMenu when a menu selected.
> on dialog fn doDialog ' branch to doDialog for most other events
>
> ' ----------
> fn BuildWindowFromNib(1, "MyCal")
>
>
> ' ----- MAIN LOOP -----
>
> while gProgramEnds = 0
> handleevents
> wend
> end
>
>