Text area

In Lazarus there is a component text area, located in the Standard tab next to the edit line under the name Memo (Figure 120). With it we know to display an existing text file in the form, listing it to the graphical area and save them into a new text file. 

Figure 120: Text area component
Figure 120: Text area component

When we wanted to write or portray objects in the graphics area, we did it with commands that started with the words Image1.Canvas, because we have worked with component Image1 and we have drawn on its canvas. The text area works on a similar principle. If we want to work with it, we need to use the command starting with Memo1.Lines because we want to work with the Memo1 component, and we want to work with all its lines. If we want to load a file into the text area, we'll do this using the Memo1.Lines.LoadFromFile ('filename.extension');. Instead of a specific file name, we can use the path to the file if that file is not in the project folder. The following example loads a text file readme.txt in the text area, located in application folder (Figures 121 and 122). 

Figure 121: Loading a text file into a text area
Figure 121: Loading a text file into a text area
Figure 122: Text area with loaded text file
Figure 122: Text area with loaded text file

We can write, delete, edit text in this open document. However, these changes are not automatically transferred to the file, so you must save them using the Memo1.Lines.SaveToFile command ('filename.extension');. Other commands that are used to work with the text area are

Memo1.Lines.Clear;     the command deletes the text area and all its contents

Memo1.Lines.Append ('text');     the command adds a line of entered text to the end of the

text area   

Both commands were used in the following example (Figures 123 and 124). One button prints randomly generated numbers in rows and deletes the second text area.   

Figure 123: Generating Random Numbers in Text Area
Figure 123: Generating Random Numbers in Text Area
Figure 124: Generation and printout result for text area
Figure 124: Generation and printout result for text area
Vytvorte si webové stránky zdarma! Táto stránka bola vytvorená pomocou služby Webnode. Vytvorte si vlastný web zdarma ešte dnes! Vytvoriť stránky