易
易名烦
Unregistered / Unconfirmed
GUEST, unregistred user!
这是我的代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread = Class(TThread)
procedure SetText;
procedure Execute;
Override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MThread: TMyThread;
begin
Mthread := TMyThread.Create(false);
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
Self.FreeOnTerminate := true;
Synchronize(SetText);
end;
procedure TMyThread.SetText;
begin
While Form1.Memo1.Lines.Count > 10do
Form1.Button1.Caption := 'Thread Over!';
end;
end.
问:为何我在MEMO1中输入数超过十行BUTTON的CAPTION却不变?
我测试了一下,好象WHILE循环没起作用,跟本就没循环。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyThread = Class(TThread)
procedure SetText;
procedure Execute;
Override;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
MThread: TMyThread;
begin
Mthread := TMyThread.Create(false);
end;
{ TMyThread }
procedure TMyThread.Execute;
begin
Self.FreeOnTerminate := true;
Synchronize(SetText);
end;
procedure TMyThread.SetText;
begin
While Form1.Memo1.Lines.Count > 10do
Form1.Button1.Caption := 'Thread Over!';
end;
end.
问:为何我在MEMO1中输入数超过十行BUTTON的CAPTION却不变?
我测试了一下,好象WHILE循环没起作用,跟本就没循环。