Page 1 of 1

Call SB Procedure with JavaScript

Posted: Fri Nov 04, 2016 10:40 am
by falsam
This example (from help) works fine.

Code: Select all

Procedure MyProcedure()
  Debug "Hello world"
EndProcedure

; Call in SpiderBasic
MyProcedure() 

; Call using Javascript
!f_myprocedure();
but not this code

Code: Select all

Procedure MyProcedure()
  Debug "Hello world"
EndProcedure

; Call using Javascript
!f_myprocedure();
Thanks for your help.

Re: Call SB Procedure with JavaScript

Posted: Fri Nov 04, 2016 10:40 am
by Fred
You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.

Re: Call SB Procedure with JavaScript

Posted: Fri Nov 04, 2016 10:48 am
by falsam
Fred wrote:You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.
Like the first code ? For me this is a non sense.

Code: Select all

Global dummy

Procedure MyProcedure()
  dummy + 1
EndProcedure

; Call in SpiderBasic
MyProcedure() 

; Call using Javascript
!f_myprocedure();
!alert(v_dummy)

Re: Call SB Procedure with JavaScript

Posted: Fri Nov 04, 2016 10:48 am
by Peter
Fred wrote:You need to reference your procedure in SB code at least once or it will get removed by the code optimizer.
in this case:

Code: Select all

If 1=2
 MyProcedure()
EndIf
i think it's more elegant when Declare do the Job:

Code: Select all

Declare MyProcedure()
Greetings ... Peter

Re: Call SB Procedure with JavaScript

Posted: Tue Oct 10, 2017 8:23 am
by mdp
Peter wrote:i think it's more elegant when Declare do the Job:
Declare MyProcedure()
Absolutely, it's ok to have the optimizer working but we need a good solution to force the compilation of a procedure meant to be called with "inline JS".