- marked as minor
- edited description
[JSCodeGen] Cannot send a reference of function/procedure as a parameter in another function/procedure
Issue #188
resolved
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)
-
reporter -
reporter - edited description
-
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;
-
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;
-
repo owner - changed status to resolved
Fixed
#188JS Codegen Variants are now assignment-compatible with all function types + test→ <<cset 106bd869634a>>
- Log in to comment