- A Cookbook Topic: "Delay", "WaitUntil" and "Let's see actions"

From: [at]} <Alexander>
Date: Sat, 6 May 2006 00:52:33 +0700

----boundary-LibPST-iamunique-1917831363_-_-
Content-type: text/plain

Hello, koend!

k> Hello Helmut,
k> I have attached a possible solution for this problem. It is pure WinApi, however...

k> Set global var 'done' to False
k> Set up a windows timer that triggers after the requested delay
k> Take over the BlackBox messageloop, until 'done' is true
k> After 'delay", Timerproc sets 'done' to TRUE
k>
k> It works smoothly, but there is room for improvement: keyboard accelerators like F1 and MDI
k> shortcuts like Ctrl-Tab to switch windows don't work during
k> 'delay'. I know how to solve this, but
k> have to look it up.

  You are absolutely right, your solution does work.
  But it should be considered that the module may be unloaded while
  the Delay is still running. This leads to "illegal execution" trap.
  Some protection is obviously required here.

  Another problem is that background services are not working during
  this kind of Delay either. And if you type something during Delay,
  you won't see new characters until the view gets updated or delay is
  over.

  If you modify the xyBoss5.Done procedure this way:

  PROCEDURE Done(wnd: USER32.Handle; message, wPar, lPar: INTEGER): INTEGER;
  BEGIN
    done := TRUE;
    StdLog.String('done!'); (* let's see, what we've done... *)
    StdLog.Ln;
    RETURN 1
  END Done;

  We'll see that timers keep on ticking, never stopped. So, if you
  call xyBoss5.Delay twice, you'll get two timers in the background.
  When you call xyBoss5.Delay third time, the delay won't actually be
  equal to the given parameter, because procedure Done will be called
  whenever any of the three timers fire.

  But that's not the point. I understand, that the given hack is quick
  and dirty, given just to illustrate the principle. And the principle
  is good.


  
To Helmut Zinn:
  
  The real problem here is that BlackBox doesn't support multitasking.
  What you are trying to do is suspend a task for some time while the
  rest of the BlackBox keeps on living. This is simply not supported.

  This would require re-entering HostMenus.Loop somehow, and then
  leaving it after some time. No such mechanism exist, because
  HostMenus.Loop procedure is not even published.

  If you would like to imitate HostMenus.Loop by just copying it into
  your function, you will need to copy all non-published functions
  from HostMenus module which it calls (like CheckFpu,
  TranslateAccelerators etc.)

  Another way - for machos only - is to modify HostMenus.Loop to make
  it return execution after given time (or when a certain time point
  is reached) and publish it. This would lead to module interface
  change, which would lead to total recompilation of BlackBox's kernel.
  This is not impossible, I must say.

  It's a pity that such great non-modal user interface turns out to be
  so modal to its different tasks. You either grab total control over
  application or must release it and hope it will remember about you
  after some time. Nothing in-between. I think it shouldn't be that
  way in a message-driven application.

  If user entered menu loop (walking around the main menu or just
  popped up a context menu and didn't close it), all background
  and "delayed" tasks will wait indefinitely.

  For example, Delphi has Application.HandleMessage and
  Application.ProcessMessages methods which make things like Delay
  easy to implement. Nothing like that I've found in BlackBox.
  Again, this is not impossible to do, but will lead to total
  recompilation and incompatibility.

  There is not even a good waiting sequence to implement, which I keep
  complaining about. If you need to track mouse movements, you will
  load CPU up to 100% and nothing will move in the background. You
  cannot go idle until mouse movement event occurs, you must keep
  asking for its coordinates until a button is released. That's awful,
  but that's what BlackBox do everywhere.
  
---=====---
 Alexander

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-1917831363_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhlbGxvLCBrb2VuZCFccGFyDQpccGFyDQprPiBI
ZWxsbyBIZWxtdXQsXHBhcg0Kaz4gSSBoYXZlIGF0dGFjaGVkIGEgcG9zc2libGUgc29sdXRpb24g
Zm9yIHRoa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gbmVlZCB0byB0cmFjayBtb3VzZSBtb3ZlbWVudHMs
IHlvdSB3aWxsXHBhcg0KICBsb2FkIENQVSB1cCB0byAxMDAlIGFuZCBub3RoaW5nIHdpbGwgbW92
ZSBpbiB0aGUgYmFja2dyb3VuZC4gWW91XHBhcg0KICBjYW5ub3QgZ28gaWRsZSB1bnRpbCBtb3Vz
ZSBtb3ZlbWVudCBldmVudCBvY2N1cnMsIHlvdSBtdXN0IGtlZXBccGFyDQogIGFza2luZyBmb3Ig
aXRzIGNvb3JkaW5hdGVzIHVudGlsIGEgYnV0dG9uIGlzIHJlbGVhc2VkLiBUaGF0J3MgYXdmdWws
XHBhcg0KICBidXQgdGhhdCdzIHdoYXQgQmxhY2tCb3ggZG8gZXZlcnl3aGVyZS5ccGFyDQogIFxw
YXINCi0tLT09PT09LS0tXHBhcg0KIEFsZXhhbmRlclxwYXINClxwYXINCi0tLSBCbGFja0JveFxw
YXINCi0tLSBzZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBibGFja2JveEBvYmVy
b24uY2h9fQADYA6wYyGzkS0R


----boundary-LibPST-iamunique-1917831363_-_---
Received on Fri May 05 2006 - 19:52:33 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:02 UTC