This is what I would like to have (this is a constructor for FB object):
METHOD FB_init : BOOL
VAR_INPUT
bInitRetains : BOOL;
bInCopyCode : BOOL;
//My variables:
typeOfVariable : TYPE; // This obviously doesn't work
END_VAR
size := 1;
myArray := __NEW(typeOfVariable, size); // Create dynamic array with 'typeOfVariable' variables.
END_METHOD
- In this method I would pass to the parameter
typeOfVariable
for exampleREAL
and the method would create array ofREAL
variables with size1
. - I need to know what
type
I declaretypeOfVariable
so it can store the data abouttype
of another variable.
Working example is the
__NEW()
method for dynamically creating array.This method takes in a argument such as
REAL
orINT
.
This is the code for it:
myArray := __NEW(REAL, 10); //Create array with type REAL variables with the size of 10
OK, here a small example how you could tackle this problem:
Create an Enum first:
Use it in a switch case:
Check for Null-Pointer and remember to __Delete when you don't need the array anymore.