cybermilky
asked on
Reset (F)
I came across these codes:
AssignFile(F, FileName);
Reset(F);
What is Reset(F)?
AssignFile(F, FileName);
Reset(F);
What is Reset(F)?
ASKER
Hi Hipoviax,
We use Reset because we want to read the file? like read a line (Readln)? Other than readln, is there any other condition that we need to use reset?
We use Reset because we want to read the file? like read a line (Readln)? Other than readln, is there any other condition that we need to use reset?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I give you 2 examples
1) AssignFile(F, 'C:\myfile.ext');
Reset(F);
this open existing file for reading
2) AssignFile(F, 'C:\myfile.ext');
Rewrite(F);
this create a empty file ready to be filled with data. If the file C:\myfile.ext exists, Rewrite erase the contents - open empty file...
reset(f) allows you to read the file. A good example:
procedure TForm1.btnReadClick(Sender
var
F: TextFile;
S: string;
begin
if FileExists('C:\Test\Data.t
AssignFile(F, 'C:\Test\Data.txt');
Reset(F); //Reset it for reading
ReadLn(F, S); //Read the first line
Edit1.Text := S; //Assign that line to a edit box
ReadLn(F, S); //Read the second line
Edit2.Text := S;//Assign it to another edit box
CloseFile(F); //Close the file when we are done
end
else
ShowMessage('File C:\Test\Data.txt not found'); //The file does not exist
end;
you may also be interested in writing to a text file:
procedure TForm1.btnWriteClick(Sende
var
F: TextFile;
begin
AssignFile(F, 'C:\Test\Data.txt');
Rewrite(F); //Similar to the reset function
WriteLn(F, Edit1.Text); //Write a line from edit1
WriteLn(F, Edit2.Text); //Write another line from edit2
CloseFile(F); //once again close the file
end;
I hope this solves your query
Regards,
Hypoviax