Well, again from my current school project.
I've been told to make a traffic light that changes automatically, and you should be able to specify how many times the cycle should run.

I have my working version, but I just want to know if there's a shorter way to do this?

Pre-note: "siklus(se)" is cycles, "Teller" is counter.
And, we haven't learned of loops yet, so I can't use them.

var
  frmRobot: TfrmRobot;
  iRTeller, iTeller, iSiklusse : integer;

{ ... }

procedure TfrmRobot.bmbBeginClick(Sender: TObject);
begin

  iSiklusse := sedSiklus.Value;
  tmrRobot.Enabled := True;
  bmbBegin.Enabled := False;
  bmbRetry.Enabled := True;

end; { proc:Begin }

procedure TfrmRobot.tmrRobotTimer(Sender: TObject);
begin

    if iTeller < iSiklusse then
      begin

    Inc(iRTeller, 1);

    if iRTeller = 1 then
      begin
        shpGroen.Visible := True;
        shpOranje.Visible := False;
        shpRed.Visible := False;
      end { if:1 }

     else if iRTeller = 2 then
      begin
        shpGroen.Visible := False;
        shpOranje.Visible := True;
        shpRed.Visible := False;
      end { else if:2 }

     else if iRTeller = 3 then
      begin
        shpGroen.Visible := False;
        shpOranje.Visible := False;
        shpRed.Visible := True;
     end { else if:3 }

     else
      begin
        shpGroen.Visible := False;
        shpOranje.Visible := False;
        shpRed.Visible := False;
        Inc(iTeller, 1);
        iRTeller := 0;
      end; { else }

    end; { if:iSiklus }

end; { proc:Timer }

procedure TfrmRobot.FormActivate(Sender: TObject);
begin

  iRTeller := 0;
  bmbRetry.Enabled := False;

end; { proc:FormAcrivate }

procedure TfrmRobot.bmbRetryClick(Sender: TObject);
begin

  iTeller := 0;
  iRTeller := 0;
  iSiklusse := 0;
  bmbBegin.Enabled := True;

end;

end. { unit }

Thanks again.

Yuo can use a 0 to 4 counter from a intenger incremented one by using (iRTeller mod 4), and aduust visibility by using a Visible:= ((iRTeller mod 4)=1), so your big code get this small (also note my different indentation, far more legible for me):

procedure TfrmRobot.tmrRobotTimer(Sender: TObject);
begin
  if iTeller < iSiklusse then begin
    Inc(iRTeller, 1);
    //Set visibility
    shpGroen.Visible := ((iRTeller mod 4)=1);
    shpOranje.Visible := ((iRTeller mod 4)=2);
    shpRed.Visible := ((iRTeller mod 4)=3);
    if ((iRTeller mod 4)=0) then Inc(iTeller);
  end;
end;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.