Recent

Author Topic: [Solved] Inc limitation  (Read 3601 times)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
[Solved] Inc limitation
« on: November 06, 2013, 10:57:05 pm »
When I used
Inc(ProgressBar1.Position)
rather than
ProgressBar1.Position := ProgressBar1.Position + 1
I received  the error message 'Error: Can't take the address of constant expressions'.

Is this expected behaviour?

In the help file Inc seems to handle various integer types declared as constants.


« Last Edit: November 25, 2013, 10:07:57 am by Windsurfer »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Inc limitation
« Reply #1 on: November 06, 2013, 11:44:25 pm »
ProgressBar1.Position is a property, while inc expects a variable.

In case of a property, typically, the compiler provides its value by calling a function, and assigns a new value through a procedure:

Code: [Select]
  TProgressBar = class(TCustomProgressBar)
...
  published
...
    property Position;

Code: [Select]
  TCustomProgressBar = class(TWinControl)
...
  public
...
    property Position: Integer read GetPosition write SetPosition default 0;

Deepaak

  • Sr. Member
  • ****
  • Posts: 454
Re: Inc limitation
« Reply #2 on: November 07, 2013, 05:20:18 am »
This is coding error. Inc function cannot be used for incrementing the progressbar.position. Because It is a property which is incremented or decremented by the help of seperate function/procedure. So for updating your progressbar.position please use variable with Inc to acheive this.
Holiday season is online now. :-)

Windsurfer

  • Sr. Member
  • ****
  • Posts: 368
    • Windsurfer
Re: Inc limitation
« Reply #3 on: November 07, 2013, 09:24:31 am »
Thanks for the helpful comments - so much to know, and so little time...

Component building is on my todo list.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12851
  • FPC developer.
Re: Inc limitation
« Reply #4 on: November 07, 2013, 09:55:37 am »
Note that in old (pre 2.6) versions this was possible if the property refered to a field. This was unintended behaviour and removed.

Zoran

  • Hero Member
  • *****
  • Posts: 1988
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Inc limitation
« Reply #5 on: November 07, 2013, 12:40:46 pm »
Note that in old (pre 2.6) versions this was possible if the property refered to a field. This was unintended behaviour and removed.

Actually, it was removed in 2.4: http://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

 

TinyPortal © 2005-2018