I created an empty function block called MyObject, then declared an array of instances of the function block, as such:
MyArray:ARRAY[1..2]OFMyObject;
So far, so good. Now I add an FB_Init method to MyObject:
METHODFB_Init : BoolVAR_INPUT
 bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
 bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
 ID : UINT;END_VAR
The question is, how do I now declare an array of MyObject? My original declaration doesn't work any more because the objects can't be created without the 'ID' parameter. But I can't figure out any way to pass it in. I was hoping something along the lines of this would work:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2014-05-15
Originally created by: scott_cunningham
I have found adding VAR_INPUTS to Fb_init() to be a little troubling - intellisense doesn't show the VAR_INPUTS, so there are no hints to the user. Also, an unfriendly error "No matching FB_init method found for instantiation...". So, I normally just create my own "init" method that I call during first boot and initialize necessary items. A bit of a workaround, but also very clear what is happening to other programmers:
FUNCTION_BLOCKMyObjectMETHODMyInitVAR_INPUT
  ID: UINT;END_VAR
...
END_METHODPROGRAMPLC_PRGVAR
  MyArray: ARRAY[1..2] OFMyObject;
  FirstBoot: BOOL:=TRUE;END_VARIFFirstBootTHEN
  MyArray[1].MyInit(ID:=24);
  MyArray[2].MyInit(ID:=17);
  ...
  FirstBoot:=FALSE;END_IF
...
END_PROGRAM
I created an empty function block called MyObject, then declared an array of instances of the function block, as such:
So far, so good. Now I add an FB_Init method to MyObject:
The question is, how do I now declare an array of MyObject? My original declaration doesn't work any more because the objects can't be created without the 'ID' parameter. But I can't figure out any way to pass it in. I was hoping something along the lines of this would work:
but that doesn't compile.
Any suggestions on how to do this?
Originally created by: scott_cunningham
I have found adding VAR_INPUTS to Fb_init() to be a little troubling - intellisense doesn't show the VAR_INPUTS, so there are no hints to the user. Also, an unfriendly error "No matching FB_init method found for instantiation...". So, I normally just create my own "init" method that I call during first boot and initialize necessary items. A bit of a workaround, but also very clear what is happening to other programmers:
Related
Talk.ru: 1
Talk.ru: 2
get rid of this:
FB_init is a method/funciton and needs to be called! not assigned...
Do it like the following:
Then intellisense works at least at the first line though
Last edit: aikapan 2020-08-21