Skip to content

Instantly share code, notes, and snippets.

@martinusso
Created June 13, 2012 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinusso/2923945 to your computer and use it in GitHub Desktop.
Save martinusso/2923945 to your computer and use it in GitHub Desktop.
"Left Side Cannot Be Assigned To" Compile Time Delphi Error
{interface}
type
TInnerRecord = record
Value: string;
end;
TClassA = class
public
InnerRecord: TInnerRecord;
end;
TClassB = class
private
FInnerRecord: TInnerRecord;
public
property InnerRecord: TInnerRecord read FInnerRecord write FInnerRecord;
end;
TClassC = class
public
procedure DoSomethingA();
procedure DoSomethingB();
procedure DoSomethingB_Error();
end;
{implementation}
procedure TClassC.DoSomethingA();
var
ClassA: TClassA;
begin
ClassA := TClassA.Create();
try
ClassA.InnerRecord.Value := 'correct implementation';
finnaly
ClassA.Free();
end;
end;
procedure TClassC.DoSomethingB();
var
ClassB: TClassB;
begin
ClassB := TClassB.Create();
try
with ClassB.InnerRecord do
Value := 'correct implementation';
finnaly
ClassB.Free();
end;
end;
procedure TClassC.DoSomethingB_Error();
var
ClassB: TClassB;
begin
ClassB := TClassB.Create();
try
ClassB.InnerRecord.Value := 'incorrect implementation'; // ERROR! "Left Side Cannot Be Assigned To"
finnaly
ClassB.Free();
end;
end;
@JTheiller
Copy link

type
PInnerRecord = ^TInnerRecord;

TInnerRecord = record
Value: string;
end;

TClassB = class
private
FInnerRecord: TInnerRecord;
function getInnerRecord...
procedure SetInnerRecord...

public
property InnerRecord: PInnerRecord read getInnerRecord write SetInnerRecord;
end;

function getInnerRecord...
Result := @FInnerRecord

procedure SetInnerRecord...
FInnerRecord := Value^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment