This question has already been answered:

Is it possible to display values ​​through edit in the code (That is, replace the number 25 with Edit):

for j:=0 to len-1 do baze:=filtr+Dict[Random(25)+1]; 

That is, what would be the type:

  for j:=0 to len-1 do Pass:=Pass+Dict[Random(edit1.text)+1]; // Но тут я не знаю как правильно оформить, **потому как ошибка**. 

Reported as a duplicate by Kromster members, 0xdb , zed , kot-da-vinci , dlarchikov 9 Jun '18 at 13:20 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    In my opinion, this kind of questions you often ask. Try to approach this logically.
    1. In Edit1 you enter text, which means most likely a string value in the Text field.
    2. Random selects a random number, so the parameter must pass a numeric value.
    From all this it follows that you need to convert the string to a number. What StrToInt handles successfully. And in case of incorrect input, you can use StrToIntDef , where the second parameter is the value that the function returns in the case of an incorrect string.

     const MAX_VALUE: Integer = ???; // Максимальный индекс Dict[] ... for j:=0 to len-1 do Pass:=Pass+Dict[Random(StrToIntDef(Edit1.Text, MAX_VALUE))+1]; 
    • Grateful for the help. I ask questions as they arise, I mostly disassemble myself. But with what I can not cope, I ask. - Tatiana
    • 2
      @Tatiana, I said that you asked a similar question a few days ago and received a similar answer with the same explanations. Stackoverflow.com/a/828752/283852 - dr. FIN
    • FIN, Yes, but I just constantly missed the parameter: MAX_VALUE - Tatiana