Board index » delphi » Help With Simple Text File Output

Help With Simple Text File Output

I am new to Delphi and have a real simple question:

        MyFileHandle := FileCreate('TEST.TXT');
        MyFileHandle := FileOpen('TEST.TXT', 1 );
                Writeln('This is a Test');
        FileClose(MyFileHandle);

This code creates the file but doesn't print anything to
the file... What am I missing?

Thanks in Advance...

 

Re:Help With Simple Text File Output


| I am new to Delphi and have a real simple question:
|
|       MyFileHandle := FileCreate('TEST.TXT');
|       MyFileHandle := FileOpen('TEST.TXT', 1 );
|               Writeln('This is a Test');
|       FileClose(MyFileHandle);
|
| This code creates the file but doesn't print anything to
| the file... What am I missing?

Instead of using Writeln, you'd need to use FileWrite, which includes
specifying the file handle. However, I normally do this kind of thing a
bit differently. If you want to write to a text file, you might try:

var
  MyTextFile : Text;
begin
{ Assign a filename to the text file var. }
AssignFile(MyTextFile, 'TEST.TXT');
{ Create the text file. }
Rewrite(MyTextFile);
{ Write a line of text to the file. }
Writeln(MyTextFile, 'This is a Test');
{ Close the file. }
CloseFile(MyTextFile);
end;

Russ Chinoy

Re:Help With Simple Text File Output


Quote
Kelton Averyt <ave...@ix.netcom.com> wrote:
>I am new to Delphi and have a real simple question:
>    MyFileHandle := FileCreate('TEST.TXT');
>    MyFileHandle := FileOpen('TEST.TXT', 1 );
>            Writeln('This is a Test');
>    FileClose(MyFileHandle);
>This code creates the file but doesn't print anything to
>the file... What am I missing?
>Thanks in Advance...

var
  F : TextFile;
begin
  AssignFile (F, 'TEST.TXT');
  Rewrite (F);  
  WriteLn (F, 'This is a Test');
  CloseFile (F);
end;

Hope this helps
Meik Weber
m.we...@public.ndh.com or
100744.3...@compuserve.com

Other Threads