Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Load a lot of files into RichEdit from a specified Directory

Posted on 2006-06-21
3
Medium Priority
?
219 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
[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 28

Assisted Solution

by:2266180
2266180 earned 100 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 400 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 31

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

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

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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

610 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