I just started with Lazarus; my last attempt to use Pascal was in the 90s writing little DOS apps so I'm incredibly rusty and have never done a GUI application before (unless you count web development)
I'm trying to make a button that displays a 15 minute countdown timer in real time. It should be simple, right?
procedure TSWF1.buBreakClick(Sender: TObject);
begin
target := IncMinute(Now,15);
While (Now <= target) do
begin
cdtimer.caption := FormatDateTime('mm:ss:z',target - Now);
sleep(10); {wait 10 ms}
{showmessage('looped'); }
end;
end;
See that commented out showmessage? If I don't comment it out, every time the OK button is pressed, it updates the label with the incorrect time (starts out showing 12 minutes 00 seconds, then goes to 12 mins 59 seconds, then counts down as normal)
If there's no showmessage, the label just never updates.
Ideally, I'd also like to show the first 2 digits of the miliseconds and drop the third, but no matter how many z's I put in the format field it always shows 3.
I've tried everything I can think of, including manually making integer variables for minutes, seconds, and miliseconds and manually altering then every loop, but that still won't display without a showmessage. I've even tried saying all of the magic words - my co-workers now believe I am transforming into Samuel L. Jackson.
How can I get this button to show a countdown timer without the user clicking an OK button every 10ms?
EDIT: target is a TDateTime declared in the form's private variables.