[JSCodeGen] Cannot send a reference of function/procedure as a parameter in another function/procedure

Issue #188 resolved
Toky Olivier Razanakotonarivo created an issue

If I have those declarations:

type
  TMyProc = procedure(param: Variant);

  procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
  procedure Proc2 (OneParam: Integer; FuncCallback: TMyProc);

The compiler return an error if I try do call Proc2 inside Proc1 like this:

Procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
begin
  Proc2 (OneParam, FuncCallback); //The compiler says: There is no overloaded procedure of Proc2 that can be called with those parameters
end;

The workaround now is doing like this or with lambda:

Procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
begin
  Proc2 (OneParam, procedure (param: Variant)
  begin
    FuncCallback(param);
  end); 
end;

May be declaring FuncCallback as Variant not TMyProc may work too but I didn’t tested yet.

Thank you.

Comments (5)

  1. Eric Grange repo owner

    I could not reproduce it with the following snippet, any more context where you’re seeing the issue ?

    unit Test;
    
    interface
    
    type
      TMyProc = procedure(param: Variant);
    
    procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
    procedure Proc2 (OneParam: Integer; FuncCallback: TMyProc);
    
    implementation
    
    Procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
    begin
      Proc2 (OneParam, FuncCallback); //The compiler says: There is no overloaded procedure of Proc2 that can be called with those parameters
    end;
    
    procedure Proc2 (OneParam: Integer; FuncCallback: TMyProc);
    begin
    end;
    

  2. Toky Olivier Razanakotonarivo reporter

    Are you using it with JSCodeGen too? With JSCOdeGen, I cannot compile it.

    As I said i shoud do like this

    Procedure Proc1 (OneParam: Integer; FuncCallback: TMyProc);
    begin
      Proc2 (OneParam, procedure (param: Variant)
      begin
        FuncCallback(param);
      end); 
    end;
    

  3. Log in to comment