Ver Mensaje Individual
  #1  
Antiguo 21-02-2007
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 23
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Una Pregunta Teórica sobre Archivos UDT

Hola:

El siguiente programa funciona correctamente:

Código Delphi [-]
 
program TestFile;
{$APPTYPE CONSOLE}
uses
  SysUtils, StrUtils;
Type
TPrnCmd = Record
   ProcPrnCmd : array [0..40] of char;
   DatePrnCmd : array [0..12] of char;
   TimePrnCmd : array [0..12] of char;
   Status : array [0..30] of char;
   CRLF : array [0..1] of char;
end;
var
   i : integer;
   RegPrnCmd : TPrnCmd;
function LogPrnCmd(LogFile, ProcPrnCmd, StatusProc : String) : Boolean;
var
   i : integer;
   f: File of TPrnCmd;
   // RegPrnCmd : TPrnCmd;
   DateProc : String;
begin
   LogFile := GetCurrentDir + '\' + LogFile;
   AssignFile(f, LogFile);
   FileMode := fmOpenWrite ;
   if FileExists(LogFile) then
      Reset(f)
   else
      Rewrite(f);
   DateProc := FormatDateTime('dd/mm/yyyy',Date);
   StrPCopy(RegPrnCmd.ProcPrnCmd,ProcPrnCmd);
   StrPCopy(RegPrnCmd.DatePrnCmd,MidStr(DateProc,7,4) + '-' + MidStr(DateProc,4,2) + '-' + MidStr(DateProc,1,2));
   StrPCopy(RegPrnCmd.TimePrnCmd,FormatDateTime('hh:mm:ss',Time));
   StrPCopy(RegPrnCmd.Status,StatusProc);
   StrPCopy(RegPrnCmd.CRLF,chr(13)+chr(10));

   Seek(f, FileSize(f));
   Write(f,RegPrnCmd);
   CloseFile(f);
end;
begin
   for i := 1 to 10 do
      LogPrnCmd('TestFile.txt','Proc'+IntToStr(i),'Status'+IntToStr(i));
end.

La estructura UDT RegPrnCmd : TPrnCmd, esta definida a nivel global, y esta en la function LogPrnCmd, pero como comentario. Si se comenta la que esta a nivel global (RegPrnCmd) y se usa a nivel local, eliminando los carácteres de comentario, el programa da el error: "Project TestFile.exe raised exception class EInOutError with message I/O error 6. Process Stopped. Use Step or Run to continue.

La pregunta es: ¿Por que funciona si la declaración de RegPrnCmd, es a nivel global y falla si es declarada a nivel local?

Como dije anteriormente es una pregunta teórica, el programa ya funciona pero me gustaría aclarar la duda.

Gracias de antemano por toda la colaboración prestada.
Responder Con Cita