5,386
社区成员
发帖
与我相关
我的任务
分享
type
Ttest=class(TThread)
private
{ Private declarations }
Fa: PString;
protected
procedure Execute; override;
public
{ Public declarations }
constructor Create(ASk: PString; AL:TListbox);
end;
constructor TTest.Create(ASk: PString; AL:TListbox);
begin
FreeOnTerminate := False;
inherited Create(False);
FA:=ASK; // 值的传递 此处仅带入一个字符串值
end;
procedure TTest.Execute;
begin
FA^:='测试';
end;
//-------------------------------------------------------------------
procedure TForm1.Button2Click(Sender: TObject);
begin
sk := '123';
with Ttest.Create(@sk, nil) do
begin
WaitFor;
Free;
end;
Caption := sk;
end;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Ttest=class(TThread)
private
{ Private declarations }
Fa:String;
FL:TListbox;
FS:TMemo;
protected
procedure Execute; override;
public
{ Public declarations }
constructor Create(ASk:string;AL:TListbox);
end;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
Edit1: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
work:TTest;
SK:string;
public
{ Public declarations }
end;
var
Form1: TForm1;
s:string;
implementation
{$R *.dfm}
constructor TTest.Create(ASk:string;AL:TListbox);
begin
inherited Create(False);
FA:=ASK; // 值的传递 此处仅带入一个字符串值
Fl:=Al; // 完成地址传递 对Fl的操作,就是对AL的 操作即对Listbox1的操作
ShowMessage(FA);
end;
procedure TTest.Execute;
begin
FA:='测试';
Fl.items.add(FA);
S:=FA;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SK:='AAA';
work:=TTest.Create(SK,ListBox1);
Edit1.Text:=S;
end;
end.