﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-射手的博客-随笔分类-Interface 接口的学习与运用</title><link>http://www.cnitblog.com/Archer/category/8227.html</link><description>学习Delphi,需要一个记录学习的博客,</description><language>zh-cn</language><lastBuildDate>Sun, 02 Oct 2011 01:46:15 GMT</lastBuildDate><pubDate>Sun, 02 Oct 2011 01:46:15 GMT</pubDate><ttl>60</ttl><item><title>接口的学习_(1)什么是接口与接口的构造,</title><link>http://www.cnitblog.com/Archer/archive/2009/04/13/56301.html</link><dc:creator>Archer</dc:creator><author>Archer</author><pubDate>Mon, 13 Apr 2009 03:19:00 GMT</pubDate><guid>http://www.cnitblog.com/Archer/archive/2009/04/13/56301.html</guid><wfw:comment>http://www.cnitblog.com/Archer/comments/56301.html</wfw:comment><comments>http://www.cnitblog.com/Archer/archive/2009/04/13/56301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Archer/comments/commentRss/56301.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Archer/services/trackbacks/56301.html</trackback:ping><description><![CDATA[<span  style="color: rgb(0, 0, 102); font-family: verdana; "><div class="posttitle" style="padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; "><br></div>&nbsp;<p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>Interface</span><span>接口<span>.</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>什么是接口<span>:</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>只声明方法<span>,</span>而不实现方法<span>.</span></span></p><div><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>简单的说<span>,</span>接口就是包含一系列不被实现的方法<span>.</span>而把这些方法的实现交给继承它的类<span>.</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; background-color: yellow; "><span>继承了此接口的类必须去实现接口中的每一个方法<span>.</span>既需要实现接口中的全部方法<span>.</span></span></p></div><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>接口与类很相似<span>.</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>&nbsp;</span><span style="background-color: yellow; ">接口只能在程序或单元的最外层声明,</span>而不能再过程或函数中声明.</p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>type interfaceName = interface (ancestorInterface)</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>&nbsp;['{GUID}'] &nbsp;//</span><span>接口标识</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>&nbsp;memberList &nbsp;//</span><span>方法列表</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>end;</span></p><div><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>ancestorInterface (</span><span>祖先类<span>)</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>&nbsp;</span><span>接口和类一样<span>,</span>继承它祖先的所有方法<span>.</span>但接口不象类那样去实现这些方法<span>.</span>他把这些方法的实现委托给支持此接口的类<span>.</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>声明一个接口时可以指定一个祖先接口，如果没有指明的话，则它直接继承自<span>&nbsp;IInterface</span>。<span>IInterface&nbsp;</span>在<span>System&nbsp;</span>单元定义，是其它所有接口的根类。<span>IInterface&nbsp;</span>定义了三个方法：<span>QueryInterface</span>、<span>_AddRef&nbsp;</span>和<span>_Release</span>。</span></p></div><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; ">&nbsp;</p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>对于<span>memberlist&nbsp;</span>我们需要注意</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; ">1.<span style="background-color: yellow; ">memberList只包括方法和属性，字段在接口中是不允许的；</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>2.</span><span>因为接口没有字段，所以属性的读（<span>read</span>）和写（<span>write</span>）限定符必须是<span style="background-color: yellow; ">方法</span>；<span></span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>3.</span><span>接口的所有成员都是公有的（<span>public</span>）</span><span>&nbsp;，不允许使用可见性限定符和存储限定符（但一个数组属性能被声明为<span>&nbsp;default</span>） ；<span></span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>4.</span><span>接口没有构造函数和析构函数，它们不能被（直接）实例化，除非使用实现了它们（的方法）的类；<span>&nbsp;</span></span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>5.</span><span>方法不能被声明为<span>&nbsp;virtual</span>、<span>dynamic</span>、<span>abstract</span>或<span>&nbsp;override</span>。因为接口自己不实现它们的方法，这些声明没有意义<span>.</span></span></p><div><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>接口标志<span>[GUID]:</span></span><span>&nbsp;</span><span>一个全局唯一标识符（<span>GUID</span>）<span>,</span>它用一个被中括号括起来的字符串表示，它出现在接口的成员之前。使用<span>Ctrl+Shift+G&nbsp;</span>自动创建</span></p></div>&nbsp;<p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>接口调用约定</span><span>(Calling conventions for interfaces):</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>&nbsp;</span><span>在接口中虽然不能使用</span><span>&#8221;</span><span>方法绑定</span><span>&#8221;,</span><span>但是可以使用调用约定</span><span>.</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>默认的调用约定是</span><span>register ,</span><span>如果你的程序或程序模块需要共享例程时</span><span>,</span><span>可以使用</span><span>stdcall&nbsp;</span><span>调用约定</span><span>.</span><span>也可以根据实际情况调用其他的约定</span><span>.</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; ">&nbsp;</p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>接口属性</span><span>(Interface properties):</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>接口声明的属性只能通过<span style="background-color: yellow; ">接口类型的表达式</span>进行访问，类类型的变量不行；</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>并且，接口的属性只在接口被编译的程序中是可见的</span><span>。</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>Forward declarations</span><span>（</span><span>Forward(</span><span>前瞻性</span><span>)&nbsp;</span><span>声明）</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>若声明一个接口时以</span><span>&nbsp;interface&nbsp;</span><span>关键字和一个分号结束，没有指定它的祖先、</span><span>GUID&nbsp;</span><span>以及成员列表，这是一个</span><span>&nbsp;forward&nbsp;</span><span>声明。</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>Forward&nbsp;</span><span>声明的接口必须在同一个声明区域进行定义声明，换句话说，<span>在</span></span><span>&nbsp;forward&nbsp;</span><span>声明和它的定义声明之间除了类型声明外，不能有任何其它内容。</span><span>.</span></p><p style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; "><span>相互继承（派生）的接口是不允许的</span><span>.</span></p></span>
<img src ="http://www.cnitblog.com/Archer/aggbug/56301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Archer/" target="_blank">Archer</a> 2009-04-13 11:19 <a href="http://www.cnitblog.com/Archer/archive/2009/04/13/56301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过"委托属性"实现接口_委托接口属性实现接口</title><link>http://www.cnitblog.com/Archer/archive/2009/04/13/56299.html</link><dc:creator>Archer</dc:creator><author>Archer</author><pubDate>Mon, 13 Apr 2009 03:17:00 GMT</pubDate><guid>http://www.cnitblog.com/Archer/archive/2009/04/13/56299.html</guid><wfw:comment>http://www.cnitblog.com/Archer/comments/56299.html</wfw:comment><comments>http://www.cnitblog.com/Archer/archive/2009/04/13/56299.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Archer/comments/commentRss/56299.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Archer/services/trackbacks/56299.html</trackback:ping><description><![CDATA[<span  style="color: rgb(0, 0, 102); font-family: verdana; "><div class="posttitle" style="padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; "><br></div><p align="left" style="font-size: small; color: rgb(0, 0, 0); padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; word-wrap: break-word; ">&nbsp;<br>&nbsp;&nbsp; implements 指示字允许你在"实现类"中委托一个属性来实现接口.<br>&nbsp;&nbsp;&nbsp; property MyInterface: IMyInterface read FMyInterface implements IMyInterface;&nbsp;&nbsp;<br>&nbsp;&nbsp; implements 指示字必须是最后一项，它可以实现多个接口，接口之间以逗号分隔。<br>------------------------<br>&nbsp;委托的属性要满足以下条件：<br>&nbsp; &nbsp;&#8226;&nbsp;&nbsp;<span style="background-color: rgb(255, 255, 0); ">必须是类或接口类型 {<span style="color: red; ">也就是说:实现接口属性分2种,一种是使用类类型实现接口,一种是使用接口类型实现接口</span>}；&nbsp;<br></span>&nbsp; &nbsp;&#8226;&nbsp; 不能是数组属性，也不能使用 index限定符；&nbsp;<br>&nbsp;&nbsp; &#8226;&nbsp;&nbsp;<span style="background-color: rgb(255, 255, 0); ">必须有一个读限定符<span style="color: red; ">(Read 通常都是类或者接口的变量</span>)。</span>若属性使用 read方法，则方法必须使用默认的 register 调用约定，并且不能<br>&nbsp; 是动态方法（但可以是虚方法） ，也不能使用 message 指示字。<br>&nbsp;注:最后都是用来实现接口的.<br>-------------------------<br>Delegating to an interface-type property（委托一个接口类型的属性）<br>&nbsp;&nbsp;&nbsp; 如果委托的属性是接口类型，那么此接口（或者它的派生接口）<span style="background-color: rgb(255, 255, 0); ">必须出现在类声明中的祖先列表中（也就是声明实现这些接口）</span>&nbsp;。</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color: rgb(255, 255, 0); ">委托的属性必须返回一个对象(<span style="color: red; ">Read标志符必须是接口,然后通过此接口返回一个实现了此接口的类</span>)，此对象所属的类完全实现了 implements 所指明的接口，</span>并且没有使用方法解析子句。<br><span style="color: red; background-color: rgb(255, 255, 0); ">&nbsp;&nbsp;&nbsp; 接口属性的一个特点: 属性标识符.读方法&nbsp;都是属于接口类型的..<br></span><br><div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 973px; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); ">&nbsp;1<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">type&nbsp;IMyInTerFace&nbsp;=&nbsp;interface(Iinterface)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;接口类型<br>&nbsp;2<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br>&nbsp;3<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;P1;<br>&nbsp;4<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;p2;<br>&nbsp;5<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;end;<br>&nbsp;6<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">type&nbsp;TmpInTerFace&nbsp;=&nbsp;class(TInterfacedObject,&nbsp;IMyInTerFace)&nbsp;&nbsp;&nbsp;//实现接口的类<br>&nbsp;7<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;constructor&nbsp;create;<br>&nbsp;8<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;P1;<br>&nbsp;9<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;p2;<br>10<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;end;<br>11<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">type&nbsp;TImplements&nbsp;=&nbsp;class(TInterfacedObject,&nbsp;IMyInTerFace)&nbsp;&nbsp; //委托属性的类<br>12<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;protected<br>13<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;FMInTerFace:&nbsp;IMyInTerFace;<br>14<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;property&nbsp;MyInTerFace:&nbsp;IMyInTerFace&nbsp;read&nbsp;FMInTerFace&nbsp;implements&nbsp;IMyInTerFace;<br>15<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;end;<br>16<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br>17<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TmpInTerFace.P1;<br>18<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br>19<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;ShowMessage('P1');<br>20<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br>21<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br>22<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TmpInTerFace.p2;<br>23<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br>24<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;ShowMessage('P2');<br>25<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br>26<br>27<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br>28<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">var<br>29<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;TImp:TImplements;&nbsp;//实现委托属性类<br>30<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;InTet:IMyInTerFace;&nbsp;//接口 {接口没有构造函数和析构函数，它们不能被（直接）实例化，除非使用实现了它们（的方法）的类}<br>31<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;TnTerImp:TmpInTerFace;&nbsp;&nbsp;//实现接口类的对象<br>32<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br>33<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;TImp:=TImplements.Create;<br>34<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;<span style="background-color: yellow; ">TnTerImp:=TmpInTerFace.create;</span>&nbsp; //&nbsp;变量初始化.注意只有这样才能赋值.<br>35<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;Timp.FMInTerFace:=TnTerImp;&nbsp; //也可以直接忽略TnTerImp变量而直接使用Timp.FMInTerFace:=TmpInTerFace.Create.<br>36<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;InTet:=TImp;<br>37<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;InTet.P1;<br>38<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br>39<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br>40<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end.<br>41<img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "></div></span>
<img src ="http://www.cnitblog.com/Archer/aggbug/56299.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Archer/" target="_blank">Archer</a> 2009-04-13 11:17 <a href="http://www.cnitblog.com/Archer/archive/2009/04/13/56299.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过"委托属性"实现接口_委托类类型属性实现接口</title><link>http://www.cnitblog.com/Archer/archive/2009/04/13/56298.html</link><dc:creator>Archer</dc:creator><author>Archer</author><pubDate>Mon, 13 Apr 2009 03:16:00 GMT</pubDate><guid>http://www.cnitblog.com/Archer/archive/2009/04/13/56298.html</guid><wfw:comment>http://www.cnitblog.com/Archer/comments/56298.html</wfw:comment><comments>http://www.cnitblog.com/Archer/archive/2009/04/13/56298.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Archer/comments/commentRss/56298.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Archer/services/trackbacks/56298.html</trackback:ping><description><![CDATA[<span  style="color: rgb(0, 0, 102); font-family: verdana; "><div class="posttitle" style="padding-top: 5px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; "><br></div>如果"委托属性"是一个 类类型 .<br><span style="background-color: yellow; ">那么在定位实现的方法时,</span><span style="background-color: yellow; ">会先搜索这个类以及它的祖先类(委托属性的类),然后再搜索当前类（也就是定义属性的类）以及它的祖先类。</span>所以，可以在属性指定的类中实现某些方法，而另一些方法在当前类实现。<br>可以象平常一样使用方法解析子句来避免含糊的声明，或者（只是）使用一个特别的方法声明。一个接口不能委托给多个类类型的属性实现。<br>&nbsp;委托属性是类类型特点是:属性名标识符和Read 都是属于类类型而不是接口类型.<br><div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 973px; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); "><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">type&nbsp;<br>&nbsp; IMyInterface = interface //接口类型<br>&nbsp;&nbsp;&nbsp; procedure P1;<br>&nbsp;&nbsp;&nbsp; procedure P2;<br>&nbsp; end;<br>&nbsp;&nbsp;<span style="background-color: yellow; ">TMyImplClass</span>&nbsp;= class&nbsp;&nbsp;&nbsp; //类类型<br>&nbsp;&nbsp;&nbsp; procedure P1;<br>&nbsp;&nbsp;&nbsp; procedure P2;<br>&nbsp; end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;TMyClass&nbsp;=&nbsp;class(TInterfacedObject,&nbsp;IMyInterface)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">FMyImplClass</span>:&nbsp;<span style="background-color: yellow; ">TMyImplClass</span>; //类类型变量<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;property&nbsp;MyImplClass:&nbsp;<span style="background-color: yellow; ">TMyImplClass</span>&nbsp;&nbsp;read&nbsp;<span style="color: red; ">FMyImplClass</span>&nbsp;implements<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">IMyInterface;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;IMyInterface.P1&nbsp;=&nbsp;MyP1; //方法别名<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;procedure&nbsp;MyP1;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">implementation<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img id="Codehighlighter1_257_266_Open_Image" onclick="this.style.display='none'; Codehighlighter1_257_266_Open_Text.style.display='none'; Codehighlighter1_257_266_Closed_Image.style.display='inline'; Codehighlighter1_257_266_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img id="Codehighlighter1_257_266_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_257_266_Closed_Text.style.display='none'; Codehighlighter1_257_266_Open_Image.style.display='inline'; Codehighlighter1_257_266_Open_Text.style.display='inline';" height="16" src="http://www.cnitblog.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img src="http://www.cnitblog.com/Images/dot.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">{$R&nbsp;*.dfm}<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img id="Codehighlighter1_269_284_Open_Image" onclick="this.style.display='none'; Codehighlighter1_269_284_Open_Text.style.display='none'; Codehighlighter1_269_284_Closed_Image.style.display='inline'; Codehighlighter1_269_284_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img id="Codehighlighter1_269_284_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_269_284_Closed_Text.style.display='none'; Codehighlighter1_269_284_Open_Image.style.display='inline'; Codehighlighter1_269_284_Open_Text.style.display='inline';" src="http://www.cnitblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img src="http://www.cnitblog.com/Images/dot.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">{&nbsp;TMyImplClass&nbsp;}<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TMyImplClass.P1;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;ShowMessage('TMyImplClass.P1');<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TMyImplClass.P2;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;ShowMessage('TMyImplClass.P2');<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img id="Codehighlighter1_431_442_Open_Image" onclick="this.style.display='none'; Codehighlighter1_431_442_Open_Text.style.display='none'; Codehighlighter1_431_442_Closed_Image.style.display='inline'; Codehighlighter1_431_442_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img id="Codehighlighter1_431_442_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_431_442_Closed_Text.style.display='none'; Codehighlighter1_431_442_Open_Image.style.display='inline'; Codehighlighter1_431_442_Open_Text.style.display='inline';" src="http://www.cnitblog.com/Images/OutliningIndicators/ContractedBlock.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><img src="http://www.cnitblog.com/Images/dot.gif" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">{&nbsp;TMyClass&nbsp;}<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TMyClass.MyP1;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;ShowMessage('TMyClass.MyP1');<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">procedure&nbsp;TForm1.btn1Click(Sender:&nbsp;TObject);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">var&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyClass:&nbsp;TMyClass;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyInterface:&nbsp;IMyInterface;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">begin&nbsp;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyClass&nbsp;:=&nbsp;TMyClass.Create;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; "><span style="background-color: yellow; ">&nbsp;&nbsp;MyClass.<span style="color: red; ">FMyImplClass</span>&nbsp;:=&nbsp;TMyImplClass.Create;&nbsp; //委托属性创建(实例化)&nbsp;<br></span><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyInterface&nbsp;:=&nbsp;MyClass;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyInterface.P1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;调用&nbsp;TMyClass.MyP1;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">&nbsp;&nbsp;MyInterface.P2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;调用&nbsp;TImplClass.P2;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; ">end;</div></span>
<img src ="http://www.cnitblog.com/Archer/aggbug/56298.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Archer/" target="_blank">Archer</a> 2009-04-13 11:16 <a href="http://www.cnitblog.com/Archer/archive/2009/04/13/56298.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>接口的初次利用.</title><link>http://www.cnitblog.com/Archer/archive/2009/04/07/56094.html</link><dc:creator>Archer</dc:creator><author>Archer</author><pubDate>Tue, 07 Apr 2009 08:33:00 GMT</pubDate><guid>http://www.cnitblog.com/Archer/archive/2009/04/07/56094.html</guid><wfw:comment>http://www.cnitblog.com/Archer/comments/56094.html</wfw:comment><comments>http://www.cnitblog.com/Archer/archive/2009/04/07/56094.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/Archer/comments/commentRss/56094.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/Archer/services/trackbacks/56094.html</trackback:ping><description><![CDATA[
&nbsp;此次接口的利用当中练习到了: <br>&nbsp;&nbsp; 1.利用对接口的实现.2.对接口方法在类中改名(方法别名).3.异常的利用.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EConvertError 异常.<font size="2">当试图用转换函数把数据从一种形式转换为另一种形式时引发,特别是当把一个字符串转换为数值时引发。<br>
</font><div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 98%; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); "><font size="2"><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;ITest&nbsp;=interface&nbsp;(Iinterface)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;['{5578FA85-1544-4B49-8DE2-5ABC4AE261B3}']<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;function&nbsp;MathTest(Value:Integer;var&nbsp;Str:string):Boolean;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;TypeTest&nbsp;=&nbsp;class(TInterfacedObject,ITest)<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;</font><span style="BACKGROUND-COLOR: yellow">function&nbsp;<span style="COLOR: red">MathValue</span>(Value:Integer;var&nbsp;Str:string):Boolean; 在类中实现接口方法的函数名称.<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;&nbsp;function&nbsp;ITest.MathTest&nbsp;=<span style="COLOR: red">MathValue</span>;&nbsp;&nbsp; //实现在此类中的方法别名</span><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;&nbsp;end;</div>
<div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 98%; word-break: break-all; padding-top: 4px; height: 150px; background-color: rgb(238, 238, 238); "><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"><span style="COLOR: #000000">function&nbsp;TypeTest.MathValue(Value:&nbsp;Integer;var&nbsp;Str:</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">):&nbsp;Boolean;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">begin<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;Str:</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">IntToStr(Value);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">&nbsp;Str&nbsp;</span><span style="COLOR: #000000">&lt;&gt;</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">''</span><span style="COLOR: #000000">&nbsp;then<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;Result:</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">True<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;</span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;raise&nbsp;EConvertError.Create(</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">请输入正常的值</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">end;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"></span></div>
<div style="padding-right: 5px; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left-color: rgb(204, 204, 204); width: 98%; word-break: break-all; padding-top: 4px; background-color: rgb(238, 238, 238); "><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top"><span style="COLOR: #000000">procedure&nbsp;TForm1.btn1Click(Sender:&nbsp;TObject);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">var<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;Math:TypeTest;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;S:</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">begin<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;Math:</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">TypeTest.Create;<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;Math.MathValue(</span><span style="COLOR: #000000">123456789</span><span style="COLOR: #000000">,S);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">&nbsp;ShowMessage(S);<br><img src="http://www.cnitblog.com/Images/OutliningIndicators/None.gif" align="top">end;</span></div>
<br>注意: 如果需要在类中对接口函数使用"别名".那么就要使用"别名"来实现例程.<br>&nbsp; <img src ="http://www.cnitblog.com/Archer/aggbug/56094.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/Archer/" target="_blank">Archer</a> 2009-04-07 16:33 <a href="http://www.cnitblog.com/Archer/archive/2009/04/07/56094.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>