Grade 10 learner will be required to save to and display a text file. However, this code will not earn any marks in grade 11 and 12.
Save to a text file from a RichEdit or an object with Items using the following code:
redOutput.Lines.SaveToFile(‘NameOfFile.txt’);
rgpOptions.Items.SaveToFile(‘NameOfFile.txt’);
Test if the file exists, before loading it into the RichEdit to avoid runtime errors:
If FileExists(‘NameOfFile.txt’) then
Display a text file in a RichEdit or an object with Items:
redOutput.Lines.LoadFromFile(‘NameOfFile.txt’);
cmbOptions.Items.LoadFromFile(‘NameOfFile.txt’);
Both SaveToFile, FileExists and LoadFromFile needs a String as an argument containing the name of the text file. This name can be built from user input. Remember to add the file extension to the end of the file name when building a name.
For the PAT, learners could save text files from the RichEdit, add the name of the file to a ComboBox and then write the ComboBox to a text file containing the names of the files. In Form OnActivate they can load this file into the ComboBox which will enable them to select a file to display in a RichEdit.