Created
June 13, 2012 13:06
-
-
Save martinusso/2923945 to your computer and use it in GitHub Desktop.
"Left Side Cannot Be Assigned To" Compile Time Delphi Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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^