Conseqences of assigning self
- by Vegar
Hi,
Found a piece of code today, that I find a little smelly...
TMyObject.LoadFromFile(const filename: String);
begin
if fileExists(filename) then
self := TSomeObjectStreamer.ReadObjectFromFile(filename);
end;
If this code works, it will atleast leak some memory, but does it work?
Is OK to assign to self in this manner?
What if the streamed object is of a different subclass then the original self?
What if the streamed object is of a different class with no common ancestore to the original self?