Hello! I once had to solve the example of numbers, where I had to do type conversion plus declare alternative variables with input validation. Is it really necessary to work with strings such a position? Or in working with strings you can get by with the class?

I mean this position, as work with alternative variables. Well, the fact that Delphi - the removal of the brain. Who would doubt that

b1 := (InputBox('Ввод числа b', 'Введите число b:', '')); b := StrToFloat(b1); 
  • 2
    Really! Not only that Delfi (Delphi ??) ... Brain removal ... - Alexey Kotov
  • So what's the problem? In the desire to output InputBox to get float? Auxiliary function does not help? Or something else? - alexlz
  • I had a great desire to write everything in one line b: = StrToFloat (InputBox ('Enter a number', 'Enter a number:', '')); In this connection, the question is what gives the input of an alternative variable. Why is the option in two lines better than one line? - Prox
  • @Prox And where does the information come from, that it is generally "better"? - VioLet
  • one
    It is better here to go to si and not to break the brain of people with crookedly asked questions. - alex7249 2:42 pm

1 answer 1

You can solve the problem in three main ways:

  1. Write a class that displays InputBox, receives data from it, performs all the necessary actions (checking, processing ...). Of the benefits - in the main program there will be little code.
  2. Make it your way - in one line, enclosing the code in try-except.
  3. Make, as said, get the string, check the value (in any way possible), and then perform type conversion (this is actually an advantage over (2) - by and large you don't need a try-except block).