Practical lesson
In the practical lesson three applications are created. 1) “Even numbers”: in the OnCreate procedure of Form1 the loop for i := 1 to 12 do ListBox1.Items.Add(IntToStr(2 * i)); fills the list with 12 items. 2) “Moving”: a button adds the item chosen in ListBox1 to ListBox2 and removes it from ListBox1: ListBox2.Items.Add(ListBox1.Items[i]); ListBox1.Items.Delete(i); where i := ListBox1.ItemIndex. 3) “Day plan”: a subject is chosen from a ComboBox and minutes (10 to 90) from a SpinEdit; when the button is pressed a “subject – minutes” line is added to ListBox2 and the total time is summed in a Label. In every application check the number of items through Items.Count and calculate the result in advance and write it in your notebook.
When forming teams, a teacher moves invented names from a “waiting” list to a “team” list. After each move the total of names in the two lists stays the same as before. If the total changes, a name has been lost or added twice.
App developers write such moving for adding things to a basket or building a playlist; organisers also divide participants into groups.
Write invented numbers on 8 cards, move 3 of them to another pile and check that the two piles still add up to 8 cards.
1procedure TForm1.FormCreate(Sender: TObject); 2var i: Integer; 3begin 4 for i := 1 to 12 do 5 ListBox1.Items.Add(IntToStr(2 * i)); 6end;
| ListBox1 | ListBox2 | Total | |
|---|---|---|---|
| before | 12 | 0 | 12 |
| after “18” is moved | 11 | 1 | 12 |
“The sorter”: a group moves five of the 12 numbers one by one and shows that the sum of the item counts of the two lists stays 12 at every step.