Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop while terminate the program

Status
Not open for further replies.

delphinewbie

Programmer
Dec 10, 2003
14
0
0
MY
I put the following code for move the mouse cursor(loop),

procedure TForm1.FormCreate(Sender: TObject);
var i :integer;
begin
i:=0;
while i =0 do
begin
if i=0 then
begin
Mouse.CursorPos := Point(200,40);
sleep(5000);
i :=1;
end;
if i = 1 then
begin
Mouse.CursorPos := Point(200,150);
sleep(5000);
i :=0;
end;
end;
end;


But the problem is that when everytime i run the program, i need to restart my pc again
in order to quit or exit the program. WHat should i do then if i want the cursor no more
moving after i close the application .. ? thx in advance for ya help ..
 
You've created an infinite loop.

What are you trying to do with the mouse cursor? and
At what point (in the programs execution)?
 
I can't imagine the need to do this, but...

If what you want your program to do is cause the mouse to iterate between two positions on the screen every five seconds then you would use a TTimer control with its Iterval property set to 5000 and its Enabled property set to True and the following code on its OnTimer event.
Code:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Timer1.Tag = 0 then begin
    Mouse.CursorPos := Point(200,40);
    Timer1.Tag := 1;
  end else begin
    Mouse.CursorPos := Point(200,150);
    Timer1.Tag := 0;
  end;
end;
Good luck!
 
A more economical (and slightly tongue in cheek) version of Punchinello's code:
Code:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Mouse.CursorPos := Point(200, (1-Timer1.Tag)*40 + Timer1.Tag*150);
  Timer1.Tag := 1 - Timer1.Tag;
end;

Andrew


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top