: : Here's what i got :
: :
: : 1 form (form1)
: :
: : 1 Timage Object (img)
: :
: : 1 timer (timer1)
: :
: : 1 Button (btn)
: :
: : 1 variable named X
: :
: : ----
: : Button code:
: : if timer1.enabled then
: : timer1.enabled:=false
: : else
: : timer1.enabled:=true;
: : -----
: : timer code:
: : var x:integer;
: :
: : timer1.interval:=20;
: :
: : x:=img.width
: :
: : if (x>=10) and not(x<=215) then
: : begin
: : img.width:=img.width + 1;
: : end else begin
: : img.width := img.width - 1;
: : end;
: : -------
: :
: : As you can see im trying to increase img's width
: : and decrease it back to custom size (in both cases).
: : (in infinite loop)
: :
: : Well , for some reason it justs goes from its current position to 10.
: :
: : Can someone fix my code ?
: :
: : thanks for reading my thread :>
: :
: :
: The easiest way is to store the direction of the change in the X variable. If the width reaches maximum value, you switch the direction around, until it reaches the minimum value. In code:
:
: Image1.Width := Image1.Width + X;
: if Image1.Width = 215 then
: X := -1;
: if Image1.Width = 10 then
: X := 1;
:
: For this trick to work, X must be a field in the form containing the OnTimer event. Also X must be set to 1 in the OnCreate() of the form.
:
Cool , thanks :)