我使用File -> New Unit
以下单元编译好......
unit CryptoUnit;
{$mode objfpc}{$H+}
interface
function Encrypt(key, plaintext:string):string;
function Decrypt(key, ciphertext:string):string;
implementation
uses
Classes, SysUtils, Blowfish;
function Encrypt(key, plaintext:string):string;
...
然而,这个有编译错误,因为它无法在第6行识别“异常”......
unit ExceptionUnit;
{$mode objfpc}{$H+}
interface
procedure DumpExceptionCallStack(E: Exception); // <--- problem
implementation
uses
Classes, SysUtils, FileUtil;
{ See http://wiki.freepascal.org/Logging_exceptions }
procedure DumpExceptionCallStack(E: Exception);
...
如果我假设在Exception
中定义了SysUtils
(我怎么知道?)我不能在uses SysUtils
之前放置interface
(编译器抱怨它期待interface
)
如何告诉编译器Exception
中定义了SysUtils
?
答案 0 :(得分:6)
您的单位使用的其他单位将在interface关键字之后引用,但在接口部分中的其他语句之前引用。
您的示例应采用以下形式:
unit ExceptionUnit;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil;
procedure DumpExceptionCallStack(E: Exception);
implementation
{ See http://wiki.freepascal.org/Logging_exceptions }
procedure DumpExceptionCallStack(E: Exception);