A typical example of this are motor characteristics. These do not follow a single mathematical formula, but must be based on corresponding diagrams in the data sheets.
The functions are created according to the following principle:
- Define a new "function envelope" in the initialization part
- Add value pairs one after the other in the initialization part of the function
- Use function anywhere
In concrete terms, these steps are carried out as follows:
First, a global integer variable must be defined, which is used to identify the function:
Test function: integer;
With the function LinFuncNew you can now create a new function in the initialization part:
Testfunction := LinFuncNew;
You can now pass the necessary value pairs to this function by calling LinFuncAddPair(id, x, y) several times. The order is important! X must always be increasing!
After all, you can use the function with LinFuncGetValue(id, x) at any point (after the definition, of course):
Result := LinFuncGetValue(Testfunction, 4); // Result = 5.5