[Pas2js] call from external js files

pas2js at gauns.org pas2js at gauns.org
Tue Jun 18 07:49:39 CEST 2019


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









>> 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  -  Pas2js at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/pas2js


More information about the Pas2js mailing list