help! WriteLN to write to a specific line in text file


I am trying to write a program with a checkbox, so that when the checkbox is clicked the following is written to a text file

Dave speaks good english true;

if the checkbox is unclicked

Dave speaks good english false;

When using WriteLn it writes to the first line of the text file i have specified, but i want to write to another line, for example, line 10. I have the following code which i couldnt get to work.

procedure Tform1.CheckBox1Click(Sender: TObject);


assignfile(txt, '/home/user/test.txt');

if checkbox1.checked then

line:='dave speaks good english true;';
Writeln(txt, line)



line :='dave speaks good english false;';


My first problem is that i cant seem to use the if else statement to write a line to a text file if the checkbox is clicked if not clicked write a different line to a text file, and the second problem is that i dont know how i could change my code to write to another line of the text file rather then line 1, for example line 10.   Thanks in advance!!

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You need begin...end blocks in your IF statement:

if checkbox1.checked then begin

line:='dave speaks good english true;';
Writeln(txt, line)


else begin

line :='dave speaks good english false;';

Geoff M.
itektasAuthor Commented:
ok cool ill try that now, but what about if i want to enter the information in a certain line other then the first one, Writeln writes into the first line of the text file, how would i write to line 10 ? is that possible? thanks
I think you can open the file in read/write mode, read 9 lines, and write the 10th. However, if the new line is shorter, I think you'll have part of the old line left over.

Perhaps a better option would be to use a TStringList.

var sl : TStringList;

sl := TStringList.Create;
sl[9] := 'whatever you want';

Geoff M.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itektasAuthor Commented:
perfect. thanks a lot :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.