Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Delphi
  4. declaring math function

declaring math function

Scheduled Pinned Locked Moved Delphi
question
3 Posts 3 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saeed_Ansari
    wrote on last edited by
    #1

    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.

    S S 2 Replies Last reply
    0
    • S Saeed_Ansari

      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.

      S Offline
      S Offline
      smags13
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • S Saeed_Ansari

        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.

        S Offline
        S Offline
        Stuart Cox from Victoria
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups