shatara@univse.dec.com (09/08/88)
I have been having a problem with TML PASCAL and have not had much luck
getting any answers from TML directly. Can someone out there help?
I'm having a problem generating a Stop alert by following the TML Pascal
examples given in the "Programmer's Introduction to the IIgs", pp 429-431. I
have followed the examples very closely, but the "TYPE" definition of the
Alert Template was not shown. I am therfore not sure whether or not the
problem is with TML Pascal or with my implementation. I suspect the latter
at this time.
I have attached the code I have written. I'm sure the problem is a trivial
one but I can't seem to locate it.
The code compiles ok but when I run it I get
The Alert Box with the "STOP ICON"
NO message and NO Cancel Button.
System hung....can't move on but can get to conrtol panel.
The source code follows.
Thanks in advance for any help you can shed on my problem.
Chris Shatara
type
ItemTempPtr = ^ItemTemplate;
ItemTemplate = record
ItemId : integer;
ItemRect : Rect;
ItemType : integer;
ItemDesc : ptr;
ItemValue : integer;
ItemFlag : integer;
ItemColor : ptr;
end;
AlertTempPtr = ^AlertTemplate;
AlertTemplate = record
AtRect : rect;
AtAlertId : integer;
AtStage1 : byte;
AtStage2 : byte;
AtStage3 : byte;
AtStage4 : byte;
AtItem1 : ItemTempPtr;
AtItem2 : ItemTempPtr;
AtItem3 : ptr;
end;
{********************************************************************}
{ Procedure: MakeATemplate }
{********************************************************************}
Procedure MakeATemplate(TheTemplate : AlertTempPtr; TheStr : StringPtr)
var
CurrentItem1 : ItemTemplate;
CurrentItem2 : ItemTemplate;
begin
With TheTemplate^ do begin
SetRect(AtRect,120,30,520,80);
AtAlertId := 1500;
AtStage1 := $80;
AtStage2 := $80;
AtStage3 := $80;
AtStage4 := $80;
AtItem1 := @CurrentItem1;
AtItem2 := @CurrentItem2;
AtItem3 := nil;
end;
With CurrentItem1 do begin
ItemId := 1;
SetRect(ItemRect,320,25,0,0);
ItemType := ButtonType;
ItemDesc := @'Cancel';
ItemValue := 0;
ItemFlag := 0;
ItemColor := nil;
end;
With CurrentItem2 do begin
ItemId := 2;
SetRect(ItemRect,71,11,400,21);
ItemType := StatTextItem;
ItemDesc := @TheStr;
ItemValue := 0;
ItemFlag := 0;
ItemColor := nil;
end;
end;
{********************************************************************}
{ Procedure: FileNotOpen }
{********************************************************************}
Procedure FileNotOpen;
Var
NoFileOpen : AlertTemplate;
DescString : str255;
ItenClicked : integer
begin
DescString := 'You have not OPENED a file yet!';
MakeATemplate(@NoFileOpen,@DescString);
ItemClicked := StopAlert(@NoFileOpen,nil);
end;keith@Apple.COM (Keith Rollin) (09/08/88)
In article <8809081422.AA20731@decwrl.dec.com> shatara@univse.dec.com writes: >I have been having a problem with TML PASCAL and have not had much luck >getting any answers from TML directly. Can someone out there help? > >I'm having a problem generating a Stop alert by following the TML Pascal >examples given in the "Programmer's Introduction to the IIgs", pp 429-431. I >have followed the examples very closely, but the "TYPE" definition of the >Alert Template was not shown. I am therfore not sure whether or not the >problem is with TML Pascal or with my implementation. I suspect the latter >at this time. > I think I see the problem. You are creating an Alert Template that uses Alert items that you defined locally in a procedure. Pascal creates it's local variable storage space on the stack. When the procedure is done, the stack is cleaned up, and the variables go away. This means that your Alert Items are no longer in the stack proper. However, the Alert Template still points to the location on the stack where they were. When you call StopAlert, a lot of other stuff gets put on the stack (return addresses, parameters to tools, etc.) which overwrites your Alert Items. Since there is now garbage on the stack where the Dialog Manager thinks there is a valid Alert Item, the Dialog Manager chokes and hangs (wow! I mixed my metaphors, but still made sense!). Keith Rollin amdahl\ Developer Technical Support pyramid!sun !apple!keith Apple Computer decwrl/ "You can do what you want to me, but leave my computer alone!"