| View previous topic :: View next topic |
| Author |
Message |
Tom Woods Guest
|
Posted: Thu Oct 23, 2003 2:31 pm Post subject: Using AssignFile |
|
|
What is the best way to test 'F' to see if the file is open?
AssignFile( F, sLogFile );
Rewrite( F );
|
|
| Back to top |
|
 |
Julia deSilva Guest
|
Posted: Thu Oct 23, 2003 6:43 pm Post subject: Re: Using AssignFile |
|
|
Do you have to do it that Pascal way or couldn't you just load the file into
a Tstringlist
var sl : Tstringlist;
...
...
sl := Tstringlist.create;
sl.loadfromfile('yourfile.txt');
for i := 0 to length(sl)-1 do
begin
......do something
end;
sl.savetofile('yourfile.txt');
sl.free;
| Quote: | What is the best way to test 'F' to see if the file is open?
AssignFile( F, sLogFile );
Rewrite( F );
.
.
.
If (valid F) then CloseFile(F);
TIA,
Tom Woods
|
|
|
| Back to top |
|
 |
Peter Below (TeamB) Guest
|
Posted: Thu Oct 23, 2003 7:50 pm Post subject: Re: Using AssignFile |
|
|
In article <3f97e722$1 (AT) newsgroups (DOT) borland.com>, Tom Woods wrote:
| Quote: | What is the best way to test 'F' to see if the file is open?
AssignFile( F, sLogFile );
Rewrite( F );
.
.
.
If (valid F) then CloseFile(F);
|
if (TTextrec( F ).Mode and fmMask) = fmOutput then
...file is open for write
Just a point of strategy: a logfile based on Textfile should never be
left open for the whole apps lifetime. If you do not want to risk
loosing log data when the app crashes use open-write-close to write log
entries. If you write to the log very frequently use a TFilestream
instead and call FlushFileBuffers( stream.handle ) at intervals. You
can then leave the stream open.
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
|
|
| Back to top |
|
 |
Tom Woods Guest
|
Posted: Thu Oct 23, 2003 8:58 pm Post subject: Re: Using AssignFile |
|
|
Thanks Peter!
I've never used TFilestream, but I'll take a look into it!
Tom.
"Peter Below (TeamB)" <100113.1101 (AT) compuXXserve (DOT) com> wrote
| Quote: | In article <3f97e722$1 (AT) newsgroups (DOT) borland.com>, Tom Woods wrote:
What is the best way to test 'F' to see if the file is open?
AssignFile( F, sLogFile );
Rewrite( F );
.
.
.
If (valid F) then CloseFile(F);
if (TTextrec( F ).Mode and fmMask) = fmOutput then
...file is open for write
Just a point of strategy: a logfile based on Textfile should never be
left open for the whole apps lifetime. If you do not want to risk
loosing log data when the app crashes use open-write-close to write log
entries. If you write to the log very frequently use a TFilestream
instead and call FlushFileBuffers( stream.handle ) at intervals. You
can then leave the stream open.
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
|
|
|
| Back to top |
|
 |
Jeffrey A. Wormsley Guest
|
Posted: Fri Oct 24, 2003 5:54 pm Post subject: Re: Using AssignFile |
|
|
"Tom Woods" <twoods (AT) jamesbaker (DOT) com> wrote in
news:3f9841e2$1 (AT) newsgroups (DOT) borland.com:
| Quote: | Thanks Peter!
I've never used TFilestream, but I'll take a look into it!
|
You'll not go back! I've "lost" a lot of problems just from making that
simple switch!
Jeff.
|
|
| Back to top |
|
 |
|