Hi

The solution is to use interfaces, but if you don't it would be difficult to implement a factory pattern There is this thing in OO language users which seems to be the muddy area between scalars and objects, ie is a TStringList a simple object or a complex scalar, of course it doesn't help that Delphi garbage collects scalars
but not objects

Maybe i've been writing to much PHP

Neven




You guys don't consider a constructor a function then?

I think its totally stylistic, if you want to have functions returning objects fine, just make it plain that they do,

IMHO

Neven

The downside to having "creator function"s returning objects is that you
have to duplicate the code in TObject.Create to ensure safety, as Struan
pointed out.

// Regular usage: constructor code guarantees no memory leak possibility

  MyObject := TMyObject.Create;
  try
    ...
  finally
    MyObject.Free;
  end;

Replace TMyObject.Create with a creator function and you have to implement
its safety code again yourself:

// Function returning constructed object requires try/except to be safe

  function CreateMyObject: TMyObject;
  begin
    ...
    Result := TMyObject.Create;
    try
{
Any code you might put in here requires this encompassing try/except block
to prevent a memory leak occurring if an exception occurs
}
    except
      Result.Free;
      raise;
end; end;


And the same again for any additional levels of nesting. Not great from the
POV of encapsulation.

Cheers,
Carl


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe



_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

Reply via email to