Hi all. I have some
TPaintBoxes that I want to repaint at a constant rate (as close to 60hz as possible, basically). I have a
TTimer on my form with an interval of 16, which essentially just calls
Invalidate on my paintboxes. This is fine, and it (kinda) works.
Let's say my timer event looks like this:
procedure TMyForm.Timer1Timer(Sender: TObject);
begin
MyPaintBox.Invalidate;
end;
The problem is that now menu items (on the main menu) don't respond to being clicked, and any other forms that exist
can't be closed with the X button. I don't really know why this occurs, I'm guessing because the repainting at 60hz is clogging the message queue with timer events or something?
I put this in as a fix:
procedure TMyForm.Timer1Timer(Sender: TObject);
begin
if PerformingTimerUpdate then Exit;
PerformingTimerUpdate := True;
MyPaintBox.Invalidate;
Application.ProcessMessages;
PerformingTimerUpdate := False;
end;
Alright, this allows menu items and other forms to work properly,
most of the time. About 1 out of every 10 clicks on a menu item will fail to work, or a form will fail to close when you click the button. When you click a menu item, the menu just stays up as if nothing happened. I have no clue why this is going on. There's no way I'm exceeding the depth of the message queue because it can store 10,000 messages and I'm clearing them out pretty quickly. So why is it seemingly dropping click events!?
What's the recommended way to do this? I know it has to be possible because other programs can do fast repaints no problem.