[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Textfile

Posted on 2002-03-14
3
Medium Priority
?
264 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

867 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