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
Solved

Load a lot of files into RichEdit from a specified Directory

Posted on 2006-06-21
3
210 Views
Last Modified: 2010-04-05
Hello All;

I know there is a better way of doing this, then the way I have "Attempted" to try.

RichEdit1.Lines.LoadFromFile('I:\FolderName\somefile.txt');
RichEdit1.Lines.LoadFromFile('I:\FolderName\somefile_2.txt');
RichEdit1.Lines.LoadFromFile('I:\FolderName\somefile_3.txt');
RichEdit1.Lines.LoadFromFile('I:\FolderName\somefile_4.txt');
RichEdit1.Lines.LoadFromFile('I:\FolderName\somefile_5.txt');

The folder has quite a bit of files located in it.
I need to load ALL The files into the RichEdit1
Basically.
After the 1st file is loaded, then go to the End, and load the 2nd file
Then go to the end of Load the 3rd file, and so on.
With no

Blank spaces between the files.

Any idea's on this one?
I would prefer not to have to write it out like I attempted to do above.

Thanks All;
Carrzkiss
0
Comment
Question by:Wayne Barron
3 Comments
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 25 total points
ID: 16955866
hm ... that is
1) ugly
2) not working.

try soemthing like this:

add all filenames you want to load in a tstringlist named files

RichEdit1.Lines.clear;
s:=TStringList.create;
for i:=1 to files.count do
begin
  s.loadfromfile(files[i-1]);
  RichEdit1.Lines.addstrings(s);
end;
s.free;

if the files are dinamically generated or soemthing, use a findfirst/findnext construction to find them all and add them to the files list.
0
 
LVL 4

Accepted Solution

by:
LMuadDIb earned 100 total points
ID: 16956145
how about TOpenDialog to select the files, its not short and neat but does a good job:

procedure CombineFiles(dlg1: TOpenDialog;Rich1: TRichEdit);

...

procedure TForm1.btn1Click(Sender: TObject);
begin
  // Set up the starting directory to be the current one
  dlgOpen1.InitialDir := GetCurrentDir;
  // Allow multiple files to be selected - of any type
  dlgOpen1.Options := [ofAllowMultiSelect];

  if dlgOpen1.Execute then
  begin
    if dlgOpen1.Files.Count > 0 then
     CombineFiles(dlgOpen1,RichEdit1);
  end;
end;

procedure TForm1.CombineFiles(dlg1: TOpenDialog; Rich1: TRichEdit);
var
  i:  INTEGER;
  s:  ARRAY OF STRING;
  Stream:  TMemoryStream;
begin
  SetLength(s,dlg1.Files.Count);
  for i := 0 to dlg1.Files.Count -1 do
  begin
    // Load files into string array
    if FileExists(dlg1.Files[i]) then begin
      Stream := TMemoryStream.Create;
      try
        Stream.LoadFromFile(dlg1.Files[i]);
        SetLength(s[i], Stream.Size);
        Stream.Read(s[i][1], Stream.Size)
      finally
        Stream.Free
      end
    end
    else s[i] := '';
  end;

  // Send string array results to RichEdit
  Rich1.Clear;
  for i := low(s) to high(s) do
          Rich1.Lines.Append(s[i]);

end;
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16956485
Thanks both.

LMuadDIb
I use to have a code like this but had lost it. Thanks a bunch for making me remember it again.

---------
ciuly
1-Ugly  - Yep
2-Not Working - Yep, that is why I posted it and wanted a better solution.
Also, I use to do some like this a long time ago, but with some more added code,
That I just could not remember.


Carrzkiss
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Yen format 3 45
SUM 2 INTEGER ARRAYS INTO 1 10 108
Tidtcpserver listening on multiports? 1 35
How to make Sign in, using Clientdataset? 1 28
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

766 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