?
Solved

Please..I need this. i am beginer.

Posted on 2000-01-31
7
Medium Priority
?
129 Views
Last Modified: 2010-04-04
Thank you in Advance.

How i can insert a text string into a specific location in a text file(Already exists) using delphi.

(without opening a temp. file and do it in a ineffective way)

0
Comment
Question by:ams4380361
7 Comments
 
LVL 1

Expert Comment

by:pede
ID: 2464891
Hi
You need to make a copy to a new file.

1. Read until you reach the position to insert the text. While you do this, you write the content to a new file

2. Write the text to insert to the new file

3. Read through the rest of the original file, while writing the content to the new file

4. Delete the original file, and rename the new file to the name of the original file

Sorry, I havent got time to give samples, Im just commenting. If anyone has a better solution, Id like to hear it, because Im about to do something similar soon, with very large files, and this method kinda sucks, but seems the only way ;o)

Regards,
Pede
0
 

Author Comment

by:ams4380361
ID: 2465281
Edited text of question.
0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 60 total points
ID: 2466241
Load the file into a Tstringlist:

var MyFile:Tstringlist;
begin
   Myfile:=Tstringlist.Create;
   Myfile.LoadFromFile('c:\somefile.txt');
   Myfile.Insert(location,'Dave was here');
   Myfile.SaveToFile('C:\somefile.txt');

end;
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:edey
ID: 2471561
As far as avoiding loading the entire file into memory the only solutions I can think of work only if the *size* of the file doesn't change, ie. you can change chars in the files, but not add or delete them


GL
Mike
0
 
LVL 1

Expert Comment

by:pede
ID: 2477288
DrDelphi: Your solution is very nice, but in my case, where the files can be well over 1GB, its not very "practical". I guess ams...'s files are smaller, since he accepts it ;)

Regards,
Pede
0
 
LVL 6

Expert Comment

by:edey
ID: 2478606
pede, why are your data files so large? is it not possible to use a db driver with them? or to split them?


GL
Mike
0
 
LVL 1

Expert Comment

by:pede
ID: 2481204
Edey: Long story ;-)  (almost as long as the files). I really have no option other than working with them. Splitting would only make things more difficult.

/Pede
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question