Board index » delphi » Beginner's question: Getting text file's contents into a RichEdit box

Beginner's question: Getting text file's contents into a RichEdit box

I have a text file, I assign it to a variable. The variable  -Articles - is
of type 'Textfile'.
    assignfile (Articles, 'data.txt');
    reset(Articles);
(The text file has been found, o'wise I'd get a 'File not there' message).

The RichEdit box intended to display the file/variable contents is empty,
until I do ... what?

I assume that I follow that with ...
    while not eof(Articles) do begin
but what then?

(I said it was a beginner's question! *grin*)
RSVP, and Thanks in advance

 

Re:Beginner's question: Getting text file's contents into a RichEdit box


Quote
Rosie wrote:
>     while not eof(Articles) do begin
> but what then?

You can get a line from the text using Readln.

Then you add it to the richedit using the "Add" method related to the
"Lines" property in the RichEdit control.

while not eof(Articles) do
  begin
   readln(Articles,s);
   richedit1.Lines.add(s); //where 's' var is in the type of string.
  end;

In the end close the file with CloseFile(Articles).

Re:Beginner's question: Getting text file's contents into a RichEdit box


Just call yourRichEdit.Lines.LoadFromFile('data.txt')
and forget about your problems:-)

--
With best regards, Mike Shkolnik
E-mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Quote
Rosie <ttgr...@nospamxtra.co.nz> wrote in message

news:eThz9.6224$8o1.998151@news.xtra.co.nz...
Quote
> I have a text file, I assign it to a variable. The variable  -Articles -
is
> of type 'Textfile'.
>     assignfile (Articles, 'data.txt');
>     reset(Articles);
> (The text file has been found, o'wise I'd get a 'File not there' message).

> The RichEdit box intended to display the file/variable contents is empty,
> until I do ... what?

> I assume that I follow that with ...
>     while not eof(Articles) do begin
> but what then?

> (I said it was a beginner's question! *grin*)
> RSVP, and Thanks in advance

Re:Beginner's question: Getting text file's contents into a RichEdit box


1st: use a TFileStream rather than pascal-style file I/O
2nd: TRichEdit.Lines.LoadFromFile(AFileName). This allows you to
compose RTF textually and feed it in.
3rd: TRichEdit.PlainText := 'abc';

I hope this helps

Cheers

Quote
"Rosie" <ttgr...@nospamxtra.co.nz> wrote:
>I have a text file, I assign it to a variable. The variable  -Articles - is
>of type 'Textfile'.
>    assignfile (Articles, 'data.txt');
>    reset(Articles);
>(The text file has been found, o'wise I'd get a 'File not there' message).

>The RichEdit box intended to display the file/variable contents is empty,
>until I do ... what?

>I assume that I follow that with ...
>    while not eof(Articles) do begin
>but what then?

>(I said it was a beginner's question! *grin*)
>RSVP, and Thanks in advance

Other Threads