On Jul 29, 2009, at 8:35 AM, Dragos Ionel wrote:

On Wed, Jul 29, 2009 at 3:24 AM, Agha Khan <agha.k...@me.com> wrote:
On Jul 28, 2009, at 7:59 PM, Kiel Gillard wrote:

On 29/07/2009, at 12:52 PM, Agha Khan wrote:

Hi:
I have a struct
@interface PngButton : UIButton
{
@public
      bool OffPos;
      CGPoint horizontalLoc;
      CGPoint verticalLoc;
}
@property (assign) bool OffPos;
@property (assign) CGPoint horizontalLoc;
@property (assign) CGPoint verticalLoc;
@end


No, you have an Objective-C class.

PngButton* pPngButton   = [PngButton
buttonWithType:UIButtonTypeInfoDark];
[pPngButton setFrame:CGRectMake(screenRect.size.width - 70.0, 50.0, 36,
36)]; // No problem

pPngButton.verticalLoc = CGPointMake((bVerticalDisplay == YES) ? 250 :
410, 50.0);

I get an error
error: lvalue required as left operand of assignment

Why it is not working? I shouldn't get this error.
Any help will be very much appreciated.


Do you get any warnings?

Try this and see what happens:
pPngButton.verticalLoc = CGPointMake((bVerticalDisplay == YES ? 250.0 :
410.0), 50.0);

Kiel



Hi:
Thank you for your reply.
Oh yes. It an Objective-C class.

regardless I place (bVerticalDisplay == YES) or not. The function silently
fails, with no warnings.
The I decided to
pPngButton.verticalLoc.x = (bVerticalDisplay == YES) ? 250 : 410;
This time I got warning.

error: lvalue required as left operand of assignment

Many thanks

-Agha



verticalLoc and x are readonly values, you cannot assign them.

use the frame property, first to retrieve it, change the x value and then to
reassign to the button.

something like

CGFrame frame = pPngButton.frame;
frame.x = ...;
pPngButton.frame = frame;

Dragos



No, that isn't correct at all - he's declared verticalLoc as a property that is perfectly valid to set (though, since this is the iPhone, should be declared as nonatomic as well)

The problem is that the (simplified) code:

        pPngButton.verticalLoc.x = 410;

is equivalent to writing:

        [pPngButton verticalLoc].x = 410;

since pPngButton.verticalLoc is used as a getter in this case (since your code then accesses the "x" field of the result).

This would be similar to:

        CGPointMake(100,200).x = 410;

i.e., you call a function (which returns a CGPoint value) and then you try to set one of the fields of the CGPoint value (which is then thrown away).

Things like structures returned from a function, or scalar values, pointers, etc... are referred to as "r-values", meaning they are values that appear on the right hand side of an assignment - they aren't stored in meaningful locations in memory, they just have a "value" but not "storage". Variables (or memory locations) that can appear on the left hand side of an assignment are called "l-values" - they are values, but they also are stored somewhere and can have their values changed.

So what you'd need to do is:

        CGPoint pt = pPngButton.verticalLoc;
        pt.x = (bVerticalDisplay == YES) ? 250 : 410;
        pPngButton.verticalLoc = pt.x;



Glenn Andreas                      gandr...@gandreas.com
 <http://www.gandreas.com/> wicked fun!
Mad, Bad, and Dangerous to Know

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to