Talk:FileRead (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

I think probably you should check if FileOpen return valid handle - according to help it should be 0 or higher value, so instead:

 ...
 begin
   try
     iFileHandle := SysUtils.FileOpen(OpenDialog1.FileName, fmOpenRead);
 ...

Maybe the better way would be:

 ...
 begin
   iFileHandle := SysUtils.FileOpen(OpenDialog1.FileName, fmOpenRead);
   if iFileHandle >= 0 then
   try
 ...

Many sources on the web shows incorrect use of FileOpen either by storing FileOpen result in THandle (which is unsigned Integer) or by checking if returned file handle is > 0