Having trouble writing to a text file

Please discuss general Delphi programming topics here.

Having trouble writing to a text file

Postby Wardlow » June 28th, 2007, 4:28 am

Here a function I have that writes to a next file. This function is called many times because it is in a while loop. NumFiles, gets incremented, 0, 1, 2, 3, 4. The first time the function is called I want to rewrite the file, however the 2nd time I call the function I don't want it to rewrite the file... I want to keep on adding to the file.

What I have down here results in an error. Anyone know what I should do?

Thanks

Code: Select all
function WriteFile
begin
        if NumFiles = 0 then
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Rewrite(SendFile);
        end
        else
          AssignFileSendFile, 'c:\ProgramResults\3ParametersData.txt');


writeln(SendFile, 'HELLOMOM');

closefile(Sendfile);
end;

Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm

Postby HPW » June 28th, 2007, 5:32 am

Try this (Untested):
Code: Select all
function WriteFile
begin
        if NumFiles = 0 then
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Rewrite(SendFile);
        end
        else
        begin
          AssignFile(SendFile, 'c:\ProgramResults\3ParametersData.txt');
          Append(SendFile);
        end;
writeln(SendFile, 'HELLOMOM');
closefile(Sendfile);
end;
Hans-Peter
HPW
Moderator
Moderator
 
Posts: 238
Joined: February 25th, 2006, 10:19 am
Location: Germany

Postby Wardlow » June 28th, 2007, 4:16 pm

thank for perfect thank you very much
Wardlow
Junior Member
Junior Member
 
Posts: 38
Joined: May 31st, 2007, 10:08 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 11 guests

cron