Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

While reviewing the code for WindowResizerClass (in an attempt to get more agreeable resizing behavior for ClarionTest) I came across a usage of RegisterEvent that I hadn't noticed before:

...

But RegisterEvent is part of the Clarion runtime, and it's smart enough to handle a method if that's what you throw at it. 

Here's a small sample program to demonstrate:

Code Block
                                            PROGRAM
                                            MAP
                                            END

EventQueue                                  queue,type
EventTime                                       long
                                            end

EventHandler                                class
EventQ                                          &EventQueue
Construct                                       procedure
Destruct                                        procedure
TakeEvent                                       procedure,byte
                                            end

Window                                      WINDOW('Timer event callback'),AT(,,177,129),GRAY,FONT('Microsoft Sans Serif',8), |
                                                TIMER(100)
                                                LIST,AT(3,2,171,124),USE(?LIST1),VSCROLL,FROM(EventHandler.EventQ), |
                                                    FORMAT('20L(2)|M@t4@')
                                            END
    CODE
    open(window)
    accept
        case event()
        of EVENT:OpenWindow
            RegisterEvent(event:timer,address(EventHandler.TakeEvent),address(EventHandler))
        end
    end
    UnRegisterEvent(event:timer,address(EventHandler.TakeEvent),address(EventHandler))
    close(window)
    
EventHandler.Construct                      procedure
    code
    self.EventQ &= new EventQueue
    
EventHandler.Destruct                       procedure
    code
    free(self.EventQ)
    dispose(self.EventQ)
    
EventHandler.TakeEvent                      procedure
    code
    self.EventQ.EventTime = clock()
    add(self.EventQ,-self.EventQ.EventTime)
    return level:benign

...

The return value can be one of the following:

Level:Benign

Calls any other handlers and the ACCEPT loop, if available.

Level:Notify

Doesn't call other handlers or the ACCEPT loop. This is like executing CYCLE when processing the event in an ACCEPT loop.

Level:Fatal

 Doesn't call other handlers or the ACCEPT loop. This is like executing BREAK when processing the event in an ACCEPT loop.

On further experimentation I found that I could reduce the program code to just four lines:

...