[comp.sys.mac.programmer] NeedHelpWithNumfilter

jkeegan@hawk.ulowell.edu (Jeff Keegan) (04/18/89)

As of recently I have started to do my Mac programming using Lightspeed C
(I formerly was using Lightspeed Pascal). In writing a program recently
I have run into a problem that I can't seem to solve on my own.
I want to create a dialog box (done), read it in and display it (done),
and call ModalDialog with a function called "numFilter" as the filter
procedure. I've managed to get it to work as far as running the filter
routine every time. That's no problem. What I am having trouble with is
determining when I'm in which editable text field (I want one field only
(out of three) to allow only numbers. The others should allow text).
I have done this successfully in the past using pascal, however I'm having
trouble for some reason still.

What I did in the past was take the DialogPtr, set a DialogPeek equal to
a typecase of the DialogPtr, and just look at the DialogPeek.editField
field (which is one less than the current text field if I remember
correctly). I've stepped through with the debugger to check the value of
this field constantly at different times throughout the program.
It comes up 7 (because the cursor is in space 8) all the way until I hit
the filter routine. Once inside there it's usually around 29,000 (garbage).
I've tripple checked the numfilter call.. It's something like

   Boolean numFilter (thediag,theevent,itemH)
   DialogPtr thediag;
   EventRecord *theevent;
   Handle *itemH;

I have checked in the only C/Macintosh book I have lying around (not with
me at the moment) and have the function declared exactly as it says to
(what I just typed above, if I remember correctly).

The only thing that I can think is that maybe since the system is doing the
call, it doesn't put all of the DialogPeek on the stack when calling 
numFilter, and that's why my typecast is failing miserably.
I'm not sure but I THINK the DialogPtr part of the newly typecasted value is
correct, and just the extra is incorrect (which would go with my theory).
This is just like the WindowPeek problem.

My question is this: How can I get it to work? If the system (or Lightspeed)
IS only giving me the DialogPtr (sized) section, how can I retrieve the rest
if the information I need?

I'd appreciate any replies, especially via direct mail (though replying
on the net is more appropriate).


Thank you.

.....Jeff Keegan	jkeegan@hawk.ulowell.edu
Undergraduate, University of Lowell

maymudes@husc4.UUCP (David Maymudes,,,4982298) (04/19/89)

From article <12863@swan.ulowell.edu>, by jkeegan@hawk.ulowell.edu (Jeff Keegan):
> 
> As of recently I have started to do my Mac programming using Lightspeed C
> (I formerly was using Lightspeed Pascal). In writing a program recently
> I have run into a problem that I can't seem to solve on my own.
> I want to create a dialog box (done), read it in and display it (done),
> and call ModalDialog with a function called "numFilter" as the filter
> procedure. I've managed to get it to work as far as running the filter
> routine every time.  [...]
> I've tripple checked the numfilter call.. It's something like
> 
>    Boolean numFilter (thediag,theevent,itemH)
>    DialogPtr thediag;
>    EventRecord *theevent;
>    Handle *itemH;
> 
Quite possibly, this should be declared as:

     pascal Boolean numFilter (thediag,theevent,itemH)
     ^^^^^^

LightSpeed C uses this convention to say that the function should use Pascal
calling conventions, required for any function called by the Toolbox.

I don't know what method other brands of Macintosh C use for this; the book
referred to in the original article may have been written with some other in
mind.
						--David Maymudes


						--David Maymudes

maymudes%husc4@harvard.ARPA	maymudes@husc4.harvard.edu
maymudes@husc4.UUCP		maymudes@HARVUNXU.BITNET
..{seismo, harpo, ihnp4, linus, allegra, ut-sally}!harvard!husc4!maymudes
davidm@harvarda.BITNET