[futurebasic] Re: When to dispose of Hndl& and Ptr&?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 1997 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Sat, 06 Dec 1997 13:41:12 -0600
Bill Kuck wrote:
> Scope:
> 1) Create an edit field
> 2) Call FN that does something with edit field,
>    but, do not dispose of the edit field in the FN
> 3) Dispose of the edit field
> '------------------
> LOCAL FN doSomething(efID%)
>   efHndl& = TEHANDLE(efID%)   'create a temp handle to ef
>   efFont% = efHndl&..teFont%  'get the font, we're done
> ' Notes about exiting FN:
> ' handle efHndl& lost, but ok, edit field still intack
> ' if DEF DISPOSEH(efHndl&) were used in the above, we
> ' would have lost the edit field, right?
> "Main"
> WINDOW 1                      'create window
> TEXT _monaco,9
> EDIT FIELD 1,"",(5,5)-(20,20) 'create edit field
> FN doSomething(1)             'get font
> WINDOW CLOSE 1                'close window, edit field

You've got it exactly right, Bill.  Many of us (certainly including
myself) get into the habit of using the word "handle" to variously mean:
the value of the handle (i.e., the long int. number), the variable that
holds the handle's value, and the relocatable data block that the handle
refers to.  This is a poor habit if you're trying to explain the handle
concept to somebody else.  Even Apple is sometimes guilty of this: for
example, FN GetHandleSize doesn't get the _handle's_ size (which is
always 4 bytes); it gets the size of the block that's referenced by the
handle.  And FN DisposHandle doesn't just dispose of the _handle_, it
also disposes of the _block_.

- Rick