Syntax Lazarus Pascal程序的语法规则;“单位”;

Syntax Lazarus Pascal程序的语法规则;“单位”;,syntax,lazarus,Syntax,Lazarus,我使用File->newunit 以下单元编译OK 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

我使用
File->newunit

以下单元编译OK

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);      
...
单元例外单元;
{$mode objfpc}{$H+}
接口

过程DumpExceptionCallStack(E:Exception);// 单元使用的其他单元将在interface关键字之后引用,但在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); 

我认为您需要将
uses SysUtils
行放在
接口
行之后(即不放在它前面)。