RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
SysUtils.Beep Function

Emits a message beep.

Pascal
procedure Beep;
C++
Beep();

Beep generates a conventional message beep.

Note: On Windows, Beep calls the Windows API MessageBeep.
Note: On Linux, to minimize library dependencies in the run time library, the SysUtils version of Beep has limited Linux functionality. For cross-platform GUI applications, use the QControls version of Beep instead.
 

C++ Examples: 

 

/*
This example requires a TRichEdit, a TButton, and a 
TFindDialog.  Clicking the button will display a Find
Dialog to the right of the edit control.  Filling in the 
"Find what" text and pressing the Find Next button will
select the first matching string in the Rich Edit control 
that follows the previous selection. Notice that the
"Match whole word only" and "Match case" work.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  FindDialog1->Position = Point(RichEdit1->Left + RichEdit1->Width, RichEdit1->Top);
  FindDialog1->Execute();
}

void __fastcall TForm1::FindDialog1Find(TObject *Sender)
{
  int FoundAt, StartPos, ToEnd;
  TSearchTypes mySearchTypes = TSearchTypes();
  // begin the search after the current selection
  // if there is one
  // otherwise, begin at the start of the text
  if (FindDialog1->Options.Contains(frMatchCase))
    mySearchTypes << stMatchCase;
  if (FindDialog1->Options.Contains(frWholeWord))
    mySearchTypes << stWholeWord;
  if (RichEdit1->SelLength)
    StartPos = RichEdit1->SelStart + RichEdit1->SelLength;
  else
    StartPos = 0;
  // ToEnd is the length from StartPos
  // to the end of the text in the rich edit control
  ToEnd = RichEdit1->Text.Length() - StartPos;
  FoundAt = RichEdit1->FindText(FindDialog1->FindText, StartPos, ToEnd, mySearchTypes);
  if (FoundAt != -1)
  {
    RichEdit1->SetFocus();
    RichEdit1->SelStart = FoundAt;
    RichEdit1->SelLength = FindDialog1->FindText.Length();
  }
  else Beep();
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  RichEdit1->PlainText = False;
  RichEdit1->Lines->LoadFromFile("../Overview.RTF");  // starts in Debug
  RichEdit1->ScrollBars = ssVertical;
}
/*
The following example beeps once for each "beep" passed in
on the command line.  The example terminates the application
if  "exit" is passed in on the command line.  Build the
project to generate a .exe file and then execute that file
from a command line: "ParamCount_proj beep beep exit".
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//  Use print statements since you can't use the debugger.
//  MessageDlg(
//    "System ParamStr = " + AnsiString(System::ParamStr(i)),
//    mtConfirmation, TMsgDlgButtons() << mbOK, 0);
  for (int i=1;i<=ParamCount();i++)
  {
    if (LowerCase(ParamStr(i)) == "beep")
      Beep();
    else if (LowerCase(ParamStr(i)) == "exit")
      Application->Terminate();
  }
}

 

Delphi Examples: 

{
This example requires a TRichEdit, a TButton, and a 
TFindDialog.  Clicking the button click will display a Find 
Dialog to the right of the edit control.  Filling in the 
"Find what" text and pressing the Find Next button will 
select the first matching string in the Rich Edit control 
that follows the previous selection.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  FindDialog1.Position := 
    Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
  FindDialog1.Execute;
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: LongInt;
  StartPos, ToEnd: Integer;
  mySearchTypes : TSearchTypes;
  myFindOptions : TFindOptions;
begin
  mySearchTypes := [];
  with RichEdit1 do
  begin
    if frMatchCase in FindDialog1.Options then
       mySearchTypes := mySearchTypes + [stMatchCase];
    if frWholeWord in FindDialog1.Options then
       mySearchTypes := mySearchTypes + [stWholeWord];
    { begin the search after the current selection if there is one }
    { otherwise, begin at the start of the text }
    if SelLength <> 0 then
      StartPos := SelStart + SelLength
    else
      StartPos := 0;
    { ToEnd is the length from StartPos to the end of the 
      text in the rich edit control }
    ToEnd := Length(Text) - StartPos;
    FoundAt := 
      FindText(FindDialog1.FindText, StartPos, ToEnd, mySearchTypes);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
    end
    else Beep;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
const Path = 'OverView.RTF';
begin
  RichEdit1.PlainText := False;
  RichEdit1.Lines.LoadFromFile(Path);
  RichEdit1.ScrollBars := ssVertical;
end;
{
The following example beeps once for each "beep" passed in
on the command line.  The example terminates the application
if  "exit" is passed in on the command line.  Build the
project to generate a .exe file and then execute that file
from a command line: "ParamCount_proj beep beep exit".
} 
procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
//  Use print statements since you can't use the debugger.
//  MessageDlg(
//    'System ParamCount = ' + IntToStr(System.ParamCount),
//    mtConfirmation, [mbOK], 0);
  for i := 1 to System.ParamCount do
  begin
    if LowerCase(ParamStr(i)) = 'beep' then
      Beep
    else if LowerCase(ParamStr(i)) = 'exit' then
      Application.Terminate;
    Sleep(250);
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!