diff --git a/src/Controls/CapControl.pas b/src/Controls/CapControl.pas index b7e371a30..b3f9aa649 100644 --- a/src/Controls/CapControl.pas +++ b/src/Controls/CapControl.pas @@ -529,6 +529,8 @@ destructor TCapControlObj.Destroy; end; procedure TCapControlObj.RecalcElementData; +var + effElement: TDSSCktElement = NIL; begin // Check for existence of capacitor @@ -568,17 +570,21 @@ procedure TCapControlObj.RecalcElementData; DoErrorMsg(FullName, Format(_('Terminal number %d does not exist.'), [ElementTerminal]), _('Re-specify terminal number.'), 362); - end - else - begin - // Sets name of i-th terminal's connected bus in CapControl's buslist - Setbus(1, MonitoredElement.GetBus(ElementTerminal)); - // Allocate a buffer bigenough to hold everything from the monitored element - ReAllocMem(cBuffer, SizeOF(cbuffer[1]) * MonitoredElement.Yorder); - ControlVars.CondOffset := (ElementTerminal - 1) * MonitoredElement.NConds; // for speedy sampling + Exit; end; + effElement := MonitoredElement; + end + else + begin + effElement := ControlledElement; end; + // Sets name of i-th terminal's connected bus in CapControl's buslist + Setbus(1, effElement.GetBus(ElementTerminal)); + // Allocate a buffer bigenough to hold everything from the monitored element + ReAllocMem(cBuffer, SizeOF(cbuffer[1]) * effElement.Yorder); + ControlVars.CondOffset := (ElementTerminal - 1) * effElement.NConds; // for speedy sampling + // Alternative override bus if ControlVars.VoverrideBusSpecified then with ControlVars do @@ -815,7 +821,7 @@ procedure TCapControlObj.Sample; else ControlVars.PresentState := CTRL_OPEN; - with MonitoredElement, ControlVars do + with ControlVars do begin ShouldSwitch := FALSE;