My application should generate a random sum calculate the answer then put it in a edit box on a panel and then the panel should move down and repeat (I have done all of this). OK the problem is while the panel is moving down nothing else works it is as if everything is disabled.
unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls, StdCtrls, math, Buttons;
type
TForm1 = class(TForm)
Image1: TImage;
Panel1: TPanel;
Edit1: TEdit;
Panel6: TPanel;
Shape1: TShape;
Panel7: TPanel;
Label1: TLabel;
Edit6: TEdit;
Label2: TLabel;
Button1: TButton;
Image5: TImage;
Edit7: TEdit;
Image2: TImage;
Label3: TLabel;
Timer1: TTimer;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Image2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var hori : integer;
vert : integer;
back : integer;
value1 : integer;
value2 : integer;
answer : integer;
star: integer;
stranswer: string;
k : integer;
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
begin
panel1.hide;
panel7.Hide;
back:=0;
star:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
stranswer:= inttostr(answer);
if edit6.Text=stranswer then
begin
star:=star+1;
edit7.text:=inttostr(star);
end;
button1.Caption:='Next';
panel7.Show;
edit6.SetFocus;
panel1.show;
randomize;
hori:=random(840);
value1:=random(10);
value2:=random(10);
panel1.Top:=0;
panel1.Left:=hori;
update;
answer:=value1+value2;
edit1.text:=(' '+inttostr(value1)+' + '+inttostr(value2));
for k:= 1 to 512 do
begin
vert:= vert+1;
panel1.Top:= vert;
update;
sleep(50)
end;
end;
procedure TForm1.Image2Click(Sender: TObject);
begin
back:=1;
form5.Close;
button1.show;
end;
end.
If you want I can send you a picture of the form.
If you can please help me.
You move the panel down in 512 single pixel steps with a 50ms sleep in between each step. Since you don’t process any messages in that time, your app will be unresponsive for the 25s it takes to animate the panel. The program hangs because you have failed to service the message queue.
The solution is to use a timer rather than a loop. In
Button1Clickyou need to start the timer ticking.The timer procedure is like this:
These functions would look like this: