Please tell me how to fix some problems when working with a form. On the form in the Memo, when you press a key, an array of 10 random numbers is generated. How to make the array appear only once, and not with each press?

procedure TForm1.Memo1Change(Sender: TObject); var a: Tarr; i: integer; str: string; begin if memchange then exit; memchange := true; randomize; str := ''; for i := 1 to 10 do begin a[i] := random(10); str := str + inttostr(a[i]) + ' '; end; Memo1.Lines.Add(str); memchange := false; end; 

Another form should have two edit components into which the user, after receiving the array, must enter: a number (element index), which is calculated using the formula (low(array)+high(array)) div 2 (first edit), index 4 ; number - the value of this element (second edit). And in case the user is not right, point out the error and ask to try again. I can not figure out exactly how to implement it. Made a check on the index, but nothing happens.

 procedure TForm3.Edit1Change(Sender: TObject); procedure CheckPivot(var a: Tarr); var pivot, pivoted: integer; begin pivot := (low(a) + high(a)) div 2; pivoted := strtoint(Edit1.Text); if pivot <> pivoted then ShowMessage('Неверно'); Edit1.SetFocus; end; begin end; 
  • What does not suit you in the first code snippet? - Igor
  • @Igor, the array will appear as many times as the user presses on the keyboard, can you make it so that you can generate the array only once, that is, with subsequent presses, a new array was not created? - yashi
  • 3
    remove the line memchange := false; - Igor
  • 1. Probably the OnCreate form event will suit you. It will work only once at the start. And for Memo, set the ReadOnly:=true property ReadOnly:=true 2. The array a declared in the Memo1Change method, how do you access it to call CheckPivot - androschuk

0