아래와 같이 소스를 만들었습니다. Create 버튼을 누르면 소리가 나게 만들었는데..
소리가 나지를 않습니다.
잘못된 점을 알려주세요
그리고
BeeperThread.Terminate;
While not Terminated do
begin
beep(200, 200);
sleep(1000);
end;
이것들이 뭔지 좀 알려주세요
해석 부탁드립니다.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
var
BeeperThread : TBeeperThread;
procedure TForm1.Button1Click(Sender: TObject);
begin
BeeperThread := TBeeperThread.Create(false);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
BeeperThread.Terminate;
BeeperThread.WaitFor;
ShowMessage('쓰레드가 종료되었습니다!');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
BeeperThread.Suspend;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
BeeperThread.Resume;
end;
end.
-------------------------------------------------
unit Unit2;
interface
uses
Classes,Windows;
type
TBeeperThread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure TBeeperThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ TBeeperThread }
procedure TBeeperThread.Execute;
begin
While true do
begin
Beep(200,200);
sleep(1000)
end;
end;
end.