トップへ(mam-mam.net/)

Playing a Sound at a Specified Frequency in Delph

Japanese

Playing a Sound at a Specified Frequency in Delph

Winapi.Windows.Beep(Frequency [Hz], Duration [ms]);
By using this Windows API function, you can play a sound at a specified frequency (Hz) for a specified duration (ms).

Create a New Delphi Project, Place Components, and Set Properties

Launch Delphi and select File → New → Windows VCL Application – Delphi.
From the Tool Palette, drag and drop a TButton onto the form.

Programming

Double‑click Button1 and enter the following source code in the OnClick event.

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Winapi.Windows.Beep(262,300); // Do
      Winapi.Windows.Beep(294,300); // Re
      Winapi.Windows.Beep(330,300); // Mi
      Winapi.Windows.Beep(349,300); // Fa
      Winapi.Windows.Beep(392,300); // So
      Winapi.Windows.Beep(440,300); // La
      Winapi.Windows.Beep(494,300); // Ti
      Winapi.Windows.Beep(523,300); // Do
    end;
    

Run the Application

Click the Run button to compile and start the application.
When you click Button1, it will play the notes Do–Re–Mi–Fa–So–La–Ti–Do.