multithreading - Delphi thread return value -
multithreading - Delphi thread return value -
can explain me how homecoming value mythread calling function test?
function test(value: integer): integer; begin result := value+2; end; procedure mythread.execute; begin inherited; test(self.fparameters); end; procedure getvaluefromthread(); var capture : mythread; begin list := tstringlist.create; capture := mythread.create(false); capture.fparameters := 2; capture.resume; end;
declare class derived tthread
. add field, or multiple fields, contain result value or values. set result value field(s) in overridden execute
method. when thread has finished, read result thread instance.
as remy points out, if wish homecoming single integer
value, can utilize returnvalue
property of tthread
. utilize in same way described above. note value placed in returnvalue
value returned underlying os thread.
you can hear onterminate
find out when thread done. or phone call waitfor
.
note set thread's parameters after starts running. either create thread suspended, or pass parameters constructor. also, should utilize start
rather resume
. latter deprecated.
multithreading delphi return-value
Comments
Post a Comment