[fpc-pascal] methods of an object to create others objects

Marcos Douglas md at delfire.net
Mon Jul 5 20:48:40 CEST 2010


We can to use methods of an object to create others objects, or this
is a bad programming practice?
eg:
var
  obj1, obj2: TmyObject;
begin
  obj1 := tobj1.create; //ok
  obj2 := obj1.createObj; // is this recommended?
  try
  //...
  finally
    obj1.free;
    obj2.free;
  end;
end;

Why I ask this:
If not exists the variable obj2 in call obj1.createObj will happen a
memory leak, right? Because there is not variable to release.


Marcos Douglas



More information about the fpc-pascal mailing list