编译此功能时没有响应?

时间:2011-05-12 09:17:27

标签: delphi compilation delphi-xe

我尝试使用Delphi XE编译时没有响应。它是否适用于您的计算机或该功能有问题?

function Test(const FileName: string;
  const Force: boolean = false): boolean;
var
  IsAllowed: boolean;
begin
  result := false;
  if FileExists(FileName) then
  begin
    try
      if (Force) then
      begin
        result := false;
        exit;
      end;
    finally
      if IsAllowed then
        DeleteFile(FileName);
    end;

    try
      result := true;
    except
      result := false;
    end;
  end;
end;

1 个答案:

答案 0 :(得分:11)

它在我的电脑上编译。虽然我收到警告W1036变量'IsAllowed'可能尚未初始化。

更新:当我在uses子句中包含Windows时,我可以重现挂起。 提交给Quality Central:QC93806

program hang_test;

{$APPTYPE CONSOLE}

uses
  // Windows, // uncomment to include Windows -> hang on compile
  SysUtils;

function Test(const FileName: string; const Force: boolean = false): boolean;
  // your function here

begin
  try

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

它看起来像一个bug;您应该在Quality Central

中报告

更新2:可重复挂起编译器的最小情况:

function HangCompiler: Boolean;
begin
  try
    Exit; // 1. exit from a try..finally
  finally
    DeleteFile(''); // 2. inlined function call in finally (include Windows to inline)
  end;
  // 3. try..except
  try
    Result := True;
  except
    Result := False;
  end;
end;