<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>个人编程</title><link>https://ainn.wang/</link><description>个人编程</description><item><title>函数</title><link>https://ainn.wang/?id=6</link><description>&lt;p style=&quot;margin-top: 0px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;我们知道圆的面积计算公式为：&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;S = πr&lt;span style=&quot;font-size: 12px; line-height: 0; position: relative; vertical-align: baseline; top: -0.5em;&quot;&gt;2&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;当我们知道半径&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;r&lt;/code&gt;的值时，就可以根据公式计算出面积。假设我们需要计算3个不同大小的圆的面积：&lt;/p&gt;&lt;pre style=&quot;margin-top: 15px; margin-bottom: 15px; padding: 10px; background-color: rgb(250, 250, 250); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 18px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px;&quot;&gt;r1&amp;nbsp;=&amp;nbsp;12.34r2&amp;nbsp;=&amp;nbsp;9.08r3&amp;nbsp;=&amp;nbsp;73.1s1&amp;nbsp;=&amp;nbsp;3.14&amp;nbsp;*&amp;nbsp;r1&amp;nbsp;*&amp;nbsp;r1s2&amp;nbsp;=&amp;nbsp;3.14&amp;nbsp;*&amp;nbsp;r2&amp;nbsp;*&amp;nbsp;r2s3&amp;nbsp;=&amp;nbsp;3.14&amp;nbsp;*&amp;nbsp;r3&amp;nbsp;*&amp;nbsp;r3&lt;/pre&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;当代码出现有规律的重复的时候，你就需要当心了，每次写&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;3.14 * x * x&lt;/code&gt;不仅很麻烦，而且，如果要把&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;3.14&lt;/code&gt;改成&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;3.14159265359&lt;/code&gt;的时候，得全部替换。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;有了函数，我们就不再每次写&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;s = 3.14 * x * x&lt;/code&gt;，而是写成更有意义的函数调用&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;s = area_of_circle(x)&lt;/code&gt;，而函数&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;area_of_circle&lt;/code&gt;本身只需要写一次，就可以多次调用。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;基本上所有的高级语言都支持函数，Python也不例外。Python不但能非常灵活地定义函数，而且本身内置了很多有用的函数，可以直接调用。&lt;/p&gt;&lt;h3 style=&quot;margin: 25px 0px 15px; font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; font-weight: normal; color: rgb(68, 68, 68); font-size: 18px; line-height: 24px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;抽象&lt;/h3&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;抽象是数学中非常常见的概念。举个例子：&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;计算数列的和，比如：&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;1 + 2 + 3 + ... + 100&lt;/code&gt;，写起来十分不方便，于是数学家发明了求和符号∑，可以把&lt;code style=&quot;font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);&quot;&gt;1 + 2 + 3 + ... + 100&lt;/code&gt;记作：&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;100&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-size: 3em;&quot;&gt;∑&lt;/span&gt;&lt;span style=&quot;font-size: 2em;&quot;&gt;n&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;n=1&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;这种抽象记法非常强大，因为我们看到 ∑ 就可以理解成求和，而不是还原成低级的加法运算。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;而且，这种抽象记法是可扩展的，比如：&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;100&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;&lt;span style=&quot;font-size: 3em;&quot;&gt;∑&lt;/span&gt;&lt;span style=&quot;font-size: 2em;&quot;&gt;(n&lt;span style=&quot;font-size: 21px; line-height: 0; position: relative; vertical-align: baseline; top: -0.5em;&quot;&gt;2&lt;/span&gt;+1)&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;n=1&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;还原成加法运算就变成了：&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;(1 x 1 + 1) + (2 x 2 + 1) + (3 x 3 + 1) + ... + (100 x 100 + 1)&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;可见，借助抽象，我们才能不关心底层的具体计算过程，而直接在更高的层次上思考问题。&lt;/p&gt;&lt;p style=&quot;margin-top: 15px; margin-bottom: 15px; color: rgb(102, 102, 102); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;写计算机程序也是一样，函数就是最基本的一种代码抽象的方式。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 23 Sep 2021 17:41:34 +0800</pubDate></item><item><title>DELPHI编写服务程序总结</title><link>https://ainn.wang/?id=5</link><description>&lt;p&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;一、服务程序和桌面程序的区别&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Windows&amp;nbsp;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000;&quot;&gt;2000&lt;/span&gt;/XP/&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000;&quot;&gt;2003&lt;/span&gt;等支持一种叫做“系统服务程序”的进程，系统服务和桌面程序的区别是：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;系统服务不用登陆系统即可运行；系统服务是运行在System&amp;nbsp;Idle&amp;nbsp;Process/System/smss/winlogon/services下的，而桌面程序是运行在Explorer下的；系统服务拥有更高的权限，系统服务拥有Sytem的权限，而桌面程序只有Administrator权限；在Delphi中系统服务是对桌面程序进行了再一次的封装，既系统服务继承于桌面程序。因而拥有桌面程序所拥有的特性；系统服务对桌面程序的DoHandleException做了改进，会自动把异常信息写到NT服务日志中；普通应用程序启动只有一个线程，而服务启动至少含有三个线程。（服务含有三个线程：TServiceStartThread服务启动线程；TServiceThread服务运行线程；Application主线程，负责消息循环）；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;摘录代码：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TServiceApplication&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Run&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartThread&amp;nbsp;:=&amp;nbsp;TServiceStartThread.Create(ServiceStartTable);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;try&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;while&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;not&lt;/span&gt;&amp;nbsp;Forms.Application.Terminated&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;do&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Forms.Application.HandleMessage;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Forms.Application.Terminate;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;if&lt;/span&gt;&amp;nbsp;StartThread.ReturnValue&amp;nbsp;&amp;lt;&amp;gt;&amp;nbsp;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000;&quot;&gt;0&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;then&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FEventLogger.LogMessage(SysErrorMessage(StartThread.ReturnValue));&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;finally&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;StartThread.Free;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TService&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;DoStart&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;try&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Status&amp;nbsp;:=&amp;nbsp;csStartPending;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;try&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FServiceThread&amp;nbsp;:=&amp;nbsp;TServiceThread.Create(Self);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FServiceThread.Resume;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FServiceThread.WaitFor;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FreeAndNil(FServiceThread);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;finally&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Status&amp;nbsp;:=&amp;nbsp;csStopped;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;except&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;on&lt;/span&gt;&amp;nbsp;E:&amp;nbsp;Exception&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;do&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LogMessage(Format(SServiceFailed,[SExecute,&amp;nbsp;E.&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Message&lt;/span&gt;]));&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;在系统服务中也可以使用TTimer这些需要消息的定时器，因为系统服务在后台使用TApplication在分发消息；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;二、如何编写一个系统服务&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;打开Delphi编辑器，选择菜单中的&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;File&lt;/span&gt;|New|Other...，在New&amp;nbsp;Item中选择Service&amp;nbsp;Application项，Delphi便自动为你建立一个基于TServiceApplication的新工程，TserviceApplication是一个封装NT服务程序的类，它包含一个TService1对象以及服务程序的装卸、注册、取消方法。&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;TService属性介绍：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;AllowPause：是否允许暂停；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;AllowStop：是否允许停止；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Dependencies：启动服务时所依赖的服务，如果依赖服务不存在则不能启动服务，而且启动本服务的时候会自动启动依赖服务；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;DisplayName：服务显示名称；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;ErrorSeverity：错误严重程度；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Interactive：是否允许和桌面交互；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;LoadGroup：加载组；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Name&lt;/span&gt;：服务名称；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Password：服务密码；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;ServiceStartName：服务启动名称；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;ServiceType：服务类型；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;StartType：启动类型；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;事件介绍：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;AfterInstall：安装服务之后调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;AfterUninstall：服务卸载之后调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;BeforeInstall：服务安装之前调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;BeforeUninstall：服务卸载之前调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnContinue：服务暂停继续调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnExecute：执行服务开始调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnPause：暂停服务调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnShutDown：关闭时调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnStart：启动服务调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OnStop：停止服务调用的方法；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;三、编写一个两栖服务&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;采用下面的方法，可以实现一个两栖系统服务（既系统服务和桌面程序的两种模式）&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;工程代码：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;program&lt;/span&gt;&amp;nbsp;FleetReportSvr;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;uses&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SvcMgr,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Forms,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SysUtils,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Windows,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SvrMain&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;SvrMain.pas&amp;#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;{FleetReportService:&amp;nbsp;TService}&lt;/span&gt;,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;AppMain&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;AppMain.pas&amp;#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;{FmFleetReport}&lt;/span&gt;；&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-meta&quot; style=&quot;box-sizing: border-box; color: #2B91AF;&quot;&gt;{$R&amp;nbsp;*.RES}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;const&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;CSMutexName&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;Global\Services_Application_Mutex&amp;#39;&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;var&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OneInstanceMutex:&amp;nbsp;THandle;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SecMem:&amp;nbsp;SECURITY_ATTRIBUTES;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;aSD:&amp;nbsp;SECURITY_DESCRIPTOR;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;InitializeSecurityDescriptor(@aSD,&amp;nbsp;SECURITY_DESCRIPTOR_REVISION);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SetSecurityDescriptorDacl(@aSD,&amp;nbsp;True,&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;nil&lt;/span&gt;,&amp;nbsp;False);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SecMem.nLength&amp;nbsp;:=&amp;nbsp;SizeOf(SECURITY_ATTRIBUTES);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SecMem.lpSecurityDescriptor&amp;nbsp;:=&amp;nbsp;@aSD;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SecMem.bInheritHandle&amp;nbsp;:=&amp;nbsp;False;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;OneInstanceMutex&amp;nbsp;:=&amp;nbsp;CreateMutex(@SecMem,&amp;nbsp;False,&amp;nbsp;CSMutexName);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;if&lt;/span&gt;&amp;nbsp;(GetLastError&amp;nbsp;=&amp;nbsp;ERROR_ALREADY_EXISTS)then&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DlgError(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;Error,&amp;nbsp;Program&amp;nbsp;or&amp;nbsp;service&amp;nbsp;already&amp;nbsp;running!&amp;#39;&lt;/span&gt;);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Exit&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;if&lt;/span&gt;&amp;nbsp;FindCmdLineSwitch(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;svc&amp;#39;&lt;/span&gt;,&amp;nbsp;True)&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;or&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FindCmdLineSwitch(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;install&amp;#39;&lt;/span&gt;,&amp;nbsp;True)&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;or&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FindCmdLineSwitch(&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;uninstall&amp;#39;&lt;/span&gt;,&amp;nbsp;True)&amp;nbsp;then&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SvcMgr.Application.Initialize;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SvcMgr.Application.CreateForm(TSvSvrMain,&amp;nbsp;SvSvrMain);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SvcMgr.Application.Run;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;end&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;else&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Forms.Application.Initialize;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Forms.Application.CreateForm(TFmFmMain,&amp;nbsp;FmMain);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Forms.Application.Run;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;然后在SvrMain注册服务：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;unit&lt;/span&gt;&amp;nbsp;SvrMain;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;interface&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;uses&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Windows,&amp;nbsp;Messages,&amp;nbsp;SysUtils,&amp;nbsp;Classes,&amp;nbsp;Graphics,&amp;nbsp;Controls,&amp;nbsp;SvcMgr,&amp;nbsp;Dialogs,&amp;nbsp;MsgCenter;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;type&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;class&lt;/span&gt;(TService)&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceStart&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;var&lt;/span&gt;&amp;nbsp;Started:&amp;nbsp;Boolean)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceStop&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;var&lt;/span&gt;&amp;nbsp;Stopped:&amp;nbsp;Boolean)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceBeforeInstall&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceAfterInstall&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;private&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;{&amp;nbsp;Private&amp;nbsp;declarations&amp;nbsp;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;public&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;function&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;GetServiceController&lt;/span&gt;:&lt;/span&gt;&amp;nbsp;TServiceController;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;override&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;{&amp;nbsp;Public&amp;nbsp;declarations&amp;nbsp;}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;var&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SvSvrMain:&amp;nbsp;TSvSvrMain;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;implementation&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;const&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;CSRegServiceURL&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;SYSTEM\CurrentControlSet\Services\&amp;#39;&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;CSRegDescription&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;Description&amp;#39;&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;CSRegImagePath&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;ImagePath&amp;#39;&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;CSServiceDescription&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;Services&amp;nbsp;Sample.&amp;#39;&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-meta&quot; style=&quot;box-sizing: border-box; color: #2B91AF;&quot;&gt;{$R&amp;nbsp;*.DFM}&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceController&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(CtrlCode:&amp;nbsp;DWord)&lt;/span&gt;;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;stdcall&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;SvSvrMain.Controller(CtrlCode);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;function&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;GetServiceController&lt;/span&gt;:&lt;/span&gt;&amp;nbsp;TServiceController;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Result&amp;nbsp;:=&amp;nbsp;ServiceController;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceStart&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;var&lt;/span&gt;&amp;nbsp;Started:&amp;nbsp;Boolean)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Started&amp;nbsp;:=&amp;nbsp;dmPublic.Start;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceStop&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;var&lt;/span&gt;&amp;nbsp;Stopped:&amp;nbsp;Boolean)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;Stopped&amp;nbsp;:=&amp;nbsp;dmPublic.Stop;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceBeforeInstall&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;RegValueDelete(HKEY_LOCAL_MACHINE,&amp;nbsp;CSRegServiceURL&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Name&lt;/span&gt;,&amp;nbsp;CSRegDescription);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TSvSvrMain&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ServiceAfterInstall&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender:&amp;nbsp;TService)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;begin&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;RegWriteString(HKEY_LOCAL_MACHINE,&amp;nbsp;CSRegServiceURL&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Name&lt;/span&gt;,&amp;nbsp;CSRegDescription,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CSServiceDescription);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;RegWriteString(HKEY_LOCAL_MACHINE,&amp;nbsp;CSRegServiceURL&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;Name&lt;/span&gt;,&amp;nbsp;CSRegImagePath,&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ParamStr(&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000;&quot;&gt;0&lt;/span&gt;)&amp;nbsp;+&amp;nbsp;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;&amp;nbsp;-svc&amp;#39;&lt;/span&gt;);&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;end&lt;/span&gt;.&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;这样，双击程序，则以普通程序方式运行，若用服务管理器来运行，则作为服务运行。&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;例如公共模块：&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;dmPublic，提供Start,Stop方法。&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;在主窗体中，调用dmPublic.Start，dmPublic.Stop方法。&lt;br style=&quot;box-sizing: border-box;&quot;/&gt;同样在Service中，调用dmPublic.Start，dmPublic.Stop方法。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 23 Sep 2021 17:37:26 +0800</pubDate></item><item><title>delphi多线程TThread详解</title><link>https://ainn.wang/?id=4</link><description>&lt;p&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; TThread 详解 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;我们常有工作线程和主线程之分，工作线程负责作一些后台操作，比如接收邮件；主线程负责界面上的一些显示。工作线程的好处在某些时候是不言而喻的，你的主界面可以响应任何操作，而背后的线程却在默默地工作。&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;VCL中，工作线程执行在Execute方法中，你必须从TThread继承一个类并覆盖Execute方法，在这个方法中，所有代码都是在另一个 线程中执行的，除此之外，你的线程类的其他方法都在主线程执行，包括构造方法，析构方法，Resume等，很多人常常忽略了这一点。&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;最简单的一个线程类如下：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;TMyThread&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;(TThread)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;protected&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Execute&lt;/span&gt;;&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;override&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;在Execute中的代码，有一个技术要点，如果你的代码执行时间很短，像这样，Sleep(&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;)，那没有关系；如果是这样Sleep (&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;10000&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;)，&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;秒，那么你就不能直接这样写了，须把这&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;秒拆分成&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;个&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;秒，然后判断Terminated属性，像下面这样： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Execute&lt;/span&gt;;&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;var&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;i: Integer; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;begin&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; i := &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;do&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Terminated &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Sleep(&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;) &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;else&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Break;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;这样写有什么好处呢，想想你要关闭程序，在关闭的时候调用MyThread.Free，这个时候线程并没有马上结束，它调用WaitFor，等待 Execute执行完后才能释放。你的程序就必须等&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;秒以后才能关闭，受得了吗。如果像上面那样写，在程序关闭时，调用Free之后，它顶多再等一秒就 会关闭。为什么？答案得去线程类的Destroy中找，它会先调用Terminate方法，在这个方法里面它把Terminated设为True（仅此而 已，很多人以为是结束线程，其实不是）。请记住这一切是在主线程中操作的，所以和Execute是并行执行的。既然Terminated属性已为 Ture，那么在Execute中判断之后，当然就&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;Break&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;了，Execute执行完毕，线程类也正常释放。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;或者有人说，TThread可以设FreeOnTerminate属性为True，线程类就能自动释放。除非你的线程执行的任务很简单，不然，还是不要去理会这个属性，一切由你来操作，才能使线程更灵活强大。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;接下来的问题是如何使工作线程和主线程很好的通信，很多时候主线程必须得到工作线程的通知，才能做出响应。比如接收邮件，工作线程向服务器收取邮件，收取完毕之后，它得通知主线程收到多少封邮件，主线程才能弹出一个窗口通知用户。&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;在VCL中，我们可以用两种方法，一种是向主线程中的窗体发送消息，另一种是使用异步事件。第一种方法其实没有第二种来得方便。想想线程类中的OnTerminate事件，这个事件由线程函数的堆栈引起，却在主线程执行。&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;事实上，真正的线程函数是这个：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ThreadProc&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Thread: TThread)&lt;/span&gt;:&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Integer; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;函数里面有Thread.Execute，这就是为什么Execute是在其他线程中执行，该方法执行之后，有如下句： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Thread.DoTerminate; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;而线程类的DoTerminate方法里面是 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Assigned(FOnTerminate) &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Synchronize(CallOnTerminate); &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;显然Synchronize方法使得CallOnTerminate在主线程中执行，而CallOnTerminate里面的代码其实就是： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Assigned(FOnTerminate) &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; FOnTerminate(Self);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;只要Execute方法一执行完就发生OnTerminate事件。不过有一点是必须注意，OnTerminate事件发生后，线程类不一定会释 放，只有在FreeOnTerminate为True之后，才会Thread.Free。看一下ThreadProc函数就知道。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;依照Onterminate事件，我们可以设计自己的异步事件。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Synchronize方法只能传进一个无参数的方法类型，但我们的事件经常是要带一些参数的，这个稍加思考就可以得到解决，即在线程类中保存参数，触发事件前先设置参数，再调用异步事件，参数复杂的可以用记录或者类来实现。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;假设这样，上面的代码每睡一秒，线程即向外面引发一次事件，我们的类可以这样设计： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;TSecondEvent = &lt;/span&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Second: Integer)&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;of&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;object&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;TMyThread&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;(TThread)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;private&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecond: Integer;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecondEvent: TSecondEvent;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;CallSecondEvent&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;protected&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;procedure Execute; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;override&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;public&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;property SencondEvent: TSecondEvent &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; FSecondEvent&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;write FSecondEvent;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;{ TMyThread }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;CallSecondEvent&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;if Assigned(FSecondEvent) then&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecondEvent(FSecond);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Execute&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;var&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;i: Integer;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;for i := &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; do&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; Terminated then&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Sleep(&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecond := i;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Synchronize(CallSecondEvent);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;end&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;else&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Break;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;在主窗体中假设我们这样操作线程：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TForm1&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Button1Click&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender: TObject)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread := TMyThread.Create(true);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.OnTerminate := ThreadTerminate;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.SencondEvent := SecondEvent;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.Resume;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TForm1&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;ThreadTerminate&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender: TObject)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;ShowMessage(&lt;/span&gt;&lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&amp;#39;ok&amp;#39;&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TForm1&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;SecondEvent&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Second: Integer)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Edit1.Text := IntToStr(Second);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;我们将每隔一秒就得到一次通知并在Edit中显示出来。&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;现在我们已经知道如何正确使用Execute方法，以及如何在主线程与工作线程之间通信了。但问题还没有结束，有一种情况出乎我的意料之外，即如果 线程中有一些资源，Execute正在使用这些资源，而主线程要释放这个线程，这个线程在释放的过程中会释放掉资源。想想会不会有问题呢，两个线程，一个 在使用资源，一个在释放资源，会出现什么情况呢， &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;用下面代码来说明：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;type&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;TMyClass = class&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;private&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecond: Integer;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;public&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;procedure SleepOneSecond;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;TMyThread&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; = &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;(TThread)&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;private&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass: TMyClass;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;protected&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;procedure Execute; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;override&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;public&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;constructor MyCreate(CreateSuspended: Boolean);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;destructor&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Destroy&lt;/span&gt;;&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;override&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;implementation&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;{ TMyThread }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;constructor&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;MyCreate&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(CreateSuspended: Boolean)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;inherited Create(CreateSuspended);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass := TMyClass.Create;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;destructor&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Destroy&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass.Free;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass := &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;inherited&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyThread&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Execute&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;var&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;i: Integer;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;for i := &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; do&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass.SleepOneSecond;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;{ TMyClass }&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TMyClass&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;SleepOneSecond&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FSecond := &lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;Sleep(&lt;/span&gt;&lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;. &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;用下面的代码来调用上面的类：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TForm1&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Button1Click&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender: TObject)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread := TMyThread.MyCreate(true);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.OnTerminate := ThreadTerminate;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.Resume;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;procedure&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;TForm1&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;Button2Click&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Sender: TObject)&lt;/span&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;begin&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;MyThread.Free;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;end&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;先点击Button1创建一个线程，再点击Button2释放该类，出现什么情况呢，违法访问，是的，MyThread.Free时，MyClass被释放掉了 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass.Free;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FMyClass := &lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;而此时Execute却还在执行，并且调用MyClass的方法，当然就出现违法访问。对于这种情况，有什么办法来防止呢，我想到一种方法，即在线程类中使用一个成员，假设为FFinished，在Execute方法中有如下的形式： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt;FFinished := False; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;try&lt;/span&gt;&lt;span style=&quot;font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap; background-color: #FFFFFF;&quot;&gt; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;//... ...&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;finally &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;FFinished := True;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;End; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;接着在线程类的Destroy中有如下形式： &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;While not FFinished do &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;Sleep(100); &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.Free; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;这样便能保证MyClass能被正确释放。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;线程是一种很有用的技术。但使用不当，常使人头痛。在CSDN论坛上看到一些人问，我的窗口在线程中调用为什么出错，主线程怎么向其他线程发送消息等等，其实，我们在抱怨线程难用时，也要想想我们使用的方法对不对，只要遵循一些正确的使用规则，线程其实很简单。 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;后记 &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;上面有一处代码有些奇怪：FMyClass.Free; FMyClass := nil;如果你只写FMyClass.Free，线程类还不会出现异常，即调用FMyClass.SleepOneSecond不会出错。我在主线程中试了下面的代码&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass := TMyClass.Create;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.SleepOneSecond; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.Free; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.SleepOneSecond; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;同样也不会出错，但关闭程序时就出错了，如果是这样：&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass := TMyClass.Create;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.SleepOneSecond; &lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.Free;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyThread := TMyThread.MyCreate(true);&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyThread.OnTerminate := ThreadTerminate;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyThread.Resume;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;MyClass.SleepOneSecond;&lt;/span&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;br style=&quot;box-sizing: border-box; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;/&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;马上就出错。所以这个和线程类无线，应该是Delphi对于堆栈空间的释放规则，我想MyClass.Free之后，该对象在堆栈上空间还是保留 着，只是允许其他资源使用这个空间，所以接着调用下面这一句MyClass.SleepOneSecond就不会出错，当程序退出时可能对堆栈作一些清理 导致出错。而如果MyClass.Free之后即创建MyThread，大概MyClass的空间已经被MyThread使用，所以再调用 MyClass.SleepOneSecond就出错了。 &lt;/span&gt;&lt;/p&gt;</description><pubDate>Thu, 23 Sep 2021 17:37:01 +0800</pubDate></item><item><title>delphi 判断是否是Hash</title><link>https://ainn.wang/?id=3</link><description>&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-function&quot; style=&quot;box-sizing: border-box;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;hljs-title&quot; style=&quot;box-sizing: border-box; color: #A31515; font-weight: bold;&quot;&gt;IsHash&lt;/span&gt;&lt;span class=&quot;hljs-params&quot; style=&quot;box-sizing: border-box;&quot;&gt;(Hash: &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;String&lt;/span&gt;)&lt;/span&gt;:&lt;/span&gt; boolean;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;var&lt;/span&gt; i: integer;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;begin&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Result := false;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;if&lt;/span&gt; Hash = &lt;span class=&quot;hljs-string&quot; style=&quot;box-sizing: border-box; color: #A31515;&quot;&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;exit&lt;/span&gt;;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;if&lt;/span&gt; Length(Hash) = &lt;span class=&quot;hljs-number&quot; style=&quot;box-sizing: border-box; color: #880000;&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot; style=&quot;box-sizing: border-box; font-weight: bold; color: #0000FF;&quot;&gt;then&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;// possible base32 encoded hash&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hash:=StrToHex(Base32Decode(UpperCase(Hash)));&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; except&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; if Length(Hash) &amp;lt;&amp;gt; 40 then exit;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; Result := true;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;&amp;nbsp; &amp;nbsp; for i := 1 to 40 do if not (Hash[i] in [&amp;#39;a&amp;#39; .. &amp;#39;f&amp;#39;, &amp;#39;A&amp;#39;..&amp;#39;F&amp;#39;, &amp;#39;0&amp;#39;..&amp;#39;9&amp;#39;]) then Result := false;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; font-family: Menlo, Monaco, Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 16px; white-space: pre-wrap;&quot;&gt;&lt;span class=&quot;hljs-comment&quot; style=&quot;box-sizing: border-box; color: #008000;&quot;&gt;end;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 23 Sep 2021 17:36:01 +0800</pubDate></item></channel></rss>