Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Linking a procedure to an object for remote execution

  1. #11

    Linking a procedure to an object for remote execution

    [pascal]objname:=TLabel.Create(self);
    objname.SetOnClick:=Procedurename;[/pascal]
    Yes this works, why would it not? All events in delphi are based on this.

    Edit: I mean works for procedures, don't know about external ones. Delphi allows pointers to procedures too though.

  2. #12

    Linking a procedure to an object for remote execution

    Quote Originally Posted by User137
    [pascal]objname:=TLabel.Create(self);
    objname.SetOnClick:=Procedurename;[/pascal]
    Yes this works, why would it not? All events in delphi are based on this.

    Edit: I mean works for procedures, don't know about external ones. Delphi allows pointers to procedures too though.
    realy?
    never tryed this...

  3. #13

    Linking a procedure to an object for remote execution

    [pascal]objname:=TLabel.Create(self);
    objname.SetOnClick:=@Procedurename;
    [/pascal]

    and thanks IK for the help
    http://ik.homelinux.org

  4. #14
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linking a procedure to an object for remote execution

    I want to mimic the functionality of JEDI-SDL's sdl_mixer function Mix_HookMusicFinished where all I do is supply the memory address of the regular procedure or function I want to run and have my GUI objects run them as they see fit.

    What I have in the end is

    1) the gui unit already written for the user and all it does is runs the assigned procedure/function to the onevent-like hook.

    2) the user's game code that needs to be written and just needs to run a function or simple assign of his/her written procedure's address to link it to the gui system.


    This is more about me being able to run a procedure from it's memory address than it is about using the DOM which I want to avoid as much as I can for size issues. This isn't for any kind of Windows App.

    This must be an available syntax for FPC please keep in mind as I'm using Lazarus.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  5. #15
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linking a procedure to an object for remote execution

    Quote Originally Posted by Brainer
    Quote Originally Posted by WILL
    Hmm... well what is FIdleFunc though?
    Let's assume you have a procedure inside your DLL, that does certain things with the variable FIdleFunc.

    A little example
    [pascal]
    // -- GLOBAL --
    type
    TMyMathEvent = procedure(Z: Single);

    // -- DLL --
    var
    FMathFunc: TMyEvent;


    procedure DLLDoIt;
    var
    x: Single;
    begin
    x := 3.14;

    if Assigned(FMathFunc) then
    FMathFunc(X);
    end;

    procedure AssignMathFunc(TheMathFunc: TMyMathEvent);
    begin
    FMathFunc := TheMathFunc;
    end;

    // -- EXTERNAL APP --
    procedure AssignMathFunc(TheMathFunc: TMyMathEvent); external 'MathDLL.dll';

    const
    Radius = 3.225;

    var
    TheArea: Single;

    procedure CalculateCircleArea(Z: Single);
    begin
    TheArea := Z * (Radius * Radius);
    end;

    begin
    AssignMathFunc(CalculateCircleArea);
    end;
    [/pascal]
    ok I'm still a little sure about all this FIdleFunc and FMathFunc stuff... are these just system variables? What do they derive from and are they documented anywhere? And do they automatically run whatever function was assigned to them?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #16

    Linking a procedure to an object for remote execution

    As far as I have seen, Mix_HookMusicFinished is used in this way;
    Code:
    Mix_HookMusicFinished(YourProc)
    well, at least something like that :lol:

    The example made by JSoftware works fine with free pascal too if you do
    [pascal]SomethingLength(@YourProc);[/pascal]
    Get your fpc4gba copy now!
    Get your fpc4nds copy now!

  7. #17
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linking a procedure to an object for remote execution

    Ok using JSoftware's example... expanding on it a little... could I do this?

    [pascal]
    type
    TProcedure = procedure; //Already declared in system

    var
    Bob: TProcedure;

    procedure RunProc(callBack: TProcedure);
    begin
    ...
    Callback; //Calls callback
    ...
    end;

    procedure StoreProc(proc: TProcedure; var StoredProc: TProcedure);
    begin
    ...
    StoredProc := proc;
    ...
    end;

    procedure MyOwn;
    begin
    ...
    end;

    begin
    StoreProc(MyOwn, Bob);
    RunProc(Bob);
    end.[/pascal]

    I'll try an experiment to see if this goes... seems like it might...
    Jason McMillen
    Pascal Game Development
    Co-Founder





  8. #18

    Linking a procedure to an object for remote execution

    You can't do that in Freepascal. It works fine in Delphi but Freepascal will complain that procedures don't return anything. You have to get the address of the procedure:

    StoreProc(@MyOwn, Bob);
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  9. #19
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linking a procedure to an object for remote execution

    so if I pass the addresses in it'll work fine then you think?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  10. #20
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Linking a procedure to an object for remote execution

    Ok follow-up question...

    What if I tried to run the store procedure but there was not one assigned? I'd need a flag to keep track of if one was stored or not, right?
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 2 of 3 FirstFirst 123 LastLast

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
  •