[comp.sys.mac.programmer] @ Operator & Keydown events in Think Pascal?

mebhl@cc.nu.oz.au (11/02/90)

I have a problem with the @ Operator in THINK Pascal 3.0.

MacTutor April 1990 has a project to create editable lists & other dialog
user items, written by David Wilcox. In his keyboard unit, he borrows some
functions from MacTutor, May 1988, to test for various keydown events.

The crucial function has the form:

   function TestKey (i: longint): boolean;
      var
         myKeys: keyMap;
   begin
      GetKeys(myKeys);
      TestKey := BitTst(@myKeys[1], i)
   end;

When this is run, THINK Pascal tells me that:

   @ can't be applied to a component of a packed type.

Fair enough, I can accept this (after looking at the manual and IM).

But the code obviously used to work. What's changed, and what can I change
get it to work again? Or am I missing something obvious?

Any help greatly appreciated.
__________
Peter Lewis                    mebhl@cc.nu.oz.au
Mech. Eng.
University of Newcastle
NSW    2308    AUSTRALIA

rsfinn@athena.mit.edu (Russell S. Finn) (11/03/90)

In article <3234.27315d8c@cc.nu.oz.au> mebhl@cc.nu.oz.au writes:
>The crucial function has the form:
>
>   function TestKey (i: longint): boolean;
>      var
>         myKeys: keyMap;
>   begin
>      GetKeys(myKeys);
>      TestKey := BitTst(@myKeys[1], i)
>   end;
>
>When this is run, THINK Pascal tells me that:
>
>   @ can't be applied to a component of a packed type.

Right, because KeyMap is defined as PACKED ARRAY[0..127] OF BOOLEAN.

>But the code obviously used to work. What's changed, and what can I change
>get it to work again? 

In versions of THINK Pascal earlier than 3.0, PACKED ARRAY OF BOOLEAN
was not implemented, and so KeyMap had to be defined as PACKED
ARRAY[0..3] OF LONGINT instead.  This required the circumlocution
described above.  

Since version 3.01, PACKED ARRAY OF BOOLEAN is supported correctly,
and you can now just say

	TestKey := myKeys[keyCode]

where keyCode is the code of the desired key (see the Event Manager
chapter of Inside Macintosh).

Note that if you're just interested in modifier keys, you can simply
call GetNextEvent and examine the modifier field of the EventRecord,
even if GetNextEvent returned FALSE (as someone has previously pointed
out).  Of course, this works for WaitNextEvent also.

-- Russ
rsfinn@{athena,lcs}.mit.edu

Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) (11/06/90)

> The crucial function has the form:
> 
>    function TestKey (i: longint): boolean;
>       var
>          myKeys: keyMap;
>    begin
>       GetKeys(myKeys);
>       TestKey := BitTst(@myKeys[1], i)
>    end;
> 
> When this is run, THINK Pascal tells me that:
> 
>    @ can't be applied to a component of a packed type.
> 
> Fair enough, I can accept this (after looking at the manual and IM).
> 
> But the code obviously used to work. What's changed, and what can I change
> get it to work again? Or am I missing something obvious?

I don't know what's changed.  Mchanges in the way that THINK Pascal stores packed structures since
version 2.  Anyhoo, since you are just testing the second most significant
bit of myKeys, why not just cast mykeys to an array of 4 longs ans then
test it?

 

--  
Uucp: ...{gatech,ames,rutgers}!ncar!asuvax!stjhmc!56.12!Chris.Gehlker
Internet: Chris.Gehlker@p12.f56.n114.z1.fidonet.org

siegel@endor.uucp (Rich Siegel) (11/09/90)

In article <29660.27364102@stjhmc.fidonet.org> Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) writes:

>>       GetKeys(myKeys);
>>       TestKey := BitTst(@myKeys[1], i)

	Inside Mac defines a KeyMap as a packed array of [0..127] of Boolean.
Since versions of THINK Pascal prior to 3.0 didn't support bit-packing, this
type was redefined to be an array[0..3] of LongInt. Since 3.0 supports 
bit-packing, the definition was changed back to conform with Inside Mac. To
test the i'th key, just say:

	GetKeys(myKeys);
	TestKey := myKeys[i];

R.



 Rich Siegel	Software Engineer	Symantec Languages Group
 Internet: siegel@endor.harvard.edu	UUCP: ..harvard!endor!siegel

If you have telekinetic powers, raise my hand.