Solved

Textfile

Posted on 2002-03-14
3
261 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 100 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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