?
Solved

Textfile

Posted on 2002-03-14
3
Medium Priority
?
262 Views
Last Modified: 2010-04-05
Hi guys,

Say for instance I have 3 .rtf files, how can I actually add/append them together (So that I only have one file) before doing any work on it ?
Here is the Code I use for one, but somewhere in between I have to append 3 different .rtf files :

procedure TForm1.Button1Click(Sender: TObject);
var
  F : TextFile;
  aString : String;
begin
  aString := ExtractFileDir(ParamStr(0)) + '\Test.rtf';

  AssignFile(F, aString);

  Reset(F);

  while not EOF(F) do
  begin
    Readln(F, bString);
   
    // Do whatever
  end;

  CloseFile(F);
end;


Thanks

Pieter
0
Comment
Question by:PieterJ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
wimmeyvaert earned 400 total points
ID: 6867448
Why don't you use the LoadFromFile-Method of a TStringList.

Example :

procedure TForm1.Button1Click(Sender: TObject);
var tstrTmp1, tstrAll : TStringList
begin
  tstrTmp := TStringList.Create;
  tstrAll := TStringList.Create;
  tstrTmp.LoadFromFile('file1.rtf');
  tstrAll.AddStrings(tstrTmp);
  tstrTmp.LoadFromFile('file2.rtf');
  tstrAll.AddStrings(tstrTmp);
  tstrTmp.LoadFromFile('file3.rtf');
  tstrAll.AddStrings(tstrTmp);
end;

In the exmaple you have added 3 files together into 1 TStringList (tstrAll).

Best regards,

Tha Mayor.

0
 
LVL 4

Expert Comment

by:jsweby
ID: 6867819
Open your first file with Append(f) so that the cursor is (figuratively speaking) at the end of the file.

Then open the other 2 files with Reset(f) and in your While Not EOF(f) loop, add each line to File 1. i.e.

procedure TForm1.Button1Click(Sender: TObject);
var
 F, F2 : TextFile;
 aString, bString : String;
begin
 aString := ExtractFileDir(ParamStr(0)) + '\Test.rtf';

 AssignFile(F, aString);
 Append(F);

 aString := ExtractFileDir(ParamStr(0)) + '\Test2.rtf';
 
 AssignFile(F2, aString);
 Reset(F2);

 while not EOF(F2) do
 begin
    Readln(F2, bString);
    Writeln(F, bString);
 end;

 CloseFile(F2);
 CloseFile(F);
end;

J.

0
 
LVL 4

Expert Comment

by:nestorua
ID: 6869226
HI,
When reading the comments above I seem to find myself in Turbo Pascal 7.0 again. It's very pleasant remembrances but why don't use TFileStream or TMemoryStream technique?
Sincerely,
Nestorua.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

770 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