Recent

Author Topic: Reset makes program crash?!  (Read 5589 times)

Giuseppe Ridinò

  • Full Member
  • ***
  • Posts: 130
Reset makes program crash?!
« on: May 07, 2004, 08:46:26 pm »
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: [Select]
procedure TForm1.ButtonClick(filename: String);
var
  fid: file of bytes;
begin
    AssignFile(fid,filename);
    Reset(fid);
...
...
[/size]

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

Any suggestion will be appreciated.  :wink:

Giuseppe Ridinò

  • Full Member
  • ***
  • Posts: 130
Reset makes program crash?!
« Reply #1 on: May 13, 2004, 07:30:10 pm »
Well. the code itself works good, but not always.
This is the code which gives the problem:
Code: [Select]
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);
[/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

  • Administrator
  • Hero Member
  • *
  • Posts: 2582
Reset makes program crash?!
« Reply #2 on: May 18, 2004, 10:59:18 am »
Just a guess, Turn off IO checking {$I-} (if I remember it ok)  around your rewrite and reset
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

 

TinyPortal © 2005-2018