Delphi出现“Unsatisfied forward or external declaration”错误分析
<p><span style="font-family: 宋体"> 今天在操作与“汉字转拼音”有关的程序编写时,总是提示“Unsatisfied forward or external declaration”错误,最终发现是如下原因造成的:</span></p><p><span style="font-family: 宋体">type<br> TForm1 = class(TForm)<br> ...<br> function GetPYIndexChar(hzchar:string):char; <span style="color: rgba(0, 0, 255, 1)">//函数声明</span></span></p>
<p><span style="font-family: 宋体"> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;</span></p>
<p><span style="font-family: 宋体">var<br> Form1: TForm1;</span></p>
<p><span style="font-family: 宋体">implementation</span></p>
<p><span style="font-family: 宋体">{$R *.dfm}</span></p>
<p><span style="font-family: 宋体">// 获取指定汉字的拼音索引字母函数,如:“汉”的索引字母是“H”<br>function GetPYIndexChar(hzchar:string):char; <span style="color: rgba(255, 0, 0, 1)"><strong>//Error,出错了!<br></strong></span> begin<br> case WORD(hzchar) shl 8 + WORD(hzchar) of<br> $B0A1..$B0C4 : result := 'A';<br> $B0C5..$B2C0 : result := 'B';<br> $B2C1..$B4ED : result := 'C';<br> $B4EE..$B6E9 : result := 'D';<br> $B6EA..$B7A1 : result := 'E';<br> $B7A2..$B8C0 : result := 'F';<br> $B8C1..$B9FD : result := 'G';<br> $B9FE..$BBF6 : result := 'H';<br> $BBF7..$BFA5 : result := 'J';<br> $BFA6..$C0AB : result := 'K';<br> $C0AC..$C2E7 : result := 'L';<br> $C2E8..$C4C2 : result := 'M';<br> $C4C3..$C5B5 : result := 'N';<br> $C5B6..$C5BD : result := 'O';<br> $C5BE..$C6D9 : result := 'P';<br> $C6DA..$C8BA : result := 'Q';<br> $C8BB..$C8F5 : result := 'R';<br> $C8F6..$CBF9 : result := 'S';<br> $CBFA..$CDD9 : result := 'T';<br> $CDDA..$CEF3 : result := 'W';<br> $CEF4..$D188 : result := 'X';<br> $D1B9..$D4D0 : result := 'Y';<br> $D4D1..$D7F9 : result := 'Z';<br> else result := char(0);<br> end; //结束Case<br> end; //结束GetPYIndexChar函数</span></p>
<p><span style="font-family: 宋体"><span style="color: rgba(0, 128, 255, 1)">分析:其实错误原因很简单,Delphi的函数声明与实现部分并非完全一样的,因为Delphi的实现部分中要加<br>入本函数归谁所有,因此改后代码如下:</span><br>type<br> TForm1 = class(TForm)<br> ...<br> function GetPYIndexChar(hzchar:string):char; //函数声明</span></p>
<p><span style="font-family: 宋体"> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;</span></p>
<p><span style="font-family: 宋体">var<br> Form1: TForm1;</span></p>
<p><span style="font-family: 宋体">implementation</span></p>
<p><span style="font-family: 宋体">{$R *.dfm}</span></p>
<p><span style="font-family: 宋体">// 获取指定汉字的拼音索引字母函数,如:“汉”的索引字母是“H”<br>function <span style="color: rgba(0, 0, 255, 1)"><strong>TForm1.</strong></span>GetPYIndexChar(hzchar:string):char; <span style="color: rgba(0, 0, 255, 1)">//只需加个TForm1就OK了呵呵!<br></span> begin<br> case WORD(hzchar) shl 8 + WORD(hzchar) of<br> $B0A1..$B0C4 : result := 'A';<br> $B0C5..$B2C0 : result := 'B';<br> $B2C1..$B4ED : result := 'C';<br> $B4EE..$B6E9 : result := 'D';<br> $B6EA..$B7A1 : result := 'E';<br> $B7A2..$B8C0 : result := 'F';<br> $B8C1..$B9FD : result := 'G';<br> $B9FE..$BBF6 : result := 'H';<br> $BBF7..$BFA5 : result := 'J';<br> $BFA6..$C0AB : result := 'K';<br> $C0AC..$C2E7 : result := 'L';<br> $C2E8..$C4C2 : result := 'M';<br> $C4C3..$C5B5 : result := 'N';<br> $C5B6..$C5BD : result := 'O';<br> $C5BE..$C6D9 : result := 'P';<br> $C6DA..$C8BA : result := 'Q';<br> $C8BB..$C8F5 : result := 'R';<br> $C8F6..$CBF9 : result := 'S';<br> $CBFA..$CDD9 : result := 'T';<br> $CDDA..$CEF3 : result := 'W';<br> $CEF4..$D188 : result := 'X';<br> $D1B9..$D4D0 : result := 'Y';<br> $D4D1..$D7F9 : result := 'Z';<br> else result := char(0);<br> end; //结束Case<br> end; //结束GetPYIndexChar函数</span></p>
</div>
<div id="MySignature" role="contentinfo">
好的代码像粥一样,都是用时间熬出来的<br><br>
来源:https://www.cnblogs.com/jijm123/p/14213815.html
頁:
[1]