On Mon, Jul 5, 2010 at 5:14 PM, Martin <f...@mfriebe.de> wrote: > > That would be, if a crash happens inside obj1.createObj? Because otherwise > the obj is stored in obj2. > > If it happens in there, then handle it in there => there is result as > variable. > > function TMyObject.creatObj : TSomeObj; > begin > result := TsomeObject.create; > end; > > > function TMyObject.creatObj : TSomeObj; > begin > result := TsomeObject.create; > try > DoFooBar; > except > result.Free; // will not be used by caller, but be aware it has still a > value, which now is invalid > end; > end; > > In the line > result := TsomeObject.create; > > the only crash that can happen is inside "create" => a crash in the > constructor is handled by the compiler, the object will be freed.
Thanks, but lets continue :) In another words, get you method: > function TMyObject.creatObj : TSomeObj; > begin > result := TsomeObject.create; > end; If I have a variable myObj, I can do this: someObj := myObj.createObj; This is the same: someObj := TsomeObject.create; Rigth? But if a remove the variable *someObj* and call like this: myObj.createObj; // I _removed_ the *someObj* here!!! What will happen with the "result" variable? Is it released by the compiler? Marcos Douglas _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal