对不起,程序太大了,但基本是重复的部分,运行是只需要在窗体上放五个Label控件,
一个Button控件,其他均取默认值,将下列程序Copy进去,就能成功
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TMyThread1 = class(TThread)
published
procedure Execute;
override;
end;
type
TMyThread2 = class(TThread)
published
procedure Execute;
override;
end;
type
TMyThread3 = class(TThread)
published
procedure Execute;
override;
end;
type
TMyThread4 = class(TThread)
published
procedure Execute;
override;
end;
type
TMyThread5 = class(TThread)
published
procedure Execute;
override;
end;
var
Form1: TForm1;
MyThread1: TMyThread1;
MyThread2: TMyThread2;
MyThread3: TMyThread3;
MyThread4: TMyThread4;
MyThread5: TMyThread5;
implementation
{$R *.DFM}
procedure TMyThread1.Execute;
var i,j: Integer;
begin
j:=0;
for i:=1 to 10000do
begin
j:=j+i;
Form1.Label1.Caption:=IntToStr(j)
end;
end;
procedure TMyThread2.Execute;
var i,j: Integer;
begin
j:=0;
for i:=1 to 10000do
begin
j:=j+i;
Form1.Label2.Caption:=IntToStr(j)
end;
end;
procedure TMyThread3.Execute;
var i,j: Integer;
begin
j:=0;
for i:=1 to 10000do
begin
j:=j+i;
Form1.Label3.Caption:=IntToStr(j)
end;
end;
procedure TMyThread4.Execute;
var i,j: Integer;
begin
j:=0;
for i:=1 to 10000do
begin
j:=j+i;
Form1.Label4.Caption:=IntToStr(j)
end;
end;
procedure TMyThread5.Execute;
var i,j: Integer;
begin
j:=0;
for i:=1 to 10000do
begin
j:=j+i;
Form1.Label5.Caption:=IntToStr(j)
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MyThread1:=TMyThread1.Create(False);//为False,直接运行
MyThread2:=TMyThread2.Create(False);
MyThread3:=TMyThread3.Create(False);
MyThread4:=TMyThread4.Create(False);
MyThread5:=TMyThread5.Create(False);
end;
end.