Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread interfacing with JavaScript
Fri, Jul 8 2016 7:03 PMPermanent Link

erickengelke

Avatar


Hi,  I am calling a JavaScript library.  IJavaScript looks like this:

hello.init({
       google: '5770808.apps.googleusercontent.com'
}, {
 redirect_uri: 'https://dark.uwaterloo.ca/oauth2/redirect.html',
 scope: 'basic'});

Which I tried translating to:

 External TGlobHelloArgs =  class
 public
    property google : string read write;
 end;

 external TGlobHelloRedirect  = class
 public
   property redirect_uri : string read write ;
   property scope : string read write;
 end;

external THello emit hello = class
 public
 property services : array of variant read write;
 procedure init( args : TGlobHelloArgs  ; arg2 : TGlobHelloRedirect );
 procedure on( arg : string ; fn : TOnFn );
 function api( what : string ):TApi;
end;

And this works, but only if I include a small JavaScript file that says:

var myargs = {};
var myargs2 = {};

Obviously I'd like to declare the variables in EWB Objective Pascall.
- - - -
If I tried the alternative and create THelloArg
 THelloArgs =  class
 public
    google : string ;
 end;

 THelloRedirect  = class
 public
   redirect_uri : string;
   scope : string ;
end;

Then call Init() with these two parameters,  it keeps getting stack overflows when they try to add properties, as the THelloArg is fixed in size.

Is there a way to declare a variable of {} in EWB?  I tried Variants and casting  but didn't have any luck

Thanks
Sat, Jul 9 2016 3:50 PMPermanent Link

erickengelke

Avatar

erickengelke wrote:

> Obviously I'd like to declare the variables in EWB Objective Pascall.
>Is there a way to declare a variable of {} in EWB?  I tried Variants and casting  but didn't have any luck

I solved it by declaring
external function eval( s : string): TGlobHelloRedirect;

var
 HelloRedirect : TGlobHelloRedirect;
begin
 HelloRedirect = eval( 'new Object();')
...
end;

And it works. I don't know if you have a preferred solution that's better than this.

Thanks
Erick
Sat, Jul 9 2016 4:39 PMPermanent Link

erickengelke

Avatar

erickengelke wrote:

erickengelke wrote:

>I solved it by declaring
>external function eval( s : string): TGlobHelloRedirect;

Small problem, external function eval( s : string) does not support overloading.  Only the first registered type is supported (In 2.05 beta)

so I declaree eval(s: string) of type object and cast it to the appropriate type.

Done.
Mon, Jul 11 2016 8:41 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< Is there a way to declare a variable of {} in EWB?  I tried Variants and casting  but didn't have any luck >>

There is, but it's undocumented:

function CreateObject(const ObjectLiteral: String): TObject;

Just cast the result to the desired class type, and you'll be all set.

Tim Young
Elevate Software
www.elevatesoft.com
Image