AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ 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
47

Entering data into an application

Textbook: pp. 102–105
GoalUses the Edit (input field) object: sets Text, ReadOnly, MaxLength and PasswordChar, checks the entered text and creates an application that greets the user.
New words
Edit: an input field where the user types one line of text · EditText: the property that holds the string typed in an Edit · TextReadOnly: if True, the user cannot change the text · ReadOnlyPasswordChar: the character shown instead of the typed letters · PasswordChar
Explanation

An application must also receive data from the user; the simplest tool is the Edit (Standard tab). It has no Caption: the typed text is held in the Text property, so it is usually used together with a Label. If ReadOnly = True the user cannot change the text but the application can write to Text: because an Edit has a frame it shows a result neatly. MaxLength limits the number of characters that can be typed (4 for a year), and PasswordChar shows a character instead of the letters (PasswordChar := '*'). When texts are compared, capital and small letters differ: 'abc' = 'ABC' is false. Writing a password inside the program code is not safe: anyone who sees the code learns it; do not type your own real password into learning applications.

PropertyMeaning
Textthe typed text
ReadOnlyTrue – the user cannot change it
MaxLengthlimit of characters
PasswordCharshows a sign instead of the letters
💡 Where will I use this?
In real life

When a pupil types an invented secret word for a game into an input field, the letters appear as stars, so a classmate behind cannot read it. The program itself still knows the typed text. This is how a private word is hidden from onlookers.

Who uses it

Web and app developers, designers of banking apps and information security specialists protect input fields.

Try it today

Draw an input box on paper and show how the letters of an invented word turn into stars; never write a real password of yours.

Worked examples
Pascal
1procedure TForm1.Button1Click(Sender: TObject);
2begin
3  if Edit2.Text = Edit1.Text then
4    Edit3.Text := 'Topdingiz!'
5  else
6    Edit3.Text := 'Yana bir urinish';
7end;
The “Secret word” game: the first player types a word in Edit1 (PasswordChar = '*', so the letters are hidden), the second types a guess in Edit2, and Edit3 shows the result (ReadOnly = True) – code above. With olma in Edit1 and olma in Edit2: Topdingiz!; with Olma in Edit2: Yana bir urinish (a capital letter makes a difference).
A birth-year field: MaxLength := 4. If the user tries to type 20091, the fifth character is not accepted and the text stays 2009. The statement Edit1.Text := ''; clears the field: Text becomes the empty string.
Class activity

“Secret word”: a pair builds the game application; another pair tests it with correct, wrong and capital-letter guesses and writes a table of results.

Practice
1
Which property holds the text typed in an Edit?
2
If MaxLength = 4 and 12345 is typed, what stays in the field?
3
If PasswordChar := '*', what is shown instead of the password letters?
4
Why is ReadOnly set to True for an Edit that shows a result?
Story of the Week · The Khwarizmi WayPay that doubles every dayClose the week: all of this week’s subjects in one storyRead →