Solved

Load a lot of files into RichEdit from a specified Directory

Posted on 2006-06-21
3
214 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 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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