itektas
asked on
help! WriteLN to write to a specific line in text file
hi
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(Send er: TObject);
var
txt:textfile;
line:string;
begin
assignfile(txt, '/home/user/test.txt');
rewrite(txt);
if checkbox1.checked then
line:='dave speaks good english true;';
Writeln(txt, line)
end
else
line :='dave speaks good english false;';
Writeln(txt,line);
end
closefile(txt);
end;
end.
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!!
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(Send
var
txt:textfile;
line:string;
begin
assignfile(txt, '/home/user/test.txt');
rewrite(txt);
if checkbox1.checked then
line:='dave speaks good english true;';
Writeln(txt, line)
end
else
line :='dave speaks good english false;';
Writeln(txt,line);
end
closefile(txt);
end;
end.
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!!
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfect. thanks a lot :)
if checkbox1.checked then begin
line:='dave speaks good english true;';
Writeln(txt, line)
end
else begin
line :='dave speaks good english false;';
Writeln(txt,line);
end
Geoff M.