How can I replace my noob code with nice loop ? I have 32 timers on form1 , every timer runs every 1 second and execute bat file, then waiting until bat file finishes his job and timer runs again.
Here is the code from image
procedure TForm1.Timer1Timer(Sender: TObject);
var nr:string;
begin
nr := '1';
Timer1.Enabled := False;
if g_stop=False then
begin
if FileExists('test'+nr+'.bat') then
begin
ExeAndWait(ExtractFilePath(Application.ExeName) + 'test'+nr+'.bat', SW_SHOWNORMAL);
end;
Timer1.Enabled := True;
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
var nr:string;
begin
nr := '2';
Timer2.Enabled := False;
if g_stop=False then
begin
if FileExists('test'+nr+'.bat') then
begin
ExeAndWait(ExtractFilePath(Application.ExeName) + 'test'+nr+'.bat', SW_SHOWNORMAL);
end;
Timer2.Enabled := True;
end;
end;
procedure TForm1.Timer3Timer(Sender: TObject);
var nr:string;
begin
nr := '3';
Timer3.Enabled := False;
if g_stop=False then
begin
if FileExists('test'+nr+'.bat') then
begin
ExeAndWait(ExtractFilePath(Application.ExeName) + 'test'+nr+'.bat', SW_SHOWNORMAL);
end;
Timer3.Enabled := True;
end;
end;