user15050478
user15050478

Reputation:

Why am I getting an Invalid typecast error from this code?

function FileSize64(var F : File): Int64;
var
  ph :_stat;
  pl:longword;
begin
  pl := fstat(TFileRec(f).Handle, ph);
  if (pl = $ffffffff) and (GetLastError <> 0) then
    CreateIOException(GetLastError, 'FileSize64', f, false);
  FileSize64 := Int64(ph) shl 32 + pl;
end;

I am getting an error:

E2089 Invalid typecast

Upvotes: -1

Views: 135

Answers (1)

Check this solution:

  uses
    Posix.SysStat;

  function FileSize64(var F: File): Int64;
  var
    ph :_stat;
  begin
    if fstat(TFileRec(F).Handle, ph) <> 0 then
      RaiseLastOSError;
    result := ph.st_size;
  end;

Hint: In the next question, please inform which units are referenced in the uses list.

Upvotes: 2

Related Questions