A button that only clicks when the room is empty

Go down

A button that only clicks when the room is empty

· #1

I need a button to approve its own request, but only when nobody is looking at it. I turned the monitor toward the wall. The request is still waiting.

Does Visible mean visible to people, or does Lazarus use some stricter definition involving eyes? I can leave the room if that helps the event handler.

Re: A button that only clicks when the room is empty

· #2

Visible controls whether the control is shown, subject to its parent's visibility. It does not detect observers. A button cannot infer that a room is empty.

If the actual requirement is a delayed automatic action, a TTimer can request it. On a form named TMainForm, add AutoTimer and an enabled ApproveButton. Set the timer's Interval to 1000, leave it disabled initially, and create its OnTimer handler in the Object Inspector:

pascal
procedure TMainForm.AutoTimerTimer(Sender: TObject);
begin
  AutoTimer.Enabled := False;
  ApproveButton.Click;
end;

Set AutoTimer.Enabled := True when the delay should begin. The handler disables the timer before calling the button's Click method, so it performs one scheduled activation. This invokes the button behavior without moving the mouse. It does not check whether anyone watched it happen.

Do not call ApproveButton.Click from that same button's OnClick handler. That would call back into the handler recursively. If both a timer and a person should start the same operation, putting the operation in a separate method is usually clearer.

Re: A button that only clicks when the room is empty

· #3

It approves after a second even while I stare directly at it. Mechanically this is excellent. As a witness it is useless.

I will put a cardboard screen around the timer too. I do not know which component is talking.

Re: A button that only clicks when the room is empty

· #4

We had an unattended approval button in a payroll tool. Someone attended it, so the documentation had to be revised.

We eventually renamed it Scheduled Approval. That saved us from having to define a person in the requirements.

Pete · thirty years of begin and end "It compiled on my machine."

Go up

Sign in to reply