From 3665c36d276f7209ed09a93dc2e08d2e34a393c0 Mon Sep 17 00:00:00 2001 From: Norayr Chilingarian Date: Wed, 27 May 2015 02:56:52 +0400 Subject: [PATCH] added events example. --- src/test/events/README.md | 7 +++++ src/test/events/clb.Mod | 55 +++++++++++++++++++++++++++++++++++++++ src/test/events/makefile | 4 +++ 3 files changed, 66 insertions(+) create mode 100644 src/test/events/README.md create mode 100644 src/test/events/clb.Mod create mode 100644 src/test/events/makefile diff --git a/src/test/events/README.md b/src/test/events/README.md new file mode 100644 index 00000000..32729f67 --- /dev/null +++ b/src/test/events/README.md @@ -0,0 +1,7 @@ +**events example in oberon** + +Just a simple example which helps to explain how events are implemented, what is callback procedure, and how easy it is. + +Some languages simplify programmer's work, hide details, so that it's not obvious to him what's going on when he defines it's own OnSomething function. + +Callbacks are common when dealing with gui events like OnClick but they can be used with any events. I guess code is simple enough, it doesn't need explanation. diff --git a/src/test/events/clb.Mod b/src/test/events/clb.Mod new file mode 100644 index 00000000..218b82b7 --- /dev/null +++ b/src/test/events/clb.Mod @@ -0,0 +1,55 @@ +MODULE clb; + +IMPORT Console; + +TYPE OnSomething = PROCEDURE (x, y : INTEGER); + +PROCEDURE ProcessEvents(x, y : INTEGER; onsomething : OnSomething); + +BEGIN + +IF onsomething # NIL THEN onsomething(x, y) +ELSE + Console.String("didn't happen"); Console.Ln +END; + +END ProcessEvents; + + +PROCEDURE OnEvent(x, y : INTEGER); + +BEGIN + +Console.String("event happened"); Console.Ln + +END OnEvent; + +PROCEDURE OnEvent2(x, y : INTEGER); + +BEGIN + +Console.String("happened"); Console.Ln + +END OnEvent2; + +PROCEDURE Something; +VAR onsmth : OnSomething; + +BEGIN + + onsmth := NIL; + ProcessEvents(0, 0, onsmth); + + onsmth := OnEvent; + ProcessEvents(0, 0, onsmth); + +END Something; + +BEGIN + Something; +(* +ProcessEvents(0, 0, NIL); +ProcessEvents(0, 0, OnEvent); +ProcessEvents(0, 0, OnEvent2); +*) +END clb. diff --git a/src/test/events/makefile b/src/test/events/makefile new file mode 100644 index 00000000..b2f73828 --- /dev/null +++ b/src/test/events/makefile @@ -0,0 +1,4 @@ + + +all: + /opt/voc/bin/voc -M clb.Mod