1. Home
  2. Computing & Technology
  3. Delphi Programming

Random Colors Piano Bar

Fancy Delphi Application Contest Entry #3 by Don Rowlett

By Zarko Gajic, About.com

Random Colors Piano - Fancy Delphi Application Contest Entry #3

Random Colors Piano - Fancy Delphi Application Contest Entry #3

The piano is a musical instrument played by means of a keyboard that produces sound by striking steel strings with felt hammers.

Imagine steel strings are color bars, imagine every color producing a different random sound .. and we have a new entry for the Fancy Delphi Application Contest.

Rate this FDAC Entry!

Random Colors Piano

This silly little program creates labels (TLabel) at run time and paints them using a random color. Labels are placed in a control array. When you hover your mouse over the label a sound is played.

Here's the main program's source section:

var
  Lab: Array[1..65] of TLabel;

.....

procedure CreatePiano;
var
  k: Byte;
begin
  for k:= 1 to 65 do Lab[k].Color:= Random(16777216) ;
end;

procedure TRndLabColForm.FormCreate(Sender: TObject) ;
var
  k: Byte;
begin
  Randomize;
  for k:= 1 to 65 do
  begin
    Lab[k]:= TLabel.Create(Self) ;
    Lab[k].Parent := Self;
    Lab[k].Left := 8 + 11*(k-1) ;
    Lab[k].Color:= Random(16777216) ;
    Lab[k].OnMouseEnter:= BarClick;
  end;
end;

procedure TRndLabColForm.BarClick(Sender: TObject) ;
begin
  Application.ProcessMessages;

  with Sender as TLabel do
     Windows.Beep(440 + (Color div 3500), 100) ;
end;

"Random Colors Piano" was submitted by "Don Rowlett".

Do you have a FDA(C)? Submit your Delphi code to the Fancy Delphi Application Contest.

Explore Delphi Programming

More from About.com

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Source Code Projects
  5. Random Colors Piano Bar - Fancy Delphi Application Contest Entry #3

©2008 About.com, a part of The New York Times Company.

All rights reserved.