我将应用程序的源代码组织到Pascal编译单元中 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;
...
Run Code Online (Sandbox Code Playgroud)
但是这个有编译错误,因为它无法识别第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);
...
Run Code Online (Sandbox Code Playgroud)
如果我认为这Exception是定义的SysUtils(我怎么能告诉?)我不能放在uses SysUtils之前interface(编译器抱怨它期待interface)
如何告诉Exception定义的编译器SysUtils?
您的单元使用的其他单元将在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);
Run Code Online (Sandbox Code Playgroud)