Κυριακή 15 Μαρτίου 2020

Open a form after closing from unload button

This is an example of how we use a form, here with a handler as SIMPLE, to pass it to three modules, Inner, Inner1 and Inner2. Each module open the form, and when we close it using the unload button on the header of the form we make a fake unload using the Unload event, which handle the visible property to hide the form.

The Inner module get a copy of the window handler. This copy can't be used to make a linked property.

Why that happen ? Is the way M2000 interpreter internal window manager work. Only one real reference to a form exist. This means that when the module CheckIt exit, this reference released, and the form unloaded. The same done when we place a Nothing. When we click on unload button, an unload happen except we cancel it using the true as value to the first by reference variable at unload event. All events called in the same module we make the form and they have the name of the declaration, here the SIMPLE, here the simple.unload function is the service routine for the event. The call is a local type, which means that inside code in function Sumple.Unload we have the visibility of module checkit, so we can see the visible property.

So in Inner module we open the form as modal, using the m2000 internal window manager for modal windows. When we click on unload button, the modal loop exit, but the form not unload, but hide.

When we call the Inner1 we pass the Simple by reference, so we can make a visible property. Now we use a simple loop on visible property to make it like a modal (but a modal type to show also lock the under the form forms).

When we call the Inner2 we pass the Simple and the Visible both by reference.

Although the name of form inside Inner, Inner1 and Inner2 is That, the actual form has the name Simple and a prefix, as a weak reference to use it to call events. Also has a list for those events that aren't servising. This list erased and make it again if the form loose the focus.

If we make a fault in code, the module's stop working and all the variables erased, so the form unload, because the form's handler always is one. The visible property never hold a reference to form, but a reference to where Simple reference, the real reference which is only one.


Module CheckIt {
      \\ Simple is a first class object
      Declare Simple Form
      \\ we can define form before open
      Layer Simple {
            \\ center Window with 12pt font, 12000 twips width and 6000 twips height
            \\ ; at the end command to center the form in current screen
            Window 12, 12000, 6000;
            \\ make layer gray and split screen 0
            Cls #333333, 0
            \\   set split screen to 3rd line, like Cls ,2 without clear screen
            Scroll Split 2
            Cursor 0, 2
      }
      With Simple, "Title", "Hello Form", "visible" as visible
      \\ Without handling the unload event, a form unload for good
      \\ So we have to cancel the unload event and make the form non visible
      Function Simple.Unload {
            Read New &cancel
            visible=False
            cancel=true
      }
      Function Simple.Click {
            Layer Simple {
                  \\ open msgbox
                  Print Ask("Hello World")
                  Refresh
            }
      }
      Module Inner (That) {
            \\ open as modal  - also we handle the Unload event
            Method That, "Show", 1
      }
      Module Inner1 (&That) {
            \\ we can produce a linked property if we pass by reference
            \\ so &That make That same as Simple
            \\ if we pass by value we get an error "Can't Get Property"
            With That, "visible" as visible
            Method That, "Show"
            do
                  wait 1
            until not visible
      }
      Module Inner2 (&That, &thatToo) {
            Method That, "Show"
            do
                  wait 1
            until not thatToo
      }
      Inner Simple
      wait 1000
      Print "ok"

      Refresh
      Inner1 &Simple
      wait 1000
      Print "ok"

      Refresh
      Inner2 &Simple, &visible
      \\ now form deleted
      \\ Make the Simple as Nothing the form unloaded if not unloaded,
      \\ without an unload event.
      Declare Simple Nothing
}
CheckIt

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.