RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TStrings.LoadFromFile Method

Fills the list with the lines of text in a specified file.

Pascal
procedure LoadFromFile(const FileName: string); virtual;
C++
virtual __fastcall LoadFromFile(const AnsiString FileName);

Call LoadFromFile to fill the list of the TStrings object from the file specified by FileName. LoadFromFile first clears any strings already in the list. Then, each line in the file, as indicated by carriage return or linefeed characters, is appended as a string in the list.

Note: LoadFromFile uses the Add method to add the strings that are read from the file.
 

C++ Examples: 

 

/*
This example requires two TRichEdit controls placed on the
form.  When the form becomes visible, the first Rich Edit
control will display the rich text in its raw form, including
formatting characters. The second will show the rich text in
its intended format.
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// you may need to change this path to suit your environment
  char const *Path = "..\\OVERVIEW.RTF";
  RichEdit1->PlainText = true;
  RichEdit1->Lines->LoadFromFile(Path);
  RichEdit2->PlainText = false;
  RichEdit2->Lines->LoadFromFile(Path);
}

 

Delphi Examples: 

{
This example requires two TRichEdit controls placed on the 
form.  When the form becomes visible, the first Rich Edit 
control will display the rich text in its raw form, including
formatting characters. The second will show the rich text in 
its intended format.
}

procedure TForm1.FormCreate(Sender: TObject);
const
  // you may need to change this path to suit your environment
  Path = 'OverView.RTF';
begin
  RichEdit1.PlainText := True;
  RichEdit1.Lines.LoadFromFile(Path);
  RichEdit1.ScrollBars := ssVertical;
  RichEdit2.PlainText := False;
  RichEdit2.Lines.LoadFromFile(Path);
  RichEdit2.ScrollBars := ssVertical;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!