Results 1 to 7 of 7

Thread: Function as parameter?

  1. #1
    Join Date
    Mar 2011
    Posts
    84
    Mentioned
    0 Post(s)
    Quoted
    2 Post(s)

    Default Function as parameter?

    In C you can use a pointer to a function as a parameter in another function like so:

    Code:
    void MyFunction( void (*ParameterFunction)(ParameterFunctionsParameters) ) {
    }
    Is this possible in pascal?

  2. #2
    Join Date
    Jan 2011
    Location
    Denver, CO
    Posts
    1,351
    Mentioned
    2 Post(s)
    Quoted
    72 Post(s)

    Default

    I'm pretty sure you can do it in pascal considering you can do it in Simba scripts. Here is a commonly used example:

    Simba Code:
    MMouse(x, y, RandomRange(-2, 2), RandomRange(-2, 2));

    So it will use the return value of the RandomRange function for the pixel randomness of x and y. You just have to make sure that the function you are using as the parameter returns the data type needed.

  3. #3
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    function TestFunc : string;
    begin
      result := 'test';
    end;

    procedure Test(Func : function : string);
    begin
      Writeln(Func());
    end;

    begin
      Test(@TestFunc);
    end.
    or
    Simba Code:
    function TestFunc : string;
    begin
      result := 'test';
    end;

    procedure Test(Func : string; Params : TVariantArray);
    begin
      writeln(CallProc('TestFunc', Params));
    end;

    begin
      Test('TestFunc', []);
    end.
    Last edited by Sex; 04-22-2011 at 06:04 PM.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  4. #4
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    If you would like to pass parameters!

    Simba Code:
    type
      TExFunc = function(s: string): boolean;

    function test(test2: TExFunc): boolean;

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Dgby714 View Post
    If you would like to pass parameters!

    Simba Code:
    type
    TExFunc = function(s: string): boolean;

    function test(test2: TExFunc): boolean;
    Or you can use CallProc .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Jan 2008
    Location
    10° north of Hell
    Posts
    2,035
    Mentioned
    65 Post(s)
    Quoted
    164 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    Or you can use CallProc .
    Yes but using CallProc requires you to make wrappers for Simba's functions.

    Dg's Small Procedures | IRC Quotes
    Thank Wishlah for my nice new avatar!
    Quote Originally Posted by IRC
    [22:12:05] <Dgby714> Im agnostic
    [22:12:36] <Blumblebee> :O ...you can read minds

  7. #7
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Yeah, was gonna just edit that in...but I still think it is nifty .
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •