☰ Contents · Computing

The Edit object

Lessons 47–48 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
48

Practical lesson

Textbook: pp. 105–106
GoalUses Edit and Label together to build small applications that check and process text; uses the Length and UpperCase functions.
New words
Length: a function that returns the number of characters in a string · LengthUpperCase: a function that converts a string to capital letters · UpperCaseOnChange: the event of the text in an Edit changing · OnChangeempty string: a string with no characters, written as '' · bo‘sh satr
Explanation

In the practical lesson three applications for working with Edit are created. The first is the “Character counter”: a word is typed in Edit1 and when the button is pressed Label1.Caption := 'Belgilar: ' + IntToStr(Length(Edit1.Text)); appears. Length also counts spaces and punctuation. The second is “Capital letters”: Edit2.Text := UpperCase(Edit1.Text); converts the text to capitals (UpperCase comes from the SysUtils unit, which is normally connected already in a new application). The third is clearing: in the OnChange event of Edit1 (double-click in the Object Inspector on the Events tab) write Label1.Caption := ''; so that the out-of-date character count disappears as soon as the text changes. In each application write the expected results in your notebook before testing.

Worked examples
Length('informatika') = 11 and Length('Ali Vali') = 8 (the space is counted too). If Edit1 holds kompyuter, the Label shows Belgilar: 9. The result of UpperCase('salom 5a') is SALOM 5A.
Clearing Label1 in OnChange: procedure TForm1.Edit1Change(Sender: TObject); ⏎ begin ⏎  Label1.Caption := ''; ⏎ end; After “Belgilar: 9” is shown, if the user adds one letter to the word in Edit1 the old number disappears, because it would now be wrong. Pressing the button again shows the new number.
Class activity

“The character counter”: each student writes 5 words in a notebook and calculates Length in advance; checks with the pair’s application and writes the reason for any difference.

Practice
1
What is Length('maktab')?
2
What is Length('10 A sinf') (spaces are counted)?
3
What is the result of UpperCase('ali')?
4
Why is clearing the old result in OnChange convenient for the user?