Line 91 appears to be
Reset(f);
so it is not clear why you include the comment about line 93.
However, if you are getting an error on Reset(f)
, the cause must be something you have not told us in your q. To see why, please follow the steps below carefully.
Note: The reason for basing the call to FileSize
in my code on the copy of the compiled EXE is so that the file is guaranted to exist but is not the EXE itself, because when the EXE is running it cannot by opened in a shareable mode, so attempting to call Reset
on it would fail.
Compile (but do not run yet) the console app below.
Copy the resulting exe to a file in the same directory, but with the extension '.BU' rather than '.EXE' is that attempting Reset
on the EXE itself will result in a RunError(5)
, which means "Access denied", because when the EXE is opened by the OS it isn't opened in a shareable mode.
Now run the app. It should correctly report the size of the .BU file.
Assuming the EXE works as predicted, you need to identify where your error is coming from. My first guess would be that the instance of FileSize
isn't the one in the System unit - my code calls System.FileSize
to ensure that the correct instance of FileSize gets invoked. You can check that by changing your code to TotalBytes := System.FileSize(...
- if the error goes away, you've found the cause.
Code:
program Files2;
{$mode objfpc}{$H+}
uses
SysUtils;
var
TotalBytes : Int64;
f : file of byte;
FileName : String;
begin
FileName := ChangeFileExt(ParamStr(0), '.BU'); // get name of this app
AssignFile(f, FileName);
Reset(f);
try
TotalBytes := System.FileSize(f);
writeln('Size of ', FileName, ' = ', TotalBytes, ' bytes');
readln;
finally
CloseFile(f);
end;
end.