i made a generic method which should be able to contain integers or strings, however i don't no the type until runtime therefore i declared the method param as any and now it does not accept my string
string is assigned to any
error: incompatible types of argument expected any, passes string
Steps to reproduce error
Solved! Go to Solution.
your method does not work, because when you create an array, you did not say that it must have any-format. For example, with func (makeArray (1)) you get an error: "... pass integer ".
If you create an array without declaring the format, Plant Simulation self selects a format that uses the minimum resource. For "A" it is a string . For 1 it is integer. For 1.1 it is real. and so on ...
For example makeArray(1,"A") create a any-format.
var a : any := makeArray("A") print func(a) a:= makeArray(1) print func(a)
Picture shows another solution
This behavior is actually not intended. If assigning an array to a local variable works, then passing that array to a parameter should also work. We will change that in version 14.2.
Thank you nadin1223 for providing a workaround.