Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a text file 2

Status
Not open for further replies.

Jonah86

Programmer
Dec 11, 2003
152
US
Hello.

I have a program that needs to write data to a text file. The text file will have a different name depending on certain parameters. I have the "writing to the text file" part working just fine, but I need to be able to create the file if it doesn't already exist. Is there a way to do this with Delphi 7?

Thanks.
 
Well that's the problem. I need to know how to create the text file if it doesn't already exist. The only code I have for it now is writing text to the file if the file already exists.
 
I think maybe I didn't explain this clearly.

I don't have any routine for creating text file. I need to know how to create the file. In addition, I need to only create the file if it doesn't exist already.

I can, currently, only create the file manually. After the file is created the rest of my code works fine to write text to it. I just can't create all the files I would need manually.

Sorry if I was unclear. After re-reading my posts I realized it didn't make as much sense as it did in my head.

Thanks again.
 
something like:

Code:
procedure CreateTextFile(Filename : string);

var FS : TFileStream;

begin
 FS := TFileStream.Create(Filename, fmCreate);
 FreeAndNil(FS);
end;

procedure WriteTextFile(Filename : string);
begin
 if not FileExists(Filename) then
  CreateTextFile(Filename);
 ... // rest of code
end

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Your simplest solution would be to write the program output to a TMemo, which would allow review. Then on close (or a save button) call Memo.lines.SaveToFile(filename) which is always a text file.

HTH

Roo
Delphi Rules!
 
Thanks a lot, everyone. This should work out nicely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top