This works in C++ Builder:

int chcolor;
for(int d, d < 5, d++);
{
    String name = "d" + IntToStr(i+1);
    TLMDSpeedButton* button = dynamic_cast<TLMDSpeedButton*>(this->FindComponent(name));
    chcolor = random(6)+1;
    switch (chcolor)
        {
        case 1:
            button->Color = clRed;
            break;
        case 2:
            button->Color = clSilver;
            break;
        case 3:
            button->Color = clBlue;
            break;
        case 4:
            button->Color = clGreen;
            break;
        case 5:
            button->Color = clYellow;
            break;
        case 6:
            button->Color = clFuchsia;
            break;
        default:;
    }
}

Thank you for your help..:)

What have you got so far? A switch is a case of, Delphi uses dot notation instead of the arrow, and := for assignments.

nailed it!!!

  for x := 0 to 5 do
  begin
    i := random(6)+1;
    case i of
      1 : TLMDSpeedButton(Components[x]).Color := clRed;
      2 : TLMDSpeedButton(Components[x]).Color := clSilver;
      3 : TLMDSpeedButton(Components[x]).Color := clBlue;
      4 : TLMDSpeedButton(Components[x]).Color := clYellow;
      5 : TLMDSpeedButton(Components[x]).Color := clGreen;
      6 : TLMDSpeedButton(Components[x]).Color := clFuchsia;
    else;
  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.