Reported by Michael Stratmann; checked by Reinier Sterkenburg
Consider the following code:
In some unit:
type
TMyRecord = record
Field1: Integer;
end;
TMyClass = class
private
FRec: TMyRecord;
public
property Rec: TMyRecord read FRec;
end;
In another unit (or program):
var
AnObj: TMyClass;
begin
AnObj := TMyClass.Create;
AnObj.Rec.Field1 := 1; // compiler error: Left side cannot be assigned to
with AnObj.Rec
do Field1 := 1; // compiles fine
(In Delphi 1, the compiler's behaviour is consistent: it gives
an error on both assignments: Invalid variable reference.)
It is strange (wrong) that the line with the first assignment does not
compile while the other with the with statement does.
Either both should compile or both should not.
If the Rec property is an object (class), then both lines compile.
(And if it's a static object, it behaves the same as the record case). |