Solved

Load a lot of files into RichEdit from a specified Directory

Posted on 2006-06-21
3
207 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:ciuly
ciuly 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

13 Experts available now in Live!

Get 1:1 Help Now