[fpc-pascal]How to make a constructor failed?
Michael Van Canneyt
michael.vancanneyt at wisa.be
Thu Aug 22 17:37:15 CEST 2002
On Thu, 22 Aug 2002, mili wrote:
> Hello, Every one
>
> I intend to create my own class such as the following:
> >>>>
> type
> TMyClass = class(TObject)
> public
> constructor Create(fn:String);
> destructor Free;
> end;//TMyClass
>
> implementation
>
> 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
>
> demo:
> myclass:=TMyClass.Create('aaaa.txt');
> if myclass=nil then exit;// ---> Here I can check if the object is valid
> <<<<<<<<
>
> Can you tell me what's the constructor should be like to implement this?
As far as I know, there is no way to do this. The best you can do is
raise an exception and catch this.
Michael.
More information about the fpc-pascal
mailing list