Ok I am writing a program that needs to have 6 different types of "windows" that open up, and a large number of each. I am trying to avoid assigning a unique handle to each gadget, and so I am using a global variable that I am incrementing each time I create a parent gadget window to define that gadget's handle. So far so good, I can open a virtually unlimited number of windows. The problem occurs when I put a deleteGadget call in my program... at all. Even when it isn't called by the program yet, it crashes. I really don't want to just hide the open windows and would rather delete them, but I can't figure out why just putting deleteGadget in my program causes it to crash (Rather it prematurely ends with no error messages as soon as it finishes loading) Yes I do have the gui include in the program. Here are the code snippets that invole the creating of the windows and the closing of them as well as the main loop.
Main Loop:
do
`Retrieve information about events
getEvent
source = eventSource()
if eventType()=MOUSE_CLICK
if source = But_FindTool
Find_Tool()
endif
if source = But_FindKit
Find_Kit()
endif
if source = But_AddTool
Add_Tool()
endif
if source = But_AddKit
Add_Kit()
endif
if source = But_EditTool
Edit_Tool()
endif
if source = But_EditKit
Edit_Kit()
endif
endif
rem End Program or Close Open Window
if eventType()=WINDOW_CLOSE
if source=mainWin then end
else
CloseWindow(source)
endif
loop
Open/Close Windows:
function CloseWindow(source)
` Close the selected window and set it's gadget data to 0
sourceID = source
sourceID = deleteGadget(sourceID)
endfunction
function OpenWindow(kind,windowID)
` Opens a tool window. The variable "kind" determines which window type to open and the variable winID declares the handle.
select kind
case 1 `Find Tool Window
`Set up the handles for the gadgets
global Pan_ToolNum
global Pan_ToolLoc
global Pan_ToolDescrip
global Can_ToolPic
Pan_ToolNum = (ToolNumPan + windowID)
Pan_ToolLoc = (ToolLocPan + windowID)
Pan_ToolDescrip = (ToolDescripPan + windowID)
Can_ToolPic = (ToolPicPan + windowID)
`Set the found tool window up.
windowID=createWindow(100,100,500,500,"Found Tool!",WINDOW_FIXED,0,0,0)
Pan_ToolNum=createPanel(0,0,100,20,windowID)
Pan_ToolLoc=createPanel(100,0,100,20,windowID)
Pan_ToolDescrip=createPanel(200,0,300,20,windowID)
Pan_ToolPic=createPanel(0,20,500,480,windowID)
setPanelBorderStyle Pan_ToolNum, 2
setPanelBorderStyle Pan_ToolLoc, 2
setPanelBorderStyle Pan_ToolDescrip, 2
setGadgetText Pan_ToolNum,CurrentTool$
setGadgetText Pan_ToolLoc,CurrentToolLoc$
setGadgetText Pan_ToolDescrip,CurrentToolDescrip$
`Paint the picture of the tool onto the canvas
load image (CurrentTool$ + ".jpg"),1,1
setPanelImage Pan_ToolPic,1
`setCanvasImage(Can_ToolPic,1,1)
endcase
case 2 `Find Kit Window
endcase
case 3 `Add Tool Window
endcase
case 4 `Add Kit Window
endcase
case 5 `Edit Tool Window
endcase
case 6 `Edit Kit Window
endcase
endselect
endfunction
Function that calls CloseWindow(source):
function Find_Tool()
tool_num_$ = GetGadgetText(Edit_FindTool)
tool_num_$ = tool_num(tool_num_$)
SetGadgetText Edit_FindTool,tool_num_$
WindowsOpened = WindowsOpened + 1
CurrentTool$ = tool_num_$
windowID = WindowsOpened
OpenWindow(1,windowID)
endfunction
Most of the variables used are globals, and everything works just fine until I put the deleteGadget line. Any help would be greatly appreciated.