declaring math function
-
hi as you know, to declare a custom math function, we can do:
function myfun(x:real):real;
begin
myfun=x*sin(x)+1;
end;and it works perfectly. BUT if we want user declare his function during running app, how can we do it?? Thanks.
-
hi as you know, to declare a custom math function, we can do:
function myfun(x:real):real;
begin
myfun=x*sin(x)+1;
end;and it works perfectly. BUT if we want user declare his function during running app, how can we do it?? Thanks.
If you want end users (like software users) to define the function body while using your software, the first thing coming into my mind is some scripting tool. If you want your clients (if you define some library package) to define the function body, you could use function pointer. Can you describe more about your project or your thought?
-
hi as you know, to declare a custom math function, we can do:
function myfun(x:real):real;
begin
myfun=x*sin(x)+1;
end;and it works perfectly. BUT if we want user declare his function during running app, how can we do it?? Thanks.
Once upon a time the Timex Sinclair computer used an interpreted BASIC that would allow its user to type in a math function as a string and then have the string evaluated to give the answer to the function. Quite cool. The BASIC in the Commodore 64 lacked that feature. Compiled languages, like Delphi's implementation of Object Pascal, quite often don't provide the ability to evaluate the values of strings as expressions nor give one a built in way to define functions/procedures at run time right out of the box. But, libraries like this one: http://tpsystools.sourceforge.net will give you the ability to key in a function and evaluate it. You'll want to use the TStExpression component and/or the TStExpressionEdit component. These are found on pages 316 and 327, respectively, in the SysTools.PDF manual, available with the library from SourceForge. There's a TON of other useful things in SysTools too. Thanks TurboPower!