BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using AssignFile

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using
View previous topic :: View next topic  
Author Message
Tom Woods
Guest





PostPosted: Thu Oct 23, 2003 2:31 pm    Post subject: Using AssignFile Reply with quote



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





PostPosted: Thu Oct 23, 2003 6:43 pm    Post subject: Re: Using AssignFile Reply with quote



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





PostPosted: Thu Oct 23, 2003 7:50 pm    Post subject: Re: Using AssignFile Reply with quote



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





PostPosted: Thu Oct 23, 2003 8:58 pm    Post subject: Re: Using AssignFile Reply with quote

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





PostPosted: Fri Oct 24, 2003 5:54 pm    Post subject: Re: Using AssignFile Reply with quote

"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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi VCL Components Using All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.