Dear Sir,

Please help me in this part of the question.

I want to change the phone a friend details. Find a person and change their phone a friend number. To do this I need to find a record in memory and overwrite that record's phone field. Then save all the records back to the file. The next time I run the program I run the program I should be able to see the person's new phone number.

Cheers,

Dear Sir,
Please help me in this part of the question.
I want to change the phone a friend details. Find a person and change their phone a friend number. To do this I need to find a record in memory and overwrite that record's phone field. Then save all the records back to the file. The next time I run the program I run the program I should be able to see the person's new phone number.
Cheers,

Sorry for wrong answer.I wrote to you that you have to use the blockread and blockwrite commands.When I'm learning more about the typed file I changed my opinion.The result now is a working program.You have to use typed file like your record.Cause only typed of record elements can be write to that file :)

{
Question: Typed Files;

[ 0.data  ]
[ 1.data  ]
[ 2.data  ]
[ ...     ]
[ n.data  ]

We can reach this file's elements row by row,or directly
}


Program Project2;

{$APPTYPE CONSOLE}

Uses
  SysUtils;

Type
    St15 = String[15];
    ConData = Record
                 F_Name:St15;
                 L_Name:St15;
                 P_Number:LongInt;
              End;
Var
    OneP:ConData;
    Person:Array[0..2]of ConData;
    Guy:Array[0..2]of ConData;
    OurFile:File Of ConData; {file type is important!}
    i:Byte; //0..255
    u:Byte;

Procedure Stars;
Var a:Byte;
Begin
   For a:=1 To 40 Do Write('*');
   WriteLn;
End;

Begin {main}
   //Fill 3 person's data
   For i:=0 To 2 Do Begin
      Stars;
      Write(i:2,'.First name: ');
      ReadLn(Person[i].F_Name);
      Write('   Last name: ');
      ReadLn(Person[i].L_Name);
      Write('   Her/His phone number: ');
      ReadLn(Person[i].P_Number);
      If (i=2)Then Begin
         Stars;
      End;
   End;
   //assigning
   Assign(OurFile,'C:\RecFile.Dat');
   //creating this file
   Rewrite(OurFile);
   //writing the records to file
   For i:=0 To 2 Do Begin
      Write(OurFile,Person[i]);
   End;
   WriteLn;
   WriteLn('Show the contents of the file:');
   WriteLn;
   Reset(OurFile);
   i:=0;
   //Fill the array with records,reading from file
   While (EoF(OurFile)=False)Do Begin
    Read(OurFile,Guy[i]);
    Inc(i);
   End;
   //write the elements of the array
   For i:=0 to 2 do begin
      Write(i,'. Name: ',Guy[i].F_name,' ');
      Write(Guy[i].L_name,'   Phone: ');
      WriteLn(Guy[i].P_number);
      WriteLn;
   End;
   WriteLn;
   Write('Please give me the member''s number.0 or 1 or 2 : ');
   ReadLn(u);
   WriteLn;
   Seek(OurFile,u);//positioning
   Read(OurFile,OneP); //read one record from file
   Write(OneP.F_name,' ');
   Write(OneP.L_name,' ');
   WriteLn('last created phone number: ',OneP.P_number);
   WriteLn;
   Write('Now,give me her/his new phone number: ');
   ReadLn(OneP.P_number);//and here changes the number by the user
   WriteLn;
   Seek(OurFile,u);//positioning
   Write(OurFile,OneP);//write the new data
   WriteLn;
   WriteLn('Read again that file: ');
   WriteLn;
   Reset(OurFile); //open for reading
   i:=0;
   //Fill the array with records,reading from file
   While (EoF(OurFile)=False)Do Begin
    Read(OurFile,Guy[i]);
    Inc(i);
   End;
   //write the elements of the array
   For i:=0 to 2 do begin
      Write(i,'. Name: ',Guy[i].F_name,' ');
      Write(Guy[i].L_name,'   Phone: ');
      WriteLn(Guy[i].P_number);
      WriteLn;
   End;
   //closing the file
   Close(OurFile);
   ReadLn;
End.{end of main}

//Tested in Delphi 7,working!

{
-=Created by FlamingClaw 2009.04.20=-
}

:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.