[Pas2js] CreateObject

warleyalex warleyalex at yahoo.com.br
Wed Aug 14 21:48:37 CEST 2019


Hey, I'd like to create an instance of this class/interface definition:
-----------------------------------------------------------------------------
TGoogleMapOptions = class external name 'google.maps.MapOptions'
  private
    fcenter: TGoogleLatLng; external name 'center';
    fmapTypeId: String; external name 'mapTypeId';
    fzoom: Integer; external name 'zoom';
  public
     property center: TGoogleLatLng read fcenter write fcenter;
     property mapTypeId: String read fmapTypeId write fmapTypeId;
     property zoom: Integer read fzoom write fzoom;
  end;   
-----------------------------------------------------------------------------

You can't create an instance of this interface, just because it's not
available through. Alright.
Yes, there's an workaround:
==============================
var  
  CreateObject: TJSObject; external name '{}';

var
  mapOptions: TGoogleMapOptions; 

begin	
  mapOptions := TGoogleMapOptions(CreateObject);
  mapOptions.zoom:= 16;
  mapOptions.center := TGoogleLatLng.New(-19.4574, -44.2417);
  mapOptions.mapTypeId := TGoogleMapTypeID.ROADMAP;
	
pas2js will generate this:

	var mapOptions = null;
	mapOptions = {};
	mapOptions.zoom = 16;
	mapOptions.center = new google.maps.LatLng(-19.4574,-44.2417,false);
	mapOptions.mapTypeId = google.maps.MapTypeId.ROADMAP;

I think the external CreateObject variable should live in the JS unit!




--
Sent from: http://pas2js.38893.n8.nabble.com/


More information about the Pas2js mailing list