This is definitely not the right way to write code. Avoid ProcessMessages() whenever possible. The example given can be replaced with a simple UI Timer instead, eg:
ProgressBar1.Value : =0;
ProgressBar1.Max := 100;
Timer1.Enabled := True;
...
procedure TForm1.Timer1Timer(Sender: TObject);
begin
ProgressBar1.Value := ProgressBar1.Value + 1;
if ProgressBar1.Value >= ProgressBar1.Max then
begin
Timer1.Enabled := True;
Exit;
end;
//...
end;
But, if your real project is using the ProgressBar to tracking status of actual tasks, those tasks should be done in the background, and updates to the UI synced with the main UI thread accordingly.