Assigning of object properties to variables

In onTimer event I have something like this:

.procedure TForm1.Timer1Timer(Sender: TObject);
. top: integer;
. top := Button1.Top;
. top := top + 1;

it doesn't work. But if I use this:

.procedure TForm1.Timer1Timer(Sender: TObject);
. Button1.Top := Button1.Top + 1;

it works fine.
Can anyone explain that please? In JavaScript I allways assign object model to variables. {document.forms[0]... etc.}

Thanks in advance. Jiri


  • When you write such a declaration like this
    var top: integer;

    top := Button1.Top; [/code]

    You're coping the value of the property 'Button1.Top' to a integer variable called 'top', and not making a reference of 'Top' to the property 'Button1.Top', so when the line

    [code] top := top + 1; [/code]

    is executed, it increments the top's variable value, and the value of Button1.Top doesn't change.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion