如果execute发生异常,则通过acquireexceptionobject取得异常对象,并存入线程类的ffatalexception成员中。
最后是线程结束前做的一些收尾工作。局部变量freethread记录了线程类的freeonterminated属性的设置,然后将线程返回值设置为线程类的返回值属性的值。然后执行线程类的doterminate方法。
doterminate方法的代码如下:
procedure tthread.doterminate;
begin
if assigned(fonterminate) then synchronize(callonterminate);
end;
很简单,就是通过synchronize来调用callonterminate方法,而callonterminate方法的代码如下,就是简单地调用onterminate事件:
procedure tthread.callonterminate;
begin
if assigned(fonterminate) then fonterminate(self);
end;