多线程基础问题
刚刚开始接触多线程,下面是使用Delphi 7照“Delphi 6开发人员指南”上的一个例子做的,可是编译报错:[Fatal Error] Main.pas(7): Circular unit reference to 'Main'。请问这个循环的引用怎么解决呢?
源码
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,MyThread;
type
TForm1 = class(TForm)
Memo1: TMemo;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
NewThread:TMyThread;
begin
NewThread:=TMyThread.Create(False);
end;
end.
unit MyThread;
interface
uses
Classes,Main;
type
TMyThread = class(TThread)
private
{ Private declarations }
Answer:Integer;
protected
procedure Execute; override;
procedure GiveAnswer;
end;
implementation
{ TMyThread }
procedure TMyThread.GiveAnswer;
begin
Form1.Edit1.Text:=IntToStr(Answer);
end;
procedure TMyThread.Execute;
var
i:Integer;
begin
{ Place thread code here }
FreeOnTerminate:=true;
for i:=i to 2000000 do
begin
if Terminated then break;
inc(Answer,Round(Abs(Sin(Sqrt(i)))));
Synchronize(GiveAnswer);
end;
end;
end.