Menu

Bug report (COM interface): TCircuit.Enable and TCircuit.Disable using the wrong "Name"

Experts
2023-08-22
2023-09-12
  • Paulo Meira

    Paulo Meira - 2023-08-22

    Hi all,
    This was reported to us on GitHub but also affects the official COM interface.

    In the circuit interface (TCircuit.Disable(const Name: WideString), TCircuit.Enable(const Name: WideString)), the Name variable is ambiguous since there is the procedure argument Name and ActiveCircuit[ActiveActor].Name, introduced via WITH scoping. Effectively, the circuit name is used instead of the argument. This will then either enable the wrong element or use the latest activated element.

    As a workaround, COM users could use the Text interface instead (e.g. editing and setting enabled=n, or using the disable DSS command).

    Related code in: https://sourceforge.net/p/electricdss/code/3639/tree/trunk/Version8/Source/DLL/ImplCircuit.pas#l392

    A minimal sample in Python to reproduce the issue:

    import comtypes.client
    dss = comtypes.client.CreateObject('OpenDSSengine.DSS')
    print(dss.Version)
    
    dss.Text.Command = 'new Circuit.test'
    dss.Text.Command = 'new Load.A'
    dss.Text.Command = 'new Load.B'
    
    # Try to disable the first load
    dss.ActiveCircuit.Disable('Load.A')
    # Here we can see that the it uses the latest activated element, disabling it
    print(dss.ActiveCircuit.ActiveDSSElement.Name, dss.ActiveCircuit.ActiveDSSElement.Properties['enabled'].Val)
    
    # And here we manually check both loads
    dss.ActiveCircuit.SetActiveElement('Load.A')
    print(dss.ActiveCircuit.ActiveDSSElement.Name, dss.ActiveCircuit.ActiveDSSElement.Properties['enabled'].Val)
    dss.ActiveCircuit.SetActiveElement('Load.B')
    print(dss.ActiveCircuit.ActiveDSSElement.Name, dss.ActiveCircuit.ActiveDSSElement.Properties['enabled'].Val)
    

    Current output:

    Version 9.6.1.3 (64-bit build); License Status: Open 
    Load.b false
    Load.a true
    Load.b false
    

    To fix this, either renaming the argument Name in the related code to make it distinct or removing the use of the WITH construct both work. There are other similar issues related to WITH in the Delphi codebase.

     
    • Davis Montenegro

      Dear Paulo,

      Thanks for the heads up, this change will be reflected in our next release.

      Best regards

      Davis

       

Log in to post a comment.