SRL Archive - General Botting Help

Procedure as a parameter, how?


schmoniquell

2014-10-01 13:29:17

Hi. I'm trying to make a procedure that calls another procedure, just like how AddOnTerminate(const proc:string) calls whatever you give it. How do I do that? Of what data type is a procedure?

Example:

program new;

procedure proc2;
begin
[INDENT]writeln('it works');[/INDENT]
end;

procedure proc1([COLOR="#FF0000"]nameofproc:procedure[/COLOR]);
begin
[INDENT]nameofproc; [/INDENT]
end;



begin
[INDENT]proc1('proc2');[/INDENT]
end;

What would I put instead of the red text?

Edit: I guess another way of asking this question is: Is there a way to run a procedure whose name you have stored in a string variable? For example,

program new;

var procname:string:='testprocedure';

procedure testprocedure;
begin
[INDENT]writeln('it works');[/INDENT]
end;



begin
[INDENT]CallProcedure(procname);[/INDENT]
end;

(CallProc and CallProcedure don't work)

———
Thanks so much for the answer Turpinator!!

Turpinator

2014-10-01 13:36:59

program new;

procedure foo(proc: procedure);
begin
proc;
end;

procedure bar();
begin
writeln('bar procedure');
end;

begin
foo(@bar);
end.

its a procedure. just as @Olly; said yesterday in IRC.
the part you were missing probably was when you called it, you need the address of it.

schmoniquell

2014-10-01 13:47:00

OHHH so you need to just put the @ infront of, yeah? Thank you SO much!

schmoniquell

2014-10-01 15:41:10

Hey, can I shamelessly ask one more detail? How would I go about sending some parameters to bar? Like this:

program new;

procedure foo(proc: procedure);
begin
proc;
end;

procedure bar(s:string);
begin
writeln(s);
end;

begin
foo(@bar('asd'));
end.

This gives me an error, saying "Exception in Script: Operator "Addr" not compatible with types at line 14, column 6 at line 14, column 6"