Board index » delphi » Reading and Writing
Nick
![]() Delphi Developer |
Tue, 05 Feb 2002 03:00:00 GMT
|
Nick
![]() Delphi Developer |
Tue, 05 Feb 2002 03:00:00 GMT
Reading and Writing
Couple of quick questions
Q1. I need to read a line of text, and then be able to write a line of text Q2. How do I search for a string in a text file, for example... in a .txt Thanks in advance Nick |
Erez Steinber
![]() Delphi Developer |
Tue, 05 Feb 2002 03:00:00 GMT
Re:Reading and WritingThe best way to handle regular text file (.TXT) is to create a TMemo object in memory, the use the LoadFromFile method to load all the text from the file into memory. When the text is in memory, you can access it easly usign the Text property, or To add a line use Lines.Add. To insert one use Lines.Insert... etc... Search and Replace can also be done something like this: procedure TForm1.FindDialog1Find(Sender: TObject); Erez Steinberg, QuoteNick wrote: |
Maynard Philbroo
![]() Delphi Developer |
Tue, 05 Feb 2002 03:00:00 GMT
Re:Reading and WritingI know what your trying to do is not very easy to do this using text files.. if you used untyped files you could then use the Seek to position the file pointer to read and write, how ever, you then must process the <LF>and <CR> of each line which is part of the file.. values #10 and #13. -- the simplest way to do this is to load up a Tstring , this object has a loadfromfile from there you can work with separate lines ect.. QuoteNick wrote: |
krin
![]() Delphi Developer |
Wed, 06 Feb 2002 03:00:00 GMT
Re:Reading and WritingAll solve i see don't use the simply text file function... So here they are File : Text; Readln, writeln, append, reset, rewrite.... check all this functions (append is what you need) To read/write a specific line number you must read from start of file and write to another file (text file limitation) And to search/replace see this sample (search 'simple search' and replace with reset(filer); QuoteNick wrote: |
Shag
![]() Delphi Developer |
Thu, 07 Feb 2002 03:00:00 GMT
Re:Reading and WritingIn answer to your second question about searching for a word then replacing it. try this nifty little function Function Alter(Line_of_Text,Search,Replace:String):String; Procedure Main_Program; On Fri, 20 Aug 1999 15:18:20 +0300, Erez Steinberg <ere...@ibm.net> Quote>The best way to handle regular text file (.TXT) is to create a TMemo object in |
Paul Sebr
![]() Delphi Developer |
Mon, 11 Feb 2002 03:00:00 GMT
Re:Reading and WritingQ1 assignfile(outputfile, assignfile(command_file, AssignFile if you wnat to go back to the exact same line just remebr how nmany reads or QuoteNick <mrnic...@hotmail.com> wrote in message Quote> Couple of quick questions |
1. Reading and Writing Record Type (structure) in BLOB field - Stream read error
2. Reading and writing to a file
3. read and write the windows registry file from pascal in
4. Read and write sequential file
5. Reading and Writing to a text File
6. Reading and Writing Directly to an IO Port
7. Protected mode - text screen reading and writing
8. W95 Memory reading and writing