2

I've created a simple application, which contain: - Main form - Main menu - Action list

Action list consists of three actions: one standard - exit, and two specific - 1. connect to database and 2. billing.

In order to prevent billing action before connecting to database I made property "enabled" for billing = false.

Connect action event (OnExecute) I linked to this procedure:

procedure TForm1.ConnectActionExecute(Sender: TObject);
begin
  ConnectAction.Enabled := false;
  BillingAction.Enabled := true;
  StatusBar1.Panels[0].Text := 'DB Status: Connected';
end;

But after firing this action ConnectAction became disabled, but BillingAction continue to stay disabled. Please point where is my fault?

Arioch 'The
  • 15,799
  • 35
  • 62
Alex Zhulin
  • 1,239
  • 2
  • 22
  • 42
  • I guess you can set breakpoint in BillingAction.SetEnabled and perhaps catch the moment when it would be set back to False (if property setter is used rather than ddirect access to private fields, which is plausible) – Arioch 'The Dec 25 '13 at 10:27
  • 3
    This is odd. Normal to control `Enabled` from `OnUpdate`. – David Heffernan Dec 25 '13 at 10:53
  • `OnUpdate` might lead to 100% CPu usage if not to tune `TApplication` – Arioch 'The Dec 25 '13 at 11:10
  • @Arioch'The OnUpdate is fine – David Heffernan Dec 25 '13 at 13:24
  • @DavidHeffernan it is called as part of Application.OnIdle loop - it needs throttling – Arioch 'The Dec 25 '13 at 14:31
  • @Arioch Why so? Why should calling OnUpdate provoke a new OnIdle? – David Heffernan Dec 25 '13 at 14:34
  • @DavidHeffernan it does not. Both OnIdle and OnUpdate are executed from the same loop, that unless throttled would consume all the CPU time left from other event handlers – Arioch 'The Dec 25 '13 at 16:45
  • @arioch No. OnIdle runs when the message loop empties the queue. If OnUpdate leads to queued messages then you have the need for throttling. But that's not what OnUpdate should be doing. – David Heffernan Dec 25 '13 at 17:01
  • @DavidHeffernan and when does OnUpdate run if not "when the message loop empties the queue" ? – Arioch 'The Dec 25 '13 at 17:36
  • @Arioch'The But it doesn't keep running. The message loop empties the queue, fires the `OnIdle` event, and blocks until the next message. – David Heffernan Dec 25 '13 at 17:44
  • 1
    When using TAction I always use OnUpdate event to set the Enabled property and I never realized any increase of cpu consumption. – Sir Rufo Dec 25 '13 at 19:59
  • @DavidHeffernan but do `OnUpdate` events keep running or not ? In my experience - they do. Just see http://stackoverflow.com/questions/14828279/ Those events are interrelated, see http://stackoverflow.com/questions/5507502 – Arioch 'The Dec 26 '13 at 06:55
  • 2
    @Arioch Why would OnUpdate handlers provoke OnIdle. Do them right and they won't. – David Heffernan Dec 26 '13 at 07:35
  • @Arioch'The: the `OnIdle` event (and thus the `OnUpdate` event) is only triggered when new messages are put into the application message queue and then processed. If you are getting endless `OnUpdate` events than something in your app is generating new messages when it likely should not be. Find out what messages are actually being put in the queue before `OnIdle` is triggered each time. – Remy Lebeau Jan 02 '14 at 17:55

1 Answers1

5

Do you have an OnExecute event wired to the BillingAction? It is standard behaviour to disable actions with no OnExecute event.

Update: You can control this with the DisableIfNoHandler property of the action.

Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130