[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);
}begin
}  if not FileExists(fn) then begin
}    // ---> Here I want to make the new object nil
}  end;
}end;//TMyClass.Create
}

You answered your question yourself: "Fail".

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

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.

------

Ingmar

------

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





More information about the fpc-pascal mailing list