Recent

Author Topic: Argument cannot be assigned to  (Read 1034 times)

Neville

  • New Member
  • *
  • Posts: 41
Argument cannot be assigned to
« on: August 06, 2022, 08:50:17 pm »
Using Lazarus 2.2.0, I'm trying to assign to a set of byte variable which is a part of a record, in an array:

Code: Pascal  [Select][+][-]
  1. procedure TIVClass.SetMemberAvailability(x:word;A:setofbyte);
  2. begin
  3.    Member[x].MemberAvailability := A;
  4. end;
  5.  

I have so far failed to find any way around the error "Argument cannot be assigned to".

Has anyone any helpful suggestions please?
« Last Edit: August 07, 2022, 12:13:58 am by Martin_fr »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Argument cannot be assigned to
« Reply #1 on: August 06, 2022, 09:29:35 pm »
To assign values to routine arguments they must be declared as var or out.
However, in the minimal code you show, you don't assign any value to the argument A, but just copy it.
Is your MemberAvailability  property read-only?
Perhaps you should post a compilable example that shows the error.

bytebites

  • Hero Member
  • *****
  • Posts: 640
Re: Argument cannot be assigned to
« Reply #2 on: August 06, 2022, 10:18:23 pm »
Use code tags please.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9877
  • Debugger - SynEdit - and more
    • wiki
Re: Argument cannot be assigned to
« Reply #3 on: August 07, 2022, 12:14:57 am »
EDITED original message to add code tags.

@Nevile

[ code=pascal ]
[ /code ]

Neville

  • New Member
  • *
  • Posts: 41
Re: Argument cannot be assigned to
« Reply #4 on: August 07, 2022, 02:49:33 pm »
Thank you all for your helpful comments.  I'll follow them up,  and it looks as if they may hold the solution.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Argument cannot be assigned to
« Reply #5 on: August 08, 2022, 11:12:44 pm »
Has anyone any helpful suggestions please?

As the Member[‌x] property returns a record you must assign that to a variable, change the value you want (in this case MemberAvailability) and then assign the variable back to Member[‌x]. This is by design, because otherwise you would change a temporary copy of the value returned by Member[‌x].

 

TinyPortal © 2005-2018