Assigning of object properties to variables

Hi.
In onTimer event I have something like this:


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


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

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


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

Comments

  • When you write such a declaration like this
    [code]
    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.

    Regards,
    Ricardo




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!

Categories

In this Discussion