D
delphi5988
Unregistered / Unconfirmed
GUEST, unregistred user!
多线程问题:
我想把多线程类写在一个单独的单元文件中,原后调用,但是中间有与VCL通信的问题
程序能运行,但不能把信息加入到控件中。
下面是程序源代码:
一定不要在unit2单元中加入UNIT1 这样看你们能不能解决!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,unit2;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
my:Tmyset;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
my:=Tmyset.create(form1.ListView1);
end;
end.
//_-----------------------------------------------------------
unit Unit2;
interface
uses
Classes,ComCtrls,SysUtils;
type
Tmyset = class(TThread)
{ Private declarations }
listview1:Tlistview;
procedure addpp(listview:Tlistview);
procedure Execute;
override;
constructor create(listview:Tlistview);
end;
implementation
{ Tmyset }
procedure Tmyset.addpp(listview: Tlistview);
var
item:Tlistitem;
i:integer;
begin
for i:=0 to 65535 do
begin
item:=listview.Items.Add;
item.Caption:=inttostr(i);
end;
end;
constructor Tmyset.create(listview: Tlistview);
begin
inherited create(false);
listview:=listview1;
end;
procedure Tmyset.Execute;
begin
addpp(listview1);
end;
end.
我想把多线程类写在一个单独的单元文件中,原后调用,但是中间有与VCL通信的问题
程序能运行,但不能把信息加入到控件中。
下面是程序源代码:
一定不要在unit2单元中加入UNIT1 这样看你们能不能解决!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,unit2;
type
TForm1 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
my:Tmyset;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
my:=Tmyset.create(form1.ListView1);
end;
end.
//_-----------------------------------------------------------
unit Unit2;
interface
uses
Classes,ComCtrls,SysUtils;
type
Tmyset = class(TThread)
{ Private declarations }
listview1:Tlistview;
procedure addpp(listview:Tlistview);
procedure Execute;
override;
constructor create(listview:Tlistview);
end;
implementation
{ Tmyset }
procedure Tmyset.addpp(listview: Tlistview);
var
item:Tlistitem;
i:integer;
begin
for i:=0 to 65535 do
begin
item:=listview.Items.Add;
item.Caption:=inttostr(i);
end;
end;
constructor Tmyset.create(listview: Tlistview);
begin
inherited create(false);
listview:=listview1;
end;
procedure Tmyset.Execute;
begin
addpp(listview1);
end;
end.