[comp.sys.mac.programmer] THINK PASCAL's Observe not working right?!

volaski@acsu.buffalo.edu (maurice volaski) (01/13/90)

Below is a program written in THINK Pascal that performs the 
Macintosh's famous task of command-period to cancel. The programs 
loops idly until command-period is pressed and then it quits.

However, according to one aspect of THINK Pascal's debugger it 
shouldn't work. In the Lightsbug window, the variables are updated 
properly, but in the Observe window they are not. The variable temp 
is appropriately set to true when command-period is set to true, but 
the the function result CmdPeriod is not set to the value of temp!
This only occurs in the observe window, not anywhere else. 
Anyone familiar with problems like this one and others in THINK Pascal's 
Observe window? Rich Siegal, are you listening?

program testcmdperiod;
 var
  BtnUpdate: boolean;

 function CmdPeriod: boolean;
  const
   periodKey = 46;
  var
   chCode: integer;
   stopEvent: EventRecord;
   temp: boolean;
 begin
  CmdPeriod := false;
  if GetNextEvent(keyDownMask, stopEvent) then
   begin
    with stopEvent do
     begin
     if (BitAnd(modifiers, CmdKey) <> 0) and 
		(BitAnd(message, CharCodeMask) = periodKey) then
      temp := true
     else
      temp := false;
     end;
   end
  else
   temp := false;
  CmdPeriod := temp;		{This line doesn't work according to only Observe}
 end;

begin
 BtnUpdate := false;
 repeat
  begin
   ;
  end;
 until CmdPeriod;
 BtnUpdate := true;
end.

siegman@sierra.Stanford.EDU (Anthony E. Siegman) (01/13/90)

In article <15719@eerie.acsu.Buffalo.EDU> volaski@acsu.buffalo.edu (maurice volaski) writes:
>Below is a program written in THINK Pascal that performs the 
>Macintosh's famous task of command-period to cancel. The programs 
>loops idly until command-period is pressed and then it quits.

(and then follows _36 lines_ of Pascal code) (which doesn't work)

Good God!  In MS QuickBASIC you say

    ON BREAK GOSUB BreakHandler: BREAK ON

and write your BreakHandler routine, and that's it!

volaski@acsu.Buffalo.EDU (maurice volaski) (01/13/90)

In article <456@sierra.stanford.edu> siegman@sierra.UUCP (Anthony E. Siegman) writes:
>In article <15719@eerie.acsu.Buffalo.EDU> volaski@acsu.buffalo.edu (maurice volaski) writes:
>>Below is a program written in THINK Pascal that performs the 
>>Macintosh's famous task of command-period to cancel. The programs 
>>loops idly until command-period is pressed and then it quits.
>
>(and then follows _36 lines_ of Pascal code) (which doesn't work)

The code does work; it's the debugger that is at issue.

siegel@endor.harvard.edu (Rich Siegel) (01/13/90)

In article <15719@eerie.acsu.Buffalo.EDU> volaski@acsu.buffalo.edu (maurice volaski) writes:
>Below is a program written in THINK Pascal that performs the 
>Macintosh's famous task of command-period to cancel. The programs 
>loops idly until command-period is pressed and then it quits.
>
>However, according to one aspect of THINK Pascal's debugger it 
>shouldn't work. In the Lightsbug window, the variables are updated 
>properly, but in the Observe window they are not. The variable temp 
>is appropriately set to true when command-period is set to true, but 
>the the function result CmdPeriod is not set to the value of temp!
>This only occurs in the observe window, not anywhere else. 
>Anyone familiar with problems like this one and others in THINK Pascal's 
>Observe window? Rich Siegal, are you listening?

This is not a problem in Observe, or in LightsBug, or in your code.

In Observe, when you enter an expression, the compiler is called to generate
the code for the expression, and this code is then executed. If the expression
includes a function name, then that function is called. In this case, you
entered the name "CmdPeriod" in the Observe window, so the function "CmdPeriod"
got called. (When executing functions from the Observe window, stopsigns
are disregarded.) Since you weren't holding a command-Period when you
evaluated the results in the Observe window, the function (correctly)
returned FALSE.

In LightsBug, the name of the function actually does refer to the value stored
as the function's result, rather than the result of an invocation of the
function itself.

This ability of the Observe window is unique, but can sometimes be confusing.

And my name does not have an "a" in it. :-)

R.
~~~~~~~~~~~~~~~
 Rich Siegel
 Staff Software Developer
 Symantec Corporation, Language Products Group
 Internet: siegel@endor.harvard.edu
 UUCP: ..harvard!endor!siegel

"When someone who makes four hundred and fifty dollars an hour wants to
tell you something for free, it's a good idea to listen."

~~~~~~~~~~~~~~~