[fpc-devel] Hom to initialize an object (old style object, not TObject)

Martin lazarus at mfriebe.de
Fri Nov 1 16:18:36 CET 2013


On 01/11/2013 15:10, Tomas Hajny wrote:
> Sorry if I overlooked something, but where is the variable of that type
> declared in your code? These objects may be either declared statically
> ("var B: TBar") or dynamically ("Result := New (TBar.Init)" - but then the
> return value must be of type PBar, not TBar).
Objects are  like (advanced) records.

So Result is a TBar, and result already has the memory it needs. "New" 
is not needed.

> If I understand it
> correctly, you initialize the object on the stack, but it would disappear
> from there (gets overwritten) immediately after the function return (the
> following function call would overwrite it).
>

It gets lost only, because i do not use the result of the function call.
But even if D did "SomVarBar := Foo;", I still get the warning.



More information about the fpc-devel mailing list