4
votes

I'm running Lazarus on Windows. I would really like to make the program "Beep". It appears that you can do so in Pascal using:

windows.beep(300,500);

But not in Lazarus! Is there another command that I can use?

Update:

sysutils.beep()

This works, but I'd really like to set the frequency and duration of sound

3

3 Answers

8
votes

Afaik this is functionality that worked for ages. (Dev Pascal is over ten years old).

What is different is that Lazarus does not automatically add Windows to the uses clause, like Delphi does.

6
votes

If this function is not declared in Lazarus, you can declare it like:

function Beep(dwFreq, dwDuration: DWORD): BOOL; stdcall; external 'kernel32.dll';
1
votes

In Lazarus create a new project and add a button. Add windows unit into uses list. In the button default event put your codes:

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,

  windows;  // added by manually

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
  n,
  freq,dur : integer;

begin
  Randomize;
  for n:=1 to 100 do
    begin
      windows.Beep(random(1000)+n,random(100)+100);
    end;
end;

end.