对比一下:
{主单元}
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Test.Create(False);
Test1.Create(False);
end;end.
{线程单元}
unit Unit2;interfaceuses
Classes, SysUtils;type
Test = class(TThread)
private
{ Private declarations }
FI: Integer;
procedure AddItem;
protected
procedure Execute; override;
end; Test1 = class(TThread)
private
FI: Integer;
procedure AddItem;
protected
procedure Execute; override;
end;implementationuses Unit1;{ Test }procedure Test.AddItem;
begin
Form1.ListBox1.Items.Add(IntToStr(FI));
end;procedure Test.Execute;
var
I: Integer;
begin
for I := 0 to 100000 do
begin
FI := I;
Synchronize(AddItem);
end;
end;{ test1 }procedure Test1.AddItem;
begin
Form1.ListBox2.Items.Add(IntToStr(FI));
end;procedure Test1.Execute;
var
I: Integer;
begin
for I := 0 to 100000 do
begin
FI := I;
Synchronize(AddItem);
end;
end;end.
{主单元}
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
Test.Create(False);
Test1.Create(False);
end;end.
{线程单元}
unit Unit2;interfaceuses
Classes, SysUtils;type
Test = class(TThread)
private
{ Private declarations }
FI: Integer;
procedure AddItem;
protected
procedure Execute; override;
end; Test1 = class(TThread)
private
FI: Integer;
procedure AddItem;
protected
procedure Execute; override;
end;implementationuses Unit1;{ Test }procedure Test.AddItem;
begin
Form1.ListBox1.Items.Add(IntToStr(FI));
end;procedure Test.Execute;
var
I: Integer;
begin
for I := 0 to 100000 do
begin
FI := I;
Synchronize(AddItem);
end;
end;{ test1 }procedure Test1.AddItem;
begin
Form1.ListBox2.Items.Add(IntToStr(FI));
end;procedure Test1.Execute;
var
I: Integer;
begin
for I := 0 to 100000 do
begin
FI := I;
Synchronize(AddItem);
end;
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货