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
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:
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