You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Procedure SomeObject.SetMyProp(Value: TObject);
begin
if Assigned(FMyProp) then
FMyProp.Free;
FMyProp := Value;
end;
then the 2 mentioned lines perform as follows.
The 1st line gets a copy of the object into LMemberValue
The second line then tries to set the value to the same value, but this ends up disposing of the value.
I suspect this is possibly a technicalality of the code and may not really be a bug, but might be something that cannot easily be remedied. Perhaps a new attribute could solve it. In the mean time I'll try to disable my free in the property setter until after the deserializing has completed.
Another solution would be not to free it in the setter but have the caller free it before setting it, but that doesn't quite feel right.
Any thoughts ?
The text was updated successfully, but these errors were encountered:
Procedure SomeObject.SetMyProp(Value: TObject);
begin
if Assigned(FMyProp) and (pointer(Value) <> pointer(FMyProp)) then
FMyProp.Free;
FMyProp := Value;
end;
so it now wont free it if its the same instance. I'll close this but leave the comments here in case they help someone else.
I've been having a problem with deserializing a class I have. It seems to destroy the property when it should not.
The code is in line 1247 (method TNeonDeserializerJSON.ReadMembers) and the 2 lines are
if I have a class with a property like
property MyProp: TObject read GetMyProp write SetMyProp;
and the SetMyProp looks like this
Procedure SomeObject.SetMyProp(Value: TObject);
begin
if Assigned(FMyProp) then
FMyProp.Free;
FMyProp := Value;
end;
then the 2 mentioned lines perform as follows.
The 1st line gets a copy of the object into LMemberValue
The second line then tries to set the value to the same value, but this ends up disposing of the value.
I suspect this is possibly a technicalality of the code and may not really be a bug, but might be something that cannot easily be remedied. Perhaps a new attribute could solve it. In the mean time I'll try to disable my free in the property setter until after the deserializing has completed.
Another solution would be not to free it in the setter but have the caller free it before setting it, but that doesn't quite feel right.
Any thoughts ?
The text was updated successfully, but these errors were encountered: