Result Might be Undefined Warning IdGlobalProtocols.pas fixed

Giganews Newsgroups
Subject: Result Might be Undefined Warning IdGlobalProtocols.pas fixed
Posted by:  Len Umina (umi…@speakeasy.net)
Date: Sun, 6 Feb 2005

function GetGMTDateByName(const AFileName : String) : TDateTime;
{$IFDEF WINDOWS}
var LRec : TWin32FindData;
  LHandle : THandle;
  LTime : Integer;
{$ENDIF}
{$IFDEF LINUX}
var LRec : TStatBuf;
  LTime : Integer;
  LU : TUnixTime;
{$ENDIF}
begin
  Result := -1; //UMINA
  {$IFDEF DOTNET}
if System.IO.File.Exists(AFileName) then
    Result := System.IO.File.GetLastWriteTimeUtc(AFileName).ToOADate;
  {$ENDIF}
  {$IFDEF WINDOWS}
  LHandle := FindFirstFile(PChar(AFileName), LRec);
  if LHandle <> INVALID_HANDLE_VALUE then
  begin
    Windows.FindClose(LHandle);
    if (LRec.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
    begin
      FileTimeToDosDateTime(LRec.ftLastWriteTime, LongRec(LTime).Hi,
LongRec(LTime).Lo);
      Result := FileDateToDateTime(LTime);
    end;
  end;
  {$ENDIF}
  {$IFDEF LINUX}
  if stat(PChar(AFileName), LRec) = 0 then
  begin
    LTime := LRec.st_mtime;
    gmtime_r(@LTime, LU);
    Result := EncodeDate(LU.tm_year + 1900, LU.tm_mon + 1, LU.tm_mday) +
              EncodeTime(LU.tm_hour, LU.tm_min, LU.tm_sec, 0);
  end;
  {$ENDIF}
end;

Replies