Page 1 of 1

TFindFile "Invalid argument to date encode"

PostPosted: November 10th, 2011, 2:07 am
by ina
Just received a bug report from MadExcept.

Code: Select all
exception class   : EConvertError
exception message : Invalid argument to date encode.

0045724a +016 XXX.exe SysUtils              ConvertError
0045b689 +021 XXX.exe SysUtils              EncodeDate
0045b815 +011 XXX.exe SysUtils              SystemTimeToDateTime
005a3345 +021 XXX.exe FindFile      777  +3 FileTimeToDateTime
005a4a84 +094 XXX.exe FindFile     1554  +8 TFindFile.DoFileMatch
005a4e41 +181 XXX.exe FindFile     1663 +22 TFindFile.SearchIn
005a4f93 +2d3 XXX.exe FindFile     1684 +43 TFindFile.SearchIn
005a4caf +043 XXX.exe FindFile     1631  +7 TFindFile.SearchForFiles
005a487c +02c XXX.exe FindFile     1490  +3 TSearchThread.Execute

disassembling:
00457234 public SysUtils.ConvertError (PCMAV.exe):  ; function entry point
00457234   push    ebx
00457235   mov     ebx, eax
00457237   mov     ecx, ebx
00457239   mov     dl, 1
0045723b   mov     eax, [$456ba8]
00457240   call    +$65af ($45d7f4)       ; SysUtils.Exception.CreateRes (XXX.exe)
00457240
00457245   call    -$52156 ($4050f4)      ; System.@RaiseExcept (XXX.exe)
00457245
0045724a > pop     ebx
0045724b   ret


The error line is at "Result := SystemTimeToDateTime(SystemTime);'

Full code of the function

Code: Select all
function FileTimeToDateTime(const FileTime: TFileTime): TDateTime;
var
  LocalFileTime: TFileTime;
  SystemTime: TSystemTime;
begin
  FileTimeToLocalFileTime(FileTime, LocalFileTime);
  FileTimeToSystemTime(LocalFileTime, SystemTime);
  Result := SystemTimeToDateTime(SystemTime); << error
end;


I never get this error message in my computer, so I wonder how to prevent this error in other computer?

Re: TFindFile "Invalid argument to date encode"

PostPosted: December 18th, 2011, 3:28 pm
by Kambiz
Is the date format identical on both computers?
You should consider localized format differences when converting a date, time, or number.