Simplicty and flexibility!


New Sample - How to use Timer(Event) to schedule exiting DataEase

Started by DataEase
You will need to Sign In to be able to comment on the Blog!

New Sample - How to use Timer(Event) to schedule exiting DataEase

Download Sample!



Here we will show how you can use the new Timer(Event) to take down DataEase automatically at a given time. 

Timer(Event) is an OML event so you need to use the OML editor to activate it.

There is one Timer() event for each document, but it is global and will be called 10 times a second as long as the document is open.

The Timer document is hence not dedicated to the document for which it is called. The only dependency is that the document is open, after that it will act as a global resources.

All DataEase functions talk directly to the active document, so a SetValue() or SetState() called in a document does not change the object on the document it is called from but on the Active document. In reality this is the document they are called for if the action is immediate like when it is called from a button or a derivation etc.

But for instance.

DocumentOpen("TestActiveDocument") + wait(1)+SetLabelText("RemoteText","This is set from KillTimer Document!")

will be "too late" to set it in the document from where it is called, so it will do the job in the new document. This is of course a feature that one both need to be aware of and can use to ones advantage.

The reason we mention this is that when you do these kind of actions from Timer() it will be delayed (it can be called weeks or months after the timer was started) so the likelihood that the document form where it is called is the active document is minuscule.

So if you want the functions to be executed in the document that owns the timer you need to activate this document prior to calling the functions.

For instance:

OML or DQL.
If GetCurrent("ActiveDoc") not="MyDocument") then 
retval := SetCurrent("ActiveDoc","MyDocument") .
end

This will activate an already open document (which it will have to be if the timer should work).

If you want to activate an already open document or open it if it is not already open then you use the following:

OML or DQL.

If GetCurrent("ActiveDoc") not="MyDocument") then
if GetCurrent("IsDocOpen","MyDocument") not="Yes" then
retval := DocumentOpen("MyDocument") .
else
retval := SetCurrent("ActiveDoc","MyDocument") .
end
end

We have made a small sample to illustrate how Timer() works in this instance and included some goodies using

SetCurrent()/GetCurrent()
"IsDocOpen"
"ActiveDoc"

SetStyle()
MoveObject()

etc


Written by DataEase 07/03/19 at 12:11:48 Dataease [{8}]FIVE

Re:New Sample - How to use Timer(Event) to schedule exiting DataEase

Update to Article.

In practical use you might stumble upon the problem of DataEase not being active when the timer runs out. To resolve this read on:

DataEase has a big divide between GUI functions and PRISM functions. 


GUI functions are called in the Windows GUI bit of the product and is basically WINDOWS stuff like DocumentOpen, ExitDataEase, SetValue, SetState etc.

PRISM functions are DataEase DNA and is functions that work on the data like concat,firstc, abs,random etc.

PRISM functions will always work but GUI functions is processed by the ACTIVE document!!

This is a new concept for most DataEase users that are used to sequential processing (PRISM and DFD etc).

DFW will go quite far in fooling you into believing that it is sequential too but it isn’t. It is all based around the Windows Message bus.

ALL GUI functions are sent as messages to active window and with luck you will 99.99% of the time up to 8.5 send that to the document from where they are called.

But the more advanced user would have tried something like this.

DocumentOpen(“NewDoc”)+DocumentClose()

What you want to achieve here is obviously to open a new document and close the one you are currently calling from…

Hmmm…

But you then to your big surprise find that ex. Nothing happens, or you see the new document open to quickly close again.

This is because you open a new document that then become the active document and then the message you have sent to the bus in reality only tell DataEase to close the active document, not the document you thought you wanted to close.

But this goes further. Because Active Document (or in reality Active Window) is not a DataEase thing but a Windows thing. You can only have 1 – ONE – Active document on your computer, so when you switch over to Word there is NO active document in DataEase and hence nothing can be executed in GUI!

And this lead us on to your problem.

You have only seen the problem when user minimize or lock DataEase but in reality the problem is the same if he is working in word. ExitDataEase(“Silent”) is a GUI function and need an Active Active Document in DataEase to be executed in.

Luckily for you we use our own product and features so when realising this we made a function to activate DataEase.

it is called

SetCurrent("ActivateDE") -- Activate DE environment for GUI updating.

And for those of you that want to take it one step further and control which Window/Document is active in your DE you also have
SetCurrent("ActiveDoc","DocumentName") -- Bring to front and activate Document

So the simple modification for you script to make it work 100 out of 100 times is
define "retval" text .

define "mytime" time .

define "timeleft" number .

if getvar("KillTimer") not =blank then

myTime := GetVar("KillTimer") .

timeleft := mytime - current time .

if mytime = current time then

retval := SetCurrent(“ActivateDE”)+ExitDataEase("silent") .

end

end

Good Luck!


Written by DataEase 07/03/19 at 12:11:10 Dataease [{8}]FIVE
DG3_BlogList