1
votes

I am migrating the code from Delphi 7 to XE2 one of the Graphical module. we are using TRect variable , the old code is working in Delphi 7 without issue

Ex:

Var
  Beold : TRect
begin
  Beold.left := Beold.right;
end.

while porting the code to new XE2 we are facing the issue E0264 : Left side cannot be assigned to

Can you please explain what is the changes in XE2 TRect and D7, how we can assign the valuse

2
Please show code that exhibits the behaviour that you describe. Until we know what the problem is, it is hard to help. - David Heffernan
TRect is declared as an advanced record in XE2. But this will not explain what you are reporting. Please show real code. - LU RD
I removed the database and sqlserver-2008 tags, as there is no mention of either of those subjects in your question. Also, when you post questions, post real code. As I said below, the code you posted compiles fine on both XE and XE2, so it can't be the code you're actually using. Posting made-up code does exactly what this one did - it can hide the actual problem (or like this one, not even produce the problem at all, because it's not the real code). If you want help, ask a real question with real code that produces the problem you're trying to solve. - Ken White

2 Answers

9
votes

The code you posted compiles and runs fine in a quick Delphi test app, so it's not your real code.

I'd suspect what you've hit is a change in the with statement when it's related to using properties, however. There was a bug in previous versions of Delphi that existed for many years that was finally fixed recently. IIRC, it was first mentioned in a note in the README.HTML file for D2010. It's been added to the documentation in XE2 (not as a behavior change, but the new behavior is documented). The documentation is located here at the docwiki.

(Additional info: It must have been 2010 where it changed; Marco Cantù's Delphi 2010 Handbook mentions it on page 111 as "The With Statement Now Preserves Read-Only Properties" which describes this behavior and the solution I indicated below.)

Instead of accessing the property of a class directly using a with statement, you now need to declare a local variable, and read and write the whole thing directly (error handling omitted for clarity - yes, I know there should be a try..finally block to free the bitmap).

var
  R: TRect;
  Bmp: TBitmap;

begin
  Bmp := TBitmap.Create;
  Bmp.Width := 100;
  Bmp.Height := 100;
  R := Bmp.Canvas.ClipRect;
  { This block will not compile, with the `Left side cannot be assigned to` error
  with Bmp.Canvas.ClipRect do
  begin
    Left := 100;
    Right := 100;
  end;
  }
  // The next block compiles fine, because of the local variable being used instead
  R := Bmp.Canvas.ClipRect;
  with R do
  begin
    Left := 100;
    Right := 100;
  end;
  Bmp.Canvas.ClipRect := R;
  // Do other stuff with bitmap, and free it when you're done.
end.
0
votes

turns out, using

  with (Bmp.Canvas.ClipRect) do
  begin
    Bottom := 100;
  end;

throws error: [Left side cannot be assigned to]

Yet,

  with Bmp.Canvas.ClipRect do
  begin
    Bottom := 100;
  end;

does not.

Delphi 10.3.3 is just as finicky about parenthesis as the older versions.