向工作线程传参数? 找用友进销存网络版
销售管理软件版1楼: 有一打印函数放在线程函数中
unit Unit7;
interface
uses
Classes, SysUtils, Printers;
type
TSendToPrinter = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ TSendToPrinter }
procedure TSendToPrinter.Execute;
var
TagUnit : SmallInt;
PosX,PosY : integer;
Label_1 : String;
begin
FreeOnTerminate := True;
Label_1 := Main_ary[TagUnit,3];
With Printer do begin
BeginDoc;
Canvas.TextOut(PosX,PosY,Label_1);
EndDoc;
end;
end;
end.
在主程序中调用此线程函数时如何向它传递参数
main_ary是全局数组,传递的参数是tagunit,posx,posy,应该怎么做?
。。。。
implementation
constructor tthread1.create(CreateSuspended: Boolean; TagUnit : smallinteger);
begin
inherited create(CreateSuspended);
//上面这一句一定要写
FTagUnit :=TagUnit;
//传别的参数也一样
。。。
end;
unit Unit7;
interface
uses
Classes, SysUtils, Printers;
type
TSendToPrinter = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ TSendToPrinter }
procedure TSendToPrinter.Execute;
var
TagUnit : SmallInt;
PosX,PosY : integer;
Label_1 : String;
begin
FreeOnTerminate := True;
Label_1 := Main_ary[TagUnit,3];
With Printer do begin
BeginDoc;
Canvas.TextOut(PosX,PosY,Label_1);
EndDoc;
end;
end;
end.
在主程序中调用此线程函数时如何向它传递参数
main_ary是全局数组,传递的参数是tagunit,posx,posy,应该怎么做?
2楼: 既然是全局的为什么不
写一个过程 然后同步执行 如用友进销存网络版
3楼: 重载构造函数create,在构造函数中传参数
private
FTagUnit:smallint;
public
。。。。
constructor create(CreateSuspended: Boolean;TagUnit :integer);reintroduce;
。。。。
implementation
constructor tthread1.create(CreateSuspended: Boolean; TagUnit : smallinteger);
begin
inherited create(CreateSuspended);
//上面这一句一定要写
FTagUnit :=TagUnit;
//传别的参数也一样
。。。
end;
4楼: to sparkif
明白了,我试试.
再问下,在主线程terminate时,辅助线程是不是也要显式的terminate,还是主线程一关闭,辅助线程也会自行terminate?
5楼: To zjknight:
主线程结束,辅助线程也会随之结束
主线程结束就意味着这个进程就结束了,进程中
所有线程都会结束
另外一个线程结束,调用terminate的同时要保证
在execute函数中去判断terminate属性
使用API TerminateThread则能强行结束
但不推荐使用
6楼: 接受答案了.