[comp.sys.mac.programmer] Can I modify the Text Window title in THINK Pascal?

bmyers@garnet.berkeley.edu (Brian Myers) (10/09/90)

The following simple program does not work (in THINK's Lightspeed Pascal):

program ChangeTitle;
var
	wPtr: WindowPtr;
	theTitle: Str255;
begin
	ShowText;			{makes TextWindow visible, active}
	wPtr:=FrontWindow;		{should give handle to Text Window}
	GetWTitle(wPtr, theTitle);	{should retrieve title string}
	WriteLn(theTitle);		{should display title string}
end.

What actually happens is a string of garbage appears as output from that last
WriteLn.  SetWTitle also has no effect--this program was what I tried when I
couldn't make SetWTitle work.

I now suspect that THINK Pascal somehow protects its standard windows (Text,
Drawing, etc) from your own programs as they run.  Might the compiler
somehow remove these windows, even though they exist on the screen, from the
system queue?  Is that even possible?  Or why else am I getting garbage?

Thanks for any help.

---------------------------------------------------------------------------
Brian Myers					 bmyers@garnet.berkeley.edu

stevec@Apple.COM (Steve Christensen) (10/09/90)

bmyers@garnet.berkeley.edu (Brian Myers) writes:
>The following simple program does not work (in THINK's Lightspeed Pascal):
>
>program ChangeTitle;
>var
>	wPtr: WindowPtr;
>	theTitle: Str255;
>begin
>	ShowText;			{makes TextWindow visible, active}
>	wPtr:=FrontWindow;		{should give handle to Text Window}
>	GetWTitle(wPtr, theTitle);	{should retrieve title string}
>	WriteLn(theTitle);		{should display title string}
>end.
>
>What actually happens is a string of garbage appears as output from that last
>WriteLn.  SetWTitle also has no effect--this program was what I tried when I
>couldn't make SetWTitle work.
>
>I now suspect that THINK Pascal somehow protects its standard windows (Text,
>Drawing, etc) from your own programs as they run.  Might the compiler
>somehow remove these windows, even though they exist on the screen, from the
>system queue?  Is that even possible?  Or why else am I getting garbage?

Have you thought about initializing theTitle with something.  Otherwise,
whatever was in that part of memory when your routine got called would
be used.  Stuff like: theTitle:='A Real Title' or theTitle:=GetString(5)^^
work pretty well...  :-)

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 whoami?     Steve Christensen
 snail:      Apple Computer, 20525 Mariani Ave, MS-81CS, Cupertino, CA  95014
 Internet:   stevec@goofy.apple.com
 AppleLink:  stevec
 CompuServe: 76174,1712

mxmora@unix.SRI.COM (Matt Mora) (10/10/90)

In article <10623@goofy.Apple.COM> stevec@Apple.COM (Steve Christensen) writes:
>bmyers@garnet.berkeley.edu (Brian Myers) writes:
>>The following simple program does not work (in THINK's Lightspeed Pascal):
>
>Have you thought about initializing theTitle with something.  Otherwise,
>whatever was in that part of memory when your routine got called would
>be used.  Stuff like: theTitle:='A Real Title' or theTitle:=GetString(5)^^
>work pretty well...  :-)

I don't think that is the will help. I believe that THINK Pascal mucks
around with the window list (or creates its own) so that the front window
command will work even if the front window is the source code or Lightsbug
window. For example if you are tracing code execution, if your code calls
frontwindow and the source code window is actually in front, frontwindow
will return a ptr to your window not the source code window.


If I get time I'll look into it. Sorry I dont have an answer.



>steve
>
>-- 
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> whoami?     Steve Christensen





-- 
___________________________________________________________
Matthew Mora                |   my Mac  Matt_Mora@sri.com
SRI International           |  my unix  mxmora@unix.sri.com
___________________________________________________________

smoke@well.sf.ca.us (Nicholas Jackiw) (10/11/90)

In article <1990Oct9.062443.18141@agate.berkeley.edu> bmyers@garnet.berkeley.edu (Brian Myers) writes:
>The following simple program does not work (in THINK's Lightspeed Pascal):
>
>	ShowText;			{makes TextWindow visible, active}
>	wPtr:=FrontWindow;		{should give handle to Text Window}
>	GetWTitle(wPtr, theTitle);	{should retrieve title string}
>	WriteLn(theTitle);		{should display title string}
>I now suspect that THINK Pascal somehow protects its standard windows (Text,
>Drawing, etc) from your own programs as they run.  Might the compiler
>somehow remove these windows, even though they exist on the screen, from the
>system queue?  Is that even possible?  Or why else am I getting garbage?

That's right and that's possible.

THINK Pascal patches FrontWindow so that it never returns one of the
(internal) windows--e. g. the Text window, the Lightsbug window, a
source code window, etc.

Whether this patch is installed only when running "under the environment"
is unclear to me.  Regardless, if you're trying to work under the environment,
it's in effect. 

That's why you'll want to go to the WindowList constant,  which is not
accessed through a (potentially patchable) trap, as you mentioned in
your last post.  Or you could ignore your aversion to the title TEXT.



-- 
                              --- * ---
Nicholas Jackiw                Smoke@well.sf.ca.us | Jackiw@cs.swarthmore.edu
Key Curriculum Press, Inc.     Applelink: D3970    | (415) 548-2304
                              --- * ---