6

を使用して、アプリのソース コードを Pascal コンパイル ユニットに整理します。File -> New Unit

次の 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ですか?

4

1 に答える 1

6

ユニットで使用される他のユニットは、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); 
于 2013-08-23T20:39:40.650 に答える