Is it possible to change a data type at runtime? I would like to set up a recipe management dynamically.
Hi Markus
It is not possible to dynamically change a datatype at runtime. This is because the compiler allocates memory based on the configured variables and datatypes at compile time. The only way to do something like this would be if you were to dynamically allocate memory at runtime using C or C++, but this is creating variables rather than modifying them.
The easiest thing to do in your case would be to create standard recipe structure that can be used across different configurations. You could also create larger variables than you need (i.e. DINTs when you may only need 8 bytes) and then only fill some of the memory allocated if you don’t need all of it. This means you also have to keep track of how much of each variable should be used in each case, but it allows you to create generic memory buckets.
If you have some more details you’re willing to share perhaps we can help you think of a better solution.
If you’re using mapp Recipe, you can also change which variables are stored in the recipe at runtime. This can be done using Categories, or by modifying the MpRecipeRegPar function blocks. However, this may cause your recipe files to get cluttered with unused data.
Hi @c577716 Markus,
It looks like you got a good recommendation from Marcus, and it has been a couple of weeks since the last activity on this post. If the answers helped you with your question, can you help the next person with the same question by marking the solution on the information which helped you the most. If you still have open questions on this topic, can you provide an update?