Search code examples
.netdelphisystem.drawingdelphi-prism

System.Drawing.Rectangle Cannot find property setter for "bottom" or "Left" or "Right" or "Top"


In Delphi Prism, I am trying to set the Rectangle properties, left right top or bottom, and compiler keeps saying that it can't find a setter to set a value to these properties for Rectangle.

I have looked at other stackoverflow questions related to this and have not found a good answer.

I want to be able to set the Rectangle it is top, bottom, right or left values to be able to do something like the following.

dragRect.right := dragRect.left;
dragRect.bottom := dragRect.top;

Obviously, you can't do this. How do you accomplish the samething in Delphi Prism?


Solution

  • As Hans Passant pointed out, it is important to understand the difference between value type and reference type. Because System.Drawing.Rectangle doesn't have setters for left, top, right or bottom, you simply can't set any values to them but only read what is already there. The only time they get updated is when you actually create the Rectangle object passing the height, width and X-Y points OR setting X, Y, height and/or width of a rectangle properties.

    Since in my program I am only trying to define the boundary or the area for drawing the shape of a rectangle, I set the X, Y, width or height. It works fine. As far as figuring out the width and height of a rectangle, you don't have to once you set its width and height once. Every time you reset the X and/or Y value of a rectangle, it maintains its width and height. Thus, it knows what its right and bottom values are.

    For instance, you can do this:

    dragRect.X := 100;
    dragRect.width := 10;
    

    but you can't do this:

    dragRect.left := 100;
    dragRect.right :=110;