Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Inc , dec width.. Posted by porodoro on 9 Feb 2006 at 10:52 AM
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 :>



Report
Re: Inc , dec width.. Posted by zibadian on 9 Feb 2006 at 11:43 AM
: 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.
Report
Re: Inc , dec width.. Posted by porodoro on 10 Feb 2006 at 7:00 AM
: : 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 :)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.