Results 1 to 9 of 9

Thread: IO Error.

  1. #1

    IO Error.

    Hello,

    I tried this code and Delphi 2006 gave me an IO Error 104:

    [pascal]procedure TForm1.Button1Click(Sender: TObject);
    var test1: TextFile;
    var rtext: System.string;
    begin
    AssignFile(test1, 'C:\test.txt');
    ReWrite(test1);
    while not Eof(test1) do
    begin
    ReadLn(test1, rtext);
    ShowMessage(rtext);
    CloseFile(test1);
    end;
    end;[/pascal]

    Yet delphibasics.co.uk use it as if it's ok,
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  2. #2

    IO Error.

    Remove the rewrite call. :roll:

  3. #3
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2

    IO Error.

    Quote Originally Posted by Robert Kosek
    Remove the rewrite call. :roll:
    More precisely, replace 'rewrite' with 'reset', and move the 'closefile' outside of the 'while...do' loop. At the moment, your code is creating the file and opening it for writing. I suspect the 104 is being raised by the EOF since EOF is only used when you've opened the file for random access with 'reset'.

    A nice way of handling it would be this...

    [pascal]
    procedure TForm1.Button1Click(Sender: TObject);
    var
    test1: TextFile;
    rtext: System.string;
    begin
    AssignFile(test1, 'C:\test.txt');
    if fileExists('c:\test.txt') then
    begin
    reset(test1);
    try
    try
    while not Eof(test1) do
    begin
    ReadLn(test1, rtext);
    ShowMessage(rtext);
    end;
    except
    on e:exception do
    showMessage('An exception occured reading C:\test.txt. Message was:- '+e.message);
    end;
    finally
    try
    CloseFile(test1);
    except
    end;
    end;
    end;
    end;
    [/pascal]

    Append - Opens the file for writing and puts the file position at the EOF (Only works for text files)
    Reset - Opens the file for random access (ie. you can read and write)
    Rewrite - Creates the file and opens it for writing
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4

    IO Error.

    Ok, this is a different program, it keep giving me "IO Error 32"

    [pascal]var FACCR: TextFile;
    begin
    try
    VACID1 := FIMANF1.MFIMANACNM1.Text;
    if not DirectoryExists('C:\HXACC') then CreateDir('C:\HXACC');

    MACCFNAM := 'C:\HXACC\' + VACID1 + '-' + 'MDF' + '.VTD';
    if not FileExists(MACCFNAM) then FileCreate(MACCFNAM);

    AssignFile(FACCR, MACCFNAM);
    ReWrite(FACCR);
    VUNITIME1 := Now;
    VUNITIME2 := DateTimeToStr(VUNITIME1);
    WriteLn(FACCR, VUNITIME2);
    WriteLn(FACCR, '[ACCOUNT-ACTIVE]');
    WriteLn(FACCR, VAMAIV);
    CloseFile(FACCR);
    HXDFLOCS1;
    MFIMANUPD1;[/pascal]

    could someone help me?
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  5. #5

    IO Error.

    Just look into help what io error 32 means and at least try to solve it yourself :?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  6. #6

    IO Error.

    I already did, I found that the problem is with ReWrite, because it won't execute any code after rewrite, but I have no idea of what to do to it...
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  7. #7

    IO Error.

    At first I couldn't find the problem either. After I cleaned up your code a bit I realized that the filename you are using is not correct.

    Code:
    procedure TForm1.Button1Click&#40;Sender&#58; TObject&#41;;
    var FACCR &#58; TextFile;
        VACID1 &#58; string;
        MACCFNAM &#58; string;
        VUNITIME1 &#58; TDateTime;
        VUNITIME2 &#58; string;
        VAMAIV &#58; string;
    begin
      try
         VACID1 &#58;= FIMANF1.MFIMANACNM1.Text;   // <--- what is this ??? 
         if not DirectoryExists&#40;'C&#58;\HXACC'&#41; then CreateDir&#40;'C&#58;\HXACC'&#41;;
    
         MACCFNAM &#58;= 'C&#58;\HXACC\test-MDF.txt'; // replaced your string with a proper filename
    
         AssignFile&#40;FACCR, MACCFNAM&#41;;
         if not FileExists&#40;MACCFNAM&#41; then  // check here if you need to create or open a new file
            rewrite&#40;FACCR&#41;
         else
           Reset&#40;FACCR&#41;;
         VUNITIME1 &#58;= Now;
         VUNITIME2 &#58;= DateTimeToStr&#40;VUNITIME1&#41;;
         WriteLn&#40;FACCR, VUNITIME2&#41;;
         WriteLn&#40;FACCR, '&#91;ACCOUNT-ACTIVE&#93;'&#41;;
         WriteLn&#40;FACCR, VAMAIV&#41;;
         CloseFile&#40;FACCR&#41;;
      except
       //your exceptions here
      end
    end;

  8. #8

    IO Error.

    Problem solved.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

  9. #9

    IO Error.

    oh, i already solved the problem, but thanks.

    that looks even better.
    Nicholas.
    <br />
    <br />Please join: http://holzstukka.proboards81.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •