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 

newbie Q about text files read/write

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
YZ
Guest





PostPosted: Sun Jan 16, 2005 4:14 am    Post subject: newbie Q about text files read/write Reply with quote



Hi,

how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in itself.

Thanks in advance

YZ

Back to top
Jud McCranie
Guest





PostPosted: Sun Jan 16, 2005 6:13 am    Post subject: Re: newbie Q about text files read/write Reply with quote



On Sun, 16 Jan 2005 04:14:19 GMT, YZ <z@***.ohio-state.edu> wrote:

Quote:
how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in itself.

I don't think a text file can be opened for both reading and writing,
although other kinds of files can.

---
Replace you know what by j to email

Back to top
Tom de Neef
Guest





PostPosted: Sun Jan 16, 2005 9:35 am    Post subject: Re: newbie Q about text files read/write Reply with quote



"YZ" <z@***.ohio-state.edu> schreef in bericht
news:vSlGd.1246$e64.110 (AT) fe2 (DOT) columbus.rr.com...
Quote:
Hi,

how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in
itself.


And rewrite(F) opens it for writing only too.
Textfiles are handled different from other files.
A convenient way of using them is to store the file in a Tstringlist and do
all the processing on that list.
myText:=Tstringlist.create;
myText.loadFromFile(filename); // reads the complete file
myText.add('a new string');
myText.delete(anyIndex);
myText.saveToFile(filename); // writes the lot back to disk
myText.free;

Note that for parameter storing, TiniFile is very convenient.
Tom



Back to top
J French
Guest





PostPosted: Sun Jan 16, 2005 9:39 am    Post subject: Re: newbie Q about text files read/write Reply with quote

On Sun, 16 Jan 2005 04:14:19 GMT, YZ <z@***.ohio-state.edu> wrote:

Quote:
Hi,

how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in itself.

Could you explain what you want to do

It might be that a TStringList or TFileStream is what you really need

Back to top
YZ
Guest





PostPosted: Sun Jan 16, 2005 5:47 pm    Post subject: Re: newbie Q about text files read/write Reply with quote

J French wrote:

Quote:
On Sun, 16 Jan 2005 04:14:19 GMT, YZ <z@***.ohio-state.edu> wrote:


Hi,

how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in itself.


Could you explain what you want to do

It might be that a TStringList or TFileStream is what you really need

I am writing a little utility for editing LaTeX bibliography files
(.bib), which are just text files with strings like this:

@ARTICLE{key,
Author={Author Name},
Title={Article Title},
Journal={Journal title},
Volume={Volume #},
Year={year},
Pages={123-456} }

etc..

I want to be able to add an entry to the file (this already works), to
delete an entry from the file, find entry in the file by one of the
fields (key, author, title, etc..), and edit the found entry. For that I
think I need the .bib file open for both write and read.

I will give it a try with TStringList. Thanks everyone.

YZ


Back to top
J French
Guest





PostPosted: Mon Jan 17, 2005 9:16 am    Post subject: Re: newbie Q about text files read/write Reply with quote

On Sun, 16 Jan 2005 17:47:14 GMT, YZ <z@***.ohio-state.edu> wrote:

Quote:
J French wrote:

On Sun, 16 Jan 2005 04:14:19 GMT, YZ <z@***.ohio-state.edu> wrote:


Hi,

how do I open text file for both read and write? reset(F) opens it for
reading only, while append(F) opens it for write only. It should be
something simple, but navigating delphi's help system is a hurdle in itself.


Could you explain what you want to do

It might be that a TStringList or TFileStream is what you really need

I am writing a little utility for editing LaTeX bibliography files
(.bib), which are just text files with strings like this:

@ARTICLE{key,
Author={Author Name},
Title={Article Title},
Journal={Journal title},
Volume={Volume #},
Year={year},
Pages={123-456} }

etc..

I want to be able to add an entry to the file (this already works), to
delete an entry from the file, find entry in the file by one of the
fields (key, author, title, etc..), and edit the found entry. For that I
think I need the .bib file open for both write and read.

I will give it a try with TStringList. Thanks everyone.

It looks as if you are messing around with an entire Text file
- a TStringList will work for that

Another alternative is to load the whole lot into one large String and
mess around with the directly using things like Pos() and PosEx()

Back to top
YZ
Guest





PostPosted: Mon Jan 17, 2005 8:06 pm    Post subject: Re: newbie Q about text files read/write Reply with quote

Yes, I got it to work with TStringList. Thanks everyone once again.

YZ
Quote:

It looks as if you are messing around with an entire Text file
- a TStringList will work for that

Another alternative is to load the whole lot into one large String and
mess around with the directly using things like Pos() and PosEx()


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc 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.