Crash Course Delphi, part 4: Event handlers

Let's code !

Our Foot-To-Meter Convertor still doesn't do anything useful. In this lesson, we'll add some real code to the event handlers.

btnFootToMeters's OnClick Event Handler

In lesson 3 we've put some temporary code in the event handler of btnFootToMeter. But what should this event handler really do?
  • the text "foot" should be shown in lblStartUnit.
  • the text of edInput should be converted to a numerical value.
  • From this number (the value in foot) the value in meter should be calculated.
  • This number is converted again to 'text', which is shown in lblResult.
  • Finally, the text ' meter' should added to the caption of lblResult.

We'll keep temporary values and texts in the variables Foot, Meter and ResultString. Variables have to be declared:
   - you indicate that they are variables via the reserved word var
   - you give their name followed by their type.

This is done BEFORE the reserved word begin in the routine. For the moment, don't worry about all the different types of variables. Later on, we shall come back to this in detail.

Now, let's code!

Lesson 3LESSON 3     HOME     LESSON 5 Lesson 5