SRL Archive - OSR Help

Write to next line in a .txt


noway123

2012-02-09 19:53:36

Hi.

Whenever i call this procedure i want to write into a new line in my data.txt but this procedure only adds a String in data.txt without going into a new line. Any help :P ?

procedure WriteToFile(YourText: String);
Var
FName: String;
x: Integer;
begin
FName := 'Data.txt';
AppendFile(FName);
OpenFile(FName,true);
WriteFileString(x, YourText+' ### ');
CloseFile(x);
end;


Noway123

Dgby714

2012-02-09 20:26:02

program new;

procedure AddLine(const Data: string);
begin
with TStringList.Create() do
try
LoadFromFile(ScriptPath + 'Data.txt');

Add(Data);

SaveToFile(ScriptPath + 'Data.txt');
finally
Free;
end;
end;

begin
AddLine('test1');
AddLine('test2');
AddLine('test3');
AddLine('test4');
AddLine('test5');
end.

noway123

2012-02-09 21:39:52

From: Dgby714
program new;

procedure AddLine(const Data: string);
begin
with TStringList.Create() do
try
LoadFromFile(ScriptPath + 'Data.txt');

Add(Data);

SaveToFile(ScriptPath + 'Data.txt');
finally
Free;
end;
end;

begin
AddLine('test1');
AddLine('test2');
AddLine('test3');
AddLine('test4');
AddLine('test5');
end.



I implemented your code into my program (thx btw.) and got this error. I run simba as admin so i dont know why i keep getting this error.


SaveToFile(FName);

Error: Exception: Unable to create file "C:\Simba\Scripts\Data.txt" at line 11


edit: Found the reason why i keep getting the error.I had a Java FileReaderStream connection to the same .txt and that messed it up.