Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2019-06

call from external js files

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

hi guys,

one last question concerning the external declarations

i have this js file
var logger = {
name: "k1",
getName: function() {

     return "k1 logger";
   },
   log: function(msg) {
     console.log(msg);
   }

}

and in my pascal file i use it this way
type
   TExternal = class
   public
     name : String;
     function getName : String; external name 'getName';
     procedure log( aMessage : String );  external name 'log';
   end;
var
   ext : TExternal; external name 'logger';

the variable name i can use without the external declaration because in the js file its called also name,
but with the function it doesn't work without the external declaration although the name of the function is the same
Error: Forward procedure not resolved "log"

would it be possible to write the class like this
type
   TExternal = class
   public
     name : String;
     function getName : String;
     procedure log( aMessage : String );
   end;
var
   logger : TExternal; external name 'logger';

if the external name is the same?

forget it if its to much work to change because its only esthetic

thanks
peter

Show quoted text 27 lines
> You can already do this > > TExternal = class external name 'Something' > public > name : String; > function getName : String; > end; > > var > logger : TExternal; external name 'logger'; > > So you can do > > logger.getname; yeaaah :) thats what i am looking for for so many hours or even days :) thanks michael, now it looks much nicer, and it was so easy, shame on me :) thanks peter _______________________________________________ Pas2js maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js

Reply by email

Michael Van Canneyt
to Unknown author
Show quoted text 51 lines
hi guys, one last question concerning the external declarations i have this js file var logger = { name: "k1", getName: function() { return "k1 logger"; }, log: function(msg) { console.log(msg); } } and in my pascal file i use it this way type TExternal = class public name : String; function getName : String; external name 'getName'; procedure log( aMessage : String ); external name 'log'; end; var ext : TExternal; external name 'logger'; the variable name i can use without the external declaration because in the js file its called also name, but with the function it doesn't work without the external declaration although the name of the function is the same Error: Forward procedure not resolved "log" would it be possible to write the class like this type TExternal = class public name : String; function getName : String; procedure log( aMessage : String ); end; var logger : TExternal; external name 'logger'; if the external name is the same? forget it if its to much work to change because its only esthetic

You can use (as I proposed originally) an external class definition: (see the external name just after the class keyword)

TExternal = class external name 'anonymous'
    public
      name : String;
      function getName : String;
      procedure log( aMessage : String );
    end;
var
   logger : TExternal; external name 'logger';

Michael.

Reply by email

Unknown author
to Michael Van Canneyt
You can use (as I proposed originally) an external class definition: (see the external name just after the class keyword)

oh sorry, i missed that

Show quoted text 11 lines
TExternal = class external name 'anonymous' public name : String; function getName : String; procedure log( aMessage : String ); end; var logger : TExternal; external name 'logger';

would by nice to have it this way, if its possible, but to have the external declaration two times (class and variable) is also ok, just a wish

type
   TExternal = class external name 'logger'
   public
     name : String;
     function getName : String;
     procedure log( aMessage : String );
   end;
var
   ext : TExternal;

thanks michael

cheers
peter

Show quoted text 5 lines
Michael. _______________________________________________ Pas2js maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js

Reply by email

Michael Van Canneyt
to Unknown author
Show quoted text 32 lines
> You can use (as I proposed originally) an external class definition: > (see the external name just after the class keyword) oh sorry, i missed that > > TExternal = class external name 'anonymous' > public > name : String; > function getName : String; > procedure log( aMessage : String ); > end; > > > var > logger : TExternal; external name 'logger'; would by nice to have it this way, if its possible, but to have the external declaration two times (class and variable) is also ok, just a wish type TExternal = class external name 'logger' public name : String; function getName : String; procedure log( aMessage : String ); end; var ext : TExternal;

This will never be possible.

You can declare & instantiate a local instance of an external class, that is what your code does.

The "external" after the ext : texternal is necessary to make clear that the variable already exists externally.

Michael.

Reply by email

Unknown author
to Michael Van Canneyt
Michael Van Canneyt wrote 44 lines
On Tue, 18 Jun 2019, wrote: > >> You can use (as I proposed originally) an external class definition: >> (see the external name just after the class keyword) > > oh sorry, i missed that > >> >> TExternal = class external name 'anonymous' >> public >> name : String; >> function getName : String; >> procedure log( aMessage : String ); >> end; >> >> >> var >> logger : TExternal; external name 'logger'; > > would by nice to have it this way, if its possible, > but to have the external declaration two times (class and variable) is > also ok, just a wish > > type > TExternal = class external name 'logger' > public > name : String; > function getName : String; > procedure log( aMessage : String ); > end; > > var > ext : TExternal; This will never be possible. You can declare & instantiate a local instance of an external class, that is what your code does. The "external" after the ext : texternal is necessary to make clear that the variable already exists externally.

thanks michael,
it was just an idea, obviously not an intelligent one :)

cheers
peter

Reply by email