Assigned method



Object Assigned.
Smart pascal source code
type TMyObj = class Field : Integer; procedure Proc; procedure ProcVirtual; virtual; end; procedure TMyObj.Proc; begin WriteLn('Proc'); WriteLn(Field); end; procedure TMyObj.ProcVirtual; begin WriteLn('ProcVirtual'); WriteLn(Field); end; { unit1.pas } var o : TMyObj; Begin if Assigned(o) then WriteLn('bug'); o := TMyObj.Create; if Assigned(o) then WriteLn('Assigned'); // Assigned o.Field:=1234; o.Proc; // 1234 o.ProcVirtual; // ProcVirtual o:=nil; if not Assigned(o) then WriteLn('not Assigned'); // not Assigned try o.Field:=456; except on E : Exception do WriteLn(E.Message); // TypeError, Cannot set property 'Field' of null end; try o.Proc; except on E : Exception do WriteLn(E.Message); end; try o.ProcVirtual; except on E : Exception do WriteLn(E.Message); // TypeError, Cannot read property 'Field' of null end;