Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Most efficient method to display text file?

Status
Not open for further replies.

LEICJDN1

Technical User
Nov 27, 2002
201
GB
I wish to add a button which will allow the user to view the contents of a text file, in a seperate 'window' (i.e. not on the main form), and then close the text file and continue. No real need to edit text file (although would be nice)

How can this best be achieved? Create a new form and place the text file in a memo on the new form? Can you have a 'free' memo or similar? Is memo the best option? Can I just call notepad and use that?

Thanks for any suggestions.
 
Displaying the text file in a memo component is good.
If you want to call notepad try the following code:

ShellExecute(Application.Handle, 'open', 'notepad.exe', PChar(FileName), nil, SW_NORMAL)

FileName is the name of your textfile including the directory. If the text file is in the same directory as the exe then you only have to state the name of the textfile for example "MyText.txt". If it is in another directory then you have to specify the whole path.
You can use ParamStr(0) to get the directory where the program is executed from.
 
I personally would use a memo, it's easy to open the required file (as you can see from the following line of code):
Code:
  Memo1.Lines.LoadFromFile(CurrentFilename);
Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top