M
mazheng
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下,为什么一删除线程窗体就没有反映呢??如何解决呢?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
mmo1: TMemo;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Txyz = class(TThread)
published
procedure Execute
override;
end;
var
XYZThread: Txyz;
Form1: TForm1;
implementation
{$R *.dfm}
procedure Txyz.Execute;
begin
while True do
begin
Form1.mmo1.Lines.Add('123456789');
Application.ProcessMessages;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
XYZThread := Txyz.Create(False);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
XYZThread.Suspend;
XYZThread.Free;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
mmo1: TMemo;
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
Txyz = class(TThread)
published
procedure Execute
override;
end;
var
XYZThread: Txyz;
Form1: TForm1;
implementation
{$R *.dfm}
procedure Txyz.Execute;
begin
while True do
begin
Form1.mmo1.Lines.Add('123456789');
Application.ProcessMessages;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
XYZThread := Txyz.Create(False);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
XYZThread.Suspend;
XYZThread.Free;
end;
end.