Destroy keyword



Destroy keyword
Pas2JS pascal source code
type TMyObj = class Field: Integer; end; { main.pas } var o: TMyObj; Begin WriteLn('Free'); o := TMyObj.Create; o.Free; try o.Free; except on E: Exception do WriteLn(E.Message); end; try WriteLn(o.Field); except on E: Exception do WriteLn(E.Message); end; try WriteLn(o.ClassName); except on E: Exception do WriteLn(E.Message); end; WriteLn('Destroy'); o := TMyObj.Create; o.Destroy; try o.Destroy; except on E: Exception do WriteLn(E.Message); end; try WriteLn(o.Field); except on E: Exception do WriteLn(E.Message); end; try WriteLn(o.ClassName); except on E: Exception do WriteLn(E.Message); end; WriteLn('nil'); o := TMyObj.Create; o := nil; o.Free; try WriteLn(o.Field); except on E: Exception do WriteLn(E.Message); end; try WriteLn(o.ClassName); except on E: Exception do WriteLn(E.Message); end; { <<<<<<<<<<<< CONSOLE OUTPUTS >>>>>>>>>>>>>>>>>>> Free 0 TMyObj Destroy 0 TMyObj nil TypeError, Cannot read property 'Field' of null TypeError, Cannot read property '$ClassName' of null }