[futurebasic] Re: key filter added to edit text button: revisited. Problems with example code.

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2004 : Group Archive : Group : All Groups

From: BrucesFB3@...
Date: Fri, 2 Jul 2004 17:42:02 EDT
Hi All,

I hate to be repetitive, but since Appearance Button Text Edit controls are 
the wave of the future, I want to learn how to use them. But so little source 
material is available. I am grateful to Brian S. for reposting the example code 
written by Robert P.   But, I can't get it to run, at least not properly. I 
made the following 3 changes in the code and finally got it to run, but type 
any key, numbers included, and the program "quits unexpectedly."   Lines 28 and 
46 are marked for reference. (More below the example). I am running OS 10.2.6

Changes:   Restore underscores to constants
               Line 28:   missing ¬ character
               Line 46 : ASC("0") and ASC("9") needed since ch is a numeric 
value. Was just "0" and "9"

'~'A
'                        Runtime : Rntm Appearance.Incl
'~'B
/*
A key filter proc applied to an EditText control.
The same technique works for an EditUnicodeText control.
Robert P.   11 June 2003
*/
#define EventModifiers as UInt16
 cmdKeyBit = 8

local fn InstallNumFilter( btnNum as long )
'~'1
begin globals
dim as proc   @ sFilter // 'static' var
end globals

long if ( sFilter == 0 )
sFilter = fn NewControlKeyFilterUPP( [proc "MyNumFilterProc" + ¬    // LINE 
28
FBprocToProcPtrOffset] )
end if
def SetButtonData( btnNum,   _kControlEditTextPart, ¬
      _kControlEditTextKeyFilterTag, sizeof( proc ), @sFilter )
end fn

long if 0                              // LINE 35
"MyNumFilterProc"
enterproc fn MyNumFilterProc( c as ControlRef, keyCode as ^SInt16, ¬
               charCode as ^SInt16, modifiers as ^EventModifiers )
'~'1
dim as SInt16   result, ch

long if ( modifiers.nil% and   cmdKeyBit% ) // command key
result =   _kControlkeyFilterPassKey
xelse
ch = charCode.nil%
select case
case ( ch == 8 ) // delete
result =   _kControlKeyFilterPassKey
case ( ch >=   asc("0") ) and ( ch <=   asc("9") ) // numeric       LINE 46
result =   _kControlKeyFilterPassKey
case else
result =   _kControlKeyFilterBlockKey
end select
end if
end fn = result
end if

local mode
local fn BuildWindow
'~'1
dim as Rect     r

appearance window 1, "Numeric Filter"
SetRect( r, 20, 90, 480, 106 )
appearance button 1,,,,,, @r,   _kControlEditTextProc
fn InstallNumFilter( 1 )
def SetButtonFocus( 1 )

end fn

// Main program
'~'1
gFBEditSelectAll =   zTrue
edit menu 2
fn BuildWindow
do
HandleEvents
until 0

I have some other questions about this example:

1. In the filter fn, why are the parameters dimmed as SINT16? In a similar 
procedure in Password +key filter demo (from Examples on Release 7), they are 
dimmed as SHORT. BTW, that demo does not crash. 

2. What is Unicode, and for that matter inline I/P? Password I understand, I  
 think. :)

3. Since this Text Edit control is going to be a prominent feature now, it 
seems to me that the topic should be worth a chapter or two in future editions 
of Switching to FutureBasic by Staz. At the least shouldn't it be worth 
multiple examples or demos?

4. What purpose does the LONG IF 0 serve? LINE 35   above. Is this to prevent 
running the procedure before needed?

Bruce Gottshall


--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...