TTlsThread.Create('Dilbert');,构造函数中的参数,'Dilbert'是如何传入到变量 GlobalStr中的?
就是说,为什么第二次的弹出消息,为什么是 Dilbert?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
var
GlobalStr:string;
type
TTlsThread=class(TThread)
private
FNewStr:string;
public
constructor Create(const ANewStr:string);
published
procedure Execute;override;
end;
procedure SetShowStr(S:string);
begin
if s='' then
MessageBox(0,PChar(GlobalStr),'The String is ...',MB_OK)
else
GlobalStr:=s;
end;
constructor TTlsThread.Create(const ANewstr: string);
begin
FNewStr:=ANewStr;
inherited Create(False);
end;
procedure TTlsThread.Execute;
begin
FreeOnTerminate:=True;
SetShowStr(FNewStr);
SetShowStr('');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetShowStr('Hello World');
SetShowStr('');
TTlsThread.Create('Dilbert');
Sleep(3000);
SetShowStr('');
end;end.
就是说,为什么第二次的弹出消息,为什么是 Dilbert?
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
var
GlobalStr:string;
type
TTlsThread=class(TThread)
private
FNewStr:string;
public
constructor Create(const ANewStr:string);
published
procedure Execute;override;
end;
procedure SetShowStr(S:string);
begin
if s='' then
MessageBox(0,PChar(GlobalStr),'The String is ...',MB_OK)
else
GlobalStr:=s;
end;
constructor TTlsThread.Create(const ANewstr: string);
begin
FNewStr:=ANewStr;
inherited Create(False);
end;
procedure TTlsThread.Execute;
begin
FreeOnTerminate:=True;
SetShowStr(FNewStr);
SetShowStr('');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SetShowStr('Hello World');
SetShowStr('');
TTlsThread.Create('Dilbert');
Sleep(3000);
SetShowStr('');
end;end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货