正好昨天有段代码,改了改,试验成功了,你可以看看
代码有点乱
---------
form1
------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TestTh= class(TThread)
private
i:integer;
procedure closeForm;
procedure showI();
procedure onTer(sender:tobject);
public
procedure execute;override;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
private
t:TestTh;
fTheF:TForm;
function getForm:TForm;
procedure SetForm(Value:Tform);
public
property F:TForm read getForm write setForm;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TestTH.execute;
var j:integer;
begin
FreeOnTerminate := true;
onterminate := self.onTer;
{ for j:=0 to 100do
begin
i:=j;
Synchronize(showI);
sleep(1);
end;
}
Synchronize(showi);
while truedo
begin
if terminated then
break;
end;
end;
procedure TestTh.onTer(sender:tobject);
begin
form1.F.Close;
end;
procedure TestTH.closeForm;
begin
if form1.f.Showing then
form1.f.Close;
end;
procedure TestTh.showI();
begin
//form1.Edit1.Text := inttostr(i);
form1.F.Show;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
t:=testth.Create(false);
for i:= 1 to 100000do
begin
edit1.Text := inttostr(i);
application.ProcessMessages;
end;
t.Terminate;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
// TForm2(self.F).ShowModal;
self.t.Terminate;
end;
function TForm1.getForm:TForm;
begin
result:=self.fTheF;
end;
procedure TForm1.SetForm(value:Tform);
begin
self.fTheF:=value;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
self.F := form2;
end;
end.
------------------------------------------------
-----
form2
-----
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComCtrls;
type
TForm2 = class(TForm)
ProgressBar1: TProgressBar;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Timer1Timer(Sender: TObject);
begin
if self.ProgressBar1.Position = self.ProgressBar1.Max then
self.ProgressBar1.Position := self.ProgressBar1.Min;
self.ProgressBar1.StepIt;
end;
end.
------------------------------------------------