Solved

Textfile

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now