2011-05-12 24 views
6

Intenté con Delphi XE y obtuve No Respondiendo mientras compilaba. ¿Funciona en su computadora o hay algún problema con la función?¿No responde al compilar esta función?

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; 
+0

Esa función compila bien en mi Delphi 2010. –

Respuesta

11

Se compila en mi computadora. Aunque recibo la advertencia W1036, la variable 'IsAllowed' podría no haberse inicializado.

Actualización: Puedo reproducir el hang cuando incluyo Windows en la cláusula uses. Subordinado a 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. 

Parece un error; debe informarlo en el Quality Central.

Actualización 2: Mínimo caso que cuelga de forma reproducible el compilador:

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; 
+0

Sí, creo que hay una posibilidad de que * puede * no se ha inicializado también! –

+0

Puedo compilarlo si hago un comentario 'DeleteFile (FileName);' o 'result: = true;'. ¿Cuál es la versión de su Delphi XE? – user

+0

Sí, Windows en la cláusula uses es el creador de problemas. Intento comentar 'Windows' y puedo compilar la función. – user

Cuestiones relacionadas