Results 1 to 8 of 8

Thread: Calling a procedure/function...

  1. #1

    Calling a procedure/function...

    A simple and short question that deserves an equally short answer:

    Is a procedure that can call a procedure/function?

    E.g.
    Code:
    procedure TheProc;
    begin
    end;
    
    var
      p: string;
    begin
      p := 'TheProc';
      magic_proc(p);
    end.
    I looked through the helpfile, although it's hard to find a command if you don't know what it's called. :/

    Thanks!
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  2. #2

    Calling a procedure/function...

    You can declare a variable procedure, asign some other procedure to it and call it normally, like:
    var
    [pascal]var
    VariableProcedure: procedure;
    VariableProcedure:=@Procedure1;
    VariableProcedure;[/pascal]

  3. #3

    Calling a procedure/function...

    Hm. Is there a way to do that by supplying a string as the proc name?

    Here's what I was thinking, but (of course) it doesn't work:

    [pascal]
    procedure TForm1.Thing;
    begin
    Button1.Caption := 'Thing proc called.';
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
    p: procedure;
    a: string;
    begin
    a := 'Thing';
    p := @a;

    p;
    end;
    [/pascal]
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  4. #4

    Calling a procedure/function...

    I don't think so. Why not use arrays of corresponding strings and function addresses, and get by by changing array's index value.

  5. #5

    Calling a procedure/function...

    Quote Originally Posted by Paulius
    I don't think so. Why not use arrays of corresponding strings and function addresses, and get by by changing array's index value.
    Because that would defeat the purpose of being able to call it by only needing a string. With that method that you described, I'd have to know all of the names of the procedures I want to call, and store them. That's what I'm trying to avoid. :)
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  6. #6

    Calling a procedure/function...

    Actually you'd still need stored string anyway, because no procedure names are compiled into the code and searching through strings woul'd be much slower.

  7. #7

    Calling a procedure/function...

    Quote Originally Posted by Paulius
    Actually you'd still need stored string anyway, because no procedure names are compiled into the code and searching through strings woul'd be much slower.
    I don't know what I'm going to do, then. :/

    In my case, it wouldn't be efficient at all to have to name every procedure/function in the code itself. Any ideas?
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  8. #8

    Calling a procedure/function...

    If you look at this topic: http://terraqueous.f2o.org/dgdev/viewtopic.php?t=1178 Alimonster showed a way to do more or less what you want.

    Also if your procedures/functions are in a dll you could call @myproc := GetProcAddress(PChar(myprocname));
    Signature:
    <br />This is a block of text that can be added to posts you make. There is a 255 character limit

Bookmarks

Posting Permissions

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