MAPHANDLE

maphandle #oldHandle, #newHandle

maphandle #oldHandle, "#newHandle"

Description:

Maphandle assigns a new handle to a device after it is open. Now it is possible to reuse code that is used to open windows, files, etc. For example a window can be opened as follows:

  open "Maphandle example" for window as #renameMe

Once this window is open, the code cannot execute this line again because the handle #renameMe is in use by that window. Opening another one is not allowed because a given handle can only be in use by one device at a time.

The maphandle command provides a way around this problem. You can change the handle of the window after you open it.

Usage:

Maphandle Examples

  maphandle #renameMe, #newHandle
  maphandle #renameMe, "#newHandle"
  a$ = "#new" + "Handle"
  maphandle #renameMe, a$

With this example you see how to create handles dynamically on the fly if desired:

  winName$ = "first second third"
  for x = 1 to 3
    call createWindow word$(winName$, x)
  next x
  wait

sub createWindow title$
  texteditor #1.te, 10, 10, 200, 200
  open "text "+title$ for window as #1
  #1.te "this is the "+title$+" window"
  #1 "trapclose aboutToClose"
  handle$ = "#"+title$
  maphandle #1, handle$
end sub

sub aboutToClose handle$
  confirm "Close "+handle$+"?"; answer
  if answer = 1 then close #handle$
end sub

The old way

Here is the old way of opening three windows without using maphandle and variable handles. In some ways this is easier to read, but it is a lot more code, and you can only open another window by adding a lot more code.

  texteditor #1.te, 10, 10, 200, 200
  open "text first" for window as #1
  #1.te "this is the first window"
  #1 "trapclose [aboutToClose1]"
  texteditor #2.te, 10, 10, 200, 200
  open "text second" for window as #2
  #2.te "this is the second window"
  #2 "trapclose [aboutToClose2]"
  texteditor #3.te, 10, 10, 200, 200
  open "text third" for window as #3
  #3.te "this is the third window"
  #3 "trapclose [aboutToClose3]"
  wait

[aboutToClose1]
  confirm "Close first?"; answer
  if answer = 1 then close #1
  wait

[aboutToClose2]
  confirm "Close second?"; answer
  if answer = 1 then close #2
  wait

[aboutToClose3]
  confirm "Close third?"; answer
  if answer = 1 then close #3
  wait