Free Pascal Compiler - File Handling

Discussion in 'Mac Programming' started by satans_banjo, Jan 10, 2006.

  1. macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #1
    Ok this is quite urgent - I've got some pascal work to do for tomorrow and the exercise is about file handling - problem is the teacher only told us about file handling on windows

    i've tried writing the same thing i would for windows but replacing the file path with just "/" as the root but that didnt work. the compiler had no problems but the terminal did this when i ran it:

    the weird thing is, i didn't put a string that says 'loading...' in the code. it must have been added by the compiler

    any advice would be much appreciated
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    If you post the relevant part of the code we might have a chance!
     
  3. thread starter macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #3
    thanks for the quick reply

    here's the main part:

    Code:
    begin
         assign(f1,'/file.car');
         load;
         menu;
    end.
    heres the load procedure:

    Code:
    procedure load;
    begin
         writeln('Loading Data Now...');
         reset(f1);
         i:=0;
         while not eof(f1) do
         	begin
         		i:=i+1;
         		seek(f1,i);
         		read(f1,car[i]);
         	end;
         close(f1);
         count:=i;
    end;
    
    and here's the save procedure

    Code:
    procedure save;
    begin
         writeln('Saving data now...');
         rewrite(f1);
         for i:=1 ro count do
         begin
         	seek(f1,i);
         	write(f1,car[i]);
         end;
         close(f1);
    end;
    
    thanks for reading
     
  4. macrumors 601

    Joined:
    Mar 8, 2005
    Location:
    Austin, TX
    #4
    Do you have file r/w permissions for the root path, and does the file currently exist when you run the program?
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Where is car (the array) defined? Where is save called? You call menu but not save!
     
  6. thread starter macrumors regular

    Joined:
    Sep 12, 2005
    Location:
    SE London
    #6
    sorry. schoolboy error

    this is the array, in the enterdata procedure:

    Code:
    procedure enterdata;
    begin
         car[1].regnum := 'D390 HDJ';
         car[1].ownname:= 'Ben Wadsworth';
         car[1].make   := 'Bentley';
         car[1].model  := 'Continental GT';
         car[2].regnum := 'F387 DJK';
         car[2].ownname:= 'Alex Branchini';
         car[2].make   := 'Fiat';
         car[2].model  := 'Punto';
         car[3].regnum := 'G768 SKF';
         car[3].ownname:= 'Tom Scott-Soundy';
         car[3].make   := 'Hummer';
         car[3].model  := 'H2';
         car[4].regnum := 'B847 DJH';
         car[4].ownname:= 'Rory Dishman';
         car[4].make   := 'Mercedes-Benz';
         car[4].model  := 'S-Class';
         car[5].regnum := 'H487 FNS';
         car[5].ownname:= 'Josh Holloway';
         car[5].make   := 'Jaguar';
         car[5].model  := 'X-Type';
    end;
    
    and here is the new main section:

    Code:
    begin
         assign(f1,'/file.car');
         enterdata;
         save;
         load;
         menu;
    end.
    
    thanks for pointing that out

    EDIT: just compiled it and it works!

    thanks macrumors! and special thanks to robbieduncan and danny_w!
     

Share This Page