[fpc-pascal]How to make a constructor failed?

Ingmar Tulva juss_it at ut.ee
Fri Aug 23 15:25:19 CEST 2002

On Thu, 22 Aug 2002, mili wrote:

}constructor TMyClass.Create(fn:String);
}  if not FileExists(fn) then begin
}    // ---> Here I want to make the new object nil
}  end;

You answered your question yourself: "Fail".

constructor TMyClass.Create (fn:String);
   if FileExists(fn) then Fail;

AFAIK this should do exactly what needed.

By the way, destructor should not be named Free - Free is another method
which calls Destroy. It is usually good idea to override TObject.Destroy.




"Salamanders can survive up to six hours outside a fire if regularly fed
pepper" (Scamander 1927).

More information about the fpc-pascal mailing list