Forum > Other

Reset makes program crash?!

(1/1)

Giuseppe RidinĂ²:
I'm using lazarus-0.9.1.4-20040419 under WinXP.
I faced with a problem related to files. The application (a kind of "Hallo World!" with one button) a button click function should read a file as binary (no text).
The function looks like this:


--- Code: ---procedure TForm1.ButtonClick(filename: String);
var
  fid: file of bytes;
begin
    AssignFile(fid,filename);
    Reset(fid);
...
...
--- End code ---
[/size]

At the Reset(fid) line the application crashes, ....... why?  :twisted:

Any suggestion will be appreciated.  :wink:

Giuseppe RidinĂ²:
Well. the code itself works good, but not always.
This is the code which gives the problem:

--- Code: ---AssignFile(fid1,filename1);
Reset(fid1);
if not IOresult=0 then
  MessageDlg('Origin file not found!',mtInformation, [mbOK],0)
else
  begin
    AssignFile(fid2,filename2);
    ReWrite(fid2);
    if not IOresult=0 then
      MessageDlg('Failed opening destination file!',mtInformation, [mbOK],0)
    else
      begin
        while not Eof(fid1) do
          begin
            Read(fid1,C);
            Write(fid2,C);
          end;
        CloseFile(fid2);
      end;
  end;
CloseFile(fid1);
--- End code ---
[/size]
This should be an dummy way to copy a file.
Variables filename1 and filename2 are strings containing the file names, respectively, of the origin file and the destination file.
It is compiled properly, but the problem arise when I give a wrong origin file name.
In such a situation MessageDlg('Origin file not found!',...) should pop up.
If I run the *.exe from windows explorer or a dos shell, this happens as aspected, but if I run the program from the IDE, no popup is shown and the program crashes!  :evil:

Marc:
Just a guess, Turn off IO checking {$I-} (if I remember it ok)  around your rewrite and reset

Navigation

[0] Message Index

Go to full version