IScriptObj.Destroyed should be a read-only property

Issue #38 closed
Anders Melander created an issue

Since the IScriptObj.Destroyed property setter (TScriptObjInstance.SetDestroyed) completely ignores the value being set, the property should be read-only and the action of marking an object destroyed, with the side effects, performed by a regular method with no parameters.

For example:

   IScriptObj = interface (IDataContext)
      ['{8D534D1E-4C6B-11D5-8DCB-0000216D9E86}']
      function GetClassSym: TClassSymbol;
      function GetExternalObject: TObject;
      procedure SetExternalObject(value: TObject);
      function GetDestroyed : Boolean;

      procedure SetDestroyed;

      property ClassSym : TClassSymbol read GetClassSym;
      property ExternalObject : TObject read GetExternalObject write SetExternalObject;
      property Destroyed : Boolean read GetDestroyed;
   end;

Comments (2)

  1. Eric Grange repo owner

    The Destroyed property of IScriptObj is not meant to necessarily destroy the underlying Delphi-side object(s), but to mark the script-side object as being destroyed, so that further references from the script will trigger an exception on the script-side.

    The idea is that object life-cycle on the script-side and object life-cycle on the Delphi-side can be totally decoupled.

  2. Anders Melander reporter

    Yes I'm aware of what it does. I'm just objecting to the use of a boolean property setter that ignores the value being set.

    I.e. currently

    ScriptObj.Destroyed := True;
    

    and

    ScriptObj.Destroyed := False;
    

    does exactly the same. It would be better to use a method instead:

    ScriptObj.SetDestroyed;
    
  3. Log in to comment