Board index » delphi » Insert Text into a RichEdit

Insert Text into a RichEdit

If I want to insert text from a file into a TRichEdit, is there a more
efficient way than simply loading a line of the file, calling
RichEdit.Lines.Insert, then repeating? That just seems so inefficient.

Have a great day!

Ernest
(efairch...@home.com)

_____________________
"Law -- a subject that seems to serve two purposes: two make lawyers rich
and to make more lawyers."

Visit my website at http://www.public.asu.edu/~ernestf

 

Re:Insert Text into a RichEdit


That looks good, thanks.

Have a great day!

Ernest
(efairch...@home.com)

_____________________
"Law -- a subject that seems to serve two purposes: two make lawyers rich
and to make more lawyers."

Visit my website at http://www.public.asu.edu/~ernestf

Quote
"Mauro Patino" <M-Pat...@govst.edu> wrote in message

news:3B2F6612.93DA5796@govst.edu...
Quote
> Ernest Fairchild wrote:

> > If I want to insert text from a file into a TRichEdit, is there a more
> > efficient way than simply loading a line of the file, calling
> > RichEdit.Lines.Insert, then repeating? That just seems so inefficient.

> You can use the SelText property.

> The file will be inserted where your cursor is placed.

> var
>  FileToInsert: TStringList;
> begin
>  FileToInsert := TStringList.Create;

>  if OpenDialog1.Execute then
>  begin
>    FileToInsert.LoadFromFile(OpenDialog1.FileName);
>    RichEdit1.SelText := FileToInsert.Text;
>  end;

>  FileToInsert.Free;
> end;

Re:Insert Text into a RichEdit


Quote
Ernest Fairchild wrote:
> If I want to insert text from a file into a TRichEdit, is there a more
> efficient way than simply loading a line of the file, calling
> RichEdit.Lines.Insert, then repeating? That just seems so inefficient.

You can use the SelText property.

The file will be inserted where your cursor is placed.

var
 FileToInsert: TStringList;
begin
 FileToInsert := TStringList.Create;

 if OpenDialog1.Execute then
 begin
   FileToInsert.LoadFromFile(OpenDialog1.FileName);
   RichEdit1.SelText := FileToInsert.Text;
 end;

 FileToInsert.Free;
end;

Re:Insert Text into a RichEdit


urm why not just use WHatever = LoadFromFile  or SaveToFile
thats gotta be the best way surely :)

Quote
"Ernest Fairchild" <efairch...@home.com> wrote in message

news:3b2f6237$1_2@dnews...
Quote
> If I want to insert text from a file into a TRichEdit, is there a more
> efficient way than simply loading a line of the file, calling
> RichEdit.Lines.Insert, then repeating? That just seems so inefficient.

> Have a great day!

> Ernest
> (efairch...@home.com)

> _____________________
> "Law -- a subject that seems to serve two purposes: two make lawyers rich
> and to make more lawyers."

> Visit my website at http://www.public.asu.edu/~ernestf

Other Threads