编译出了问题,有劳各位给看一下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Mytest1.Create(False);
end;end.
unit Unit2;interfaceuses
Classes;type
Mytest1 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;implementation{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure Mytest.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ Mytest }procedure Mytest1.Execute;
begin
FreeOnTerminate:=True;
ShowMessage('线程1');
end;end.[Error] Unit2.pas(35): Undeclared identifier: 'ShowMessage'
[Fatal Error] Unit1.pas(28): Could not compile used unit 'Unit2.pas'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation
uses
Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Mytest1.Create(False);
end;end.
unit Unit2;interfaceuses
Classes;type
Mytest1 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;implementation{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure Mytest.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }{ Mytest }procedure Mytest1.Execute;
begin
FreeOnTerminate:=True;
ShowMessage('线程1');
end;end.[Error] Unit2.pas(35): Undeclared identifier: 'ShowMessage'
[Fatal Error] Unit1.pas(28): Could not compile used unit 'Unit2.pas'
Classes; type
Mytest1 = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end; implementation { Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure Mytest.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; } { Mytest } procedure Mytest1.Execute;
begin
FreeOnTerminate:=True;
ShowMessage('线程1'); //这里出错了,这是第35句。
end; end.
{VCL是非线程安全的,要Synchronize,不过还是不要在线程中直接使用VCL组件。
至于你说的线程很复杂,有多复杂。很简单的,你不一定要使用TThread,也可以
使用系统的CreateThread函数,虽然不推荐使用,但那只是VCL库中某些函数不能
重入而导致错误的问题,同样的问题也在C语言库中。
而且你发的帖子中用到了多线程,简直是驴头装到马屁股上,没用对地方。记住一点就好了
线程就是自己开着一辆车,脱离大部队自己行动去了。不过把柄还在长官手里。就这个道理。
}