Well, I solved my problem by using the IdleTimer in between each statement. In one sense you’re correct when you say that each statement is completed one after the other but in practice the events can happen so fast that one statement doesn’t always have a chance to finish before the next one is started and they overlap each other, especially if you’re dealing with graphics. In the first example below, which doesn’t work right, I want to load a graphics file and then perform an analysis of the file (Button2Click). The next example, used with the IdleTimer, works fine because it gives a few microseconds delay before Button2Click is called.
This doesn't work
procedure TForm1.Button1Click(Sender: TObject);
var picture:TPicture;
begin
picture := TPicture.create;
Image1.picture.loadfromfile('pix1.png');
picture.free;
Button2Click(Sender);
end;
These two work
procedure TForm1.Button1Click(Sender: TObject);
var picture:TPicture;
begin
picture := TPicture.create;
Image1.picture.loadfromfile('pix1.png');
picture.free;
IdleTimer1.interval := 100;
IdleTimer1.enabled := true;
end;
procedure TForm1.IdleTimer1Timer(Sender: TObject);
begin
Button2Click(Sender);
IdleTimer1.enabled := false;
end;
Thanks for your quick responses!