You can't access the array fields that way.
There are several other ways you can achieve what you want in Structured Text:
- Since your property is public there is no reason not to declare the array of IObserver as an input field of the Function Block.
If you do so you can access it the way you desire.
Declaration part:
FUNCTION_BLOCK CommandHandler
VAR_INPUT
IObservers : ARRAY[0..19] OF IObserver;
END_VAR
Example call:
fbCommandHandler.IObservers[i].update();
- Another way is you access (and modifiy, etc..) your IObservers from inside the update method:
Create a new Interface IObserverArray with an update method:
METHOD update : BOOL
VAR_INPUT
index : INT;
cmd : INT;
END_VAR
Create a new Function Block implementing the IObserverArray itf:
FUNCTION_BLOCK ObserverArray IMPLEMENTS IObserverArray
//declaration part of the update method
METHOD update : BOOL
VAR_INPUT
index : INT;
cmd : INT;
END_VAR
VAR
itfObservers : ARRAY [0..19] OF IObserver;
END_VAR
//imlementation part of the update method
itfObservers[index].update(cmd);
Create a method getObservers() in your CommandHandler Function Block that returns a IObserverArray:
METHOD getObservers : IObserverArray
//imlementation part of the getObservers method
getObservers := aObservers;
Now you just declare aObservers : ObserverArray;
in your CommandHandler as a VAR
and call it like this : fbCommandHandler.getObservers().update(5,12);