webgl2.js 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284
  1. var pas = {};
  2. var rtl = {
  3. quiet: false,
  4. debug_load_units: false,
  5. debug_rtti: false,
  6. debug: function(){
  7. if (rtl.quiet || !console || !console.log) return;
  8. console.log(arguments);
  9. },
  10. error: function(s){
  11. rtl.debug('Error: ',s);
  12. throw s;
  13. },
  14. warn: function(s){
  15. rtl.debug('Warn: ',s);
  16. },
  17. hasString: function(s){
  18. return rtl.isString(s) && (s.length>0);
  19. },
  20. isArray: function(a) {
  21. return Array.isArray(a);
  22. },
  23. isFunction: function(f){
  24. return typeof(f)==="function";
  25. },
  26. isModule: function(m){
  27. return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name]===m);
  28. },
  29. isImplementation: function(m){
  30. return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl===m);
  31. },
  32. isNumber: function(n){
  33. return typeof(n)==="number";
  34. },
  35. isObject: function(o){
  36. var s=typeof(o);
  37. return (typeof(o)==="object") && (o!=null);
  38. },
  39. isString: function(s){
  40. return typeof(s)==="string";
  41. },
  42. getNumber: function(n){
  43. return typeof(n)==="number"?n:NaN;
  44. },
  45. getChar: function(c){
  46. return ((typeof(c)==="string") && (c.length===1)) ? c : "";
  47. },
  48. getObject: function(o){
  49. return ((typeof(o)==="object") || (typeof(o)==='function')) ? o : null;
  50. },
  51. isPasClass: function(type){
  52. return (rtl.isObject(type) && type.hasOwnProperty('$classname') && rtl.isObject(type.$module));
  53. },
  54. isPasClassInstance: function(type){
  55. return (rtl.isObject(type) && rtl.isPasClass(type.$class));
  56. },
  57. hexStr: function(n,digits){
  58. return ("000000000000000"+n.toString(16).toUpperCase()).slice(-digits);
  59. },
  60. m_loading: 0,
  61. m_loading_intf: 1,
  62. m_intf_loaded: 2,
  63. m_loading_impl: 3, // loading all used unit
  64. m_initializing: 4, // running initialization
  65. m_initialized: 5,
  66. module: function(module_name, intfuseslist, intfcode, impluseslist, implcode){
  67. if (rtl.debug_load_units) rtl.debug('rtl.module name="'+module_name+'" intfuses='+intfuseslist+' impluses='+impluseslist+' hasimplcode='+rtl.isFunction(implcode));
  68. if (!rtl.hasString(module_name)) rtl.error('invalid module name "'+module_name+'"');
  69. if (!rtl.isArray(intfuseslist)) rtl.error('invalid interface useslist of "'+module_name+'"');
  70. if (!rtl.isFunction(intfcode)) rtl.error('invalid interface code of "'+module_name+'"');
  71. if (!(impluseslist==undefined) && !rtl.isArray(impluseslist)) rtl.error('invalid implementation useslist of "'+module_name+'"');
  72. if (!(implcode==undefined) && !rtl.isFunction(implcode)) rtl.error('invalid implementation code of "'+module_name+'"');
  73. if (pas[module_name])
  74. rtl.error('module "'+module_name+'" is already registered');
  75. var module = pas[module_name] = {
  76. $name: module_name,
  77. $intfuseslist: intfuseslist,
  78. $impluseslist: impluseslist,
  79. $state: rtl.m_loading,
  80. $intfcode: intfcode,
  81. $implcode: implcode,
  82. $impl: null,
  83. $rtti: Object.create(rtl.tSectionRTTI)
  84. };
  85. module.$rtti.$module = module;
  86. if (implcode) module.$impl = {
  87. $module: module,
  88. $rtti: module.$rtti
  89. };
  90. },
  91. exitcode: 0,
  92. run: function(module_name){
  93. function doRun(){
  94. if (!rtl.hasString(module_name)) module_name='program';
  95. if (rtl.debug_load_units) rtl.debug('rtl.run module="'+module_name+'"');
  96. rtl.initRTTI();
  97. var module = pas[module_name];
  98. if (!module) rtl.error('rtl.run module "'+module_name+'" missing');
  99. rtl.loadintf(module);
  100. rtl.loadimpl(module);
  101. if (module_name=='program'){
  102. if (rtl.debug_load_units) rtl.debug('running $main');
  103. var r = pas.program.$main();
  104. if (rtl.isNumber(r)) rtl.exitcode = r;
  105. }
  106. }
  107. if (rtl.showUncaughtExceptions) {
  108. try{
  109. doRun();
  110. } catch(re) {
  111. var errMsg = re.hasOwnProperty('$class') ? re.$class.$classname : '';
  112. errMsg += ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
  113. alert('Uncaught Exception : '+errMsg);
  114. rtl.exitCode = 216;
  115. }
  116. } else {
  117. doRun();
  118. }
  119. return rtl.exitcode;
  120. },
  121. loadintf: function(module){
  122. if (module.$state>rtl.m_loading_intf) return; // already finished
  123. if (rtl.debug_load_units) rtl.debug('loadintf: "'+module.$name+'"');
  124. if (module.$state===rtl.m_loading_intf)
  125. rtl.error('unit cycle detected "'+module.$name+'"');
  126. module.$state=rtl.m_loading_intf;
  127. // load interfaces of interface useslist
  128. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadintf);
  129. // run interface
  130. if (rtl.debug_load_units) rtl.debug('loadintf: run intf of "'+module.$name+'"');
  131. module.$intfcode(module.$intfuseslist);
  132. // success
  133. module.$state=rtl.m_intf_loaded;
  134. // Note: units only used in implementations are not yet loaded (not even their interfaces)
  135. },
  136. loaduseslist: function(module,useslist,f){
  137. if (useslist==undefined) return;
  138. for (var i in useslist){
  139. var unitname=useslist[i];
  140. if (rtl.debug_load_units) rtl.debug('loaduseslist of "'+module.$name+'" uses="'+unitname+'"');
  141. if (pas[unitname]==undefined)
  142. rtl.error('module "'+module.$name+'" misses "'+unitname+'"');
  143. f(pas[unitname]);
  144. }
  145. },
  146. loadimpl: function(module){
  147. if (module.$state>=rtl.m_loading_impl) return; // already processing
  148. if (module.$state<rtl.m_intf_loaded) rtl.error('loadimpl: interface not loaded of "'+module.$name+'"');
  149. if (rtl.debug_load_units) rtl.debug('loadimpl: load uses of "'+module.$name+'"');
  150. module.$state=rtl.m_loading_impl;
  151. // load interfaces of implementation useslist
  152. rtl.loaduseslist(module,module.$impluseslist,rtl.loadintf);
  153. // load implementation of interfaces useslist
  154. rtl.loaduseslist(module,module.$intfuseslist,rtl.loadimpl);
  155. // load implementation of implementation useslist
  156. rtl.loaduseslist(module,module.$impluseslist,rtl.loadimpl);
  157. // Note: At this point all interfaces used by this unit are loaded. If
  158. // there are implementation uses cycles some used units might not yet be
  159. // initialized. This is by design.
  160. // run implementation
  161. if (rtl.debug_load_units) rtl.debug('loadimpl: run impl of "'+module.$name+'"');
  162. if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
  163. // run initialization
  164. if (rtl.debug_load_units) rtl.debug('loadimpl: run init of "'+module.$name+'"');
  165. module.$state=rtl.m_initializing;
  166. if (rtl.isFunction(module.$init)) module.$init();
  167. // unit initialized
  168. module.$state=rtl.m_initialized;
  169. },
  170. createCallback: function(scope, fn){
  171. var cb;
  172. if (typeof(fn)==='string'){
  173. cb = function(){
  174. return scope[fn].apply(scope,arguments);
  175. };
  176. } else {
  177. cb = function(){
  178. return fn.apply(scope,arguments);
  179. };
  180. };
  181. cb.scope = scope;
  182. cb.fn = fn;
  183. return cb;
  184. },
  185. cloneCallback: function(cb){
  186. return rtl.createCallback(cb.scope,cb.fn);
  187. },
  188. eqCallback: function(a,b){
  189. // can be a function or a function wrapper
  190. if (a==b){
  191. return true;
  192. } else {
  193. return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
  194. }
  195. },
  196. initClass: function(c,parent,name,initfn){
  197. parent[name] = c;
  198. c.$classname = name;
  199. if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module;
  200. c.$parent = parent;
  201. c.$fullname = parent.$name+'.'+name;
  202. if (rtl.isModule(parent)){
  203. c.$module = parent;
  204. c.$name = name;
  205. } else {
  206. c.$module = parent.$module;
  207. c.$name = parent.name+'.'+name;
  208. };
  209. // rtti
  210. if (rtl.debug_rtti) rtl.debug('initClass '+c.$fullname);
  211. var t = c.$module.$rtti.$Class(c.$name,{ "class": c, module: parent });
  212. c.$rtti = t;
  213. if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
  214. if (!t.ancestor) t.ancestor = null;
  215. // init members
  216. initfn.call(c);
  217. },
  218. createClass: function(parent,name,ancestor,initfn){
  219. // create a normal class,
  220. // ancestor must be null or a normal class,
  221. // the root ancestor can be an external class
  222. var c = null;
  223. if (ancestor != null){
  224. c = Object.create(ancestor);
  225. c.$ancestor = ancestor;
  226. // Note:
  227. // if root is an "object" then c.$ancestor === Object.getPrototypeOf(c)
  228. // if root is a "function" then c.$ancestor === c.__proto__, Object.getPrototypeOf(c) returns the root
  229. } else {
  230. c = {};
  231. c.$create = function(fnname,args){
  232. if (args == undefined) args = [];
  233. var o = Object.create(this);
  234. o.$class = this; // Note: o.$class === Object.getPrototypeOf(o)
  235. o.$init();
  236. try{
  237. o[fnname].apply(o,args);
  238. o.AfterConstruction();
  239. } catch($e){
  240. o.$destroy;
  241. throw $e;
  242. }
  243. return o;
  244. };
  245. c.$destroy = function(fnname){
  246. this.BeforeDestruction();
  247. this[fnname]();
  248. this.$final;
  249. };
  250. };
  251. rtl.initClass(c,parent,name,initfn);
  252. },
  253. createClassExt: function(parent,name,ancestor,newinstancefnname,initfn){
  254. // Create a class using an external ancestor.
  255. // If newinstancefnname is given, use that function to create the new object.
  256. // If exist call BeforeDestruction and AfterConstruction.
  257. var c = null;
  258. c = Object.create(ancestor);
  259. c.$create = function(fnname,args){
  260. if (args == undefined) args = [];
  261. var o = null;
  262. if (newinstancefnname.length>0){
  263. o = this[newinstancefnname](fnname,args);
  264. } else {
  265. o = Object.create(this);
  266. }
  267. o.$class = this; // Note: o.$class === Object.getPrototypeOf(o)
  268. o.$init();
  269. try{
  270. o[fnname].apply(o,args);
  271. if (o.AfterConstruction) o.AfterConstruction();
  272. } catch($e){
  273. o.$destroy;
  274. throw $e;
  275. }
  276. return o;
  277. };
  278. c.$destroy = function(fnname){
  279. if (this.BeforeDestruction) this.BeforeDestruction();
  280. this[fnname]();
  281. this.$final;
  282. };
  283. rtl.initClass(c,parent,name,initfn);
  284. },
  285. tObjectDestroy: "Destroy",
  286. free: function(obj,name){
  287. if (obj[name]==null) return;
  288. obj[name].$destroy(rtl.tObjectDestroy);
  289. obj[name]=null;
  290. },
  291. freeLoc: function(obj){
  292. if (obj==null) return;
  293. obj.$destroy(rtl.tObjectDestroy);
  294. return null;
  295. },
  296. is: function(instance,type){
  297. return type.isPrototypeOf(instance) || (instance===type);
  298. },
  299. isExt: function(instance,type,mode){
  300. // mode===1 means instance must be a Pascal class instance
  301. // mode===2 means instance must be a Pascal class
  302. // Notes:
  303. // isPrototypeOf and instanceof return false on equal
  304. // isPrototypeOf does not work for Date.isPrototypeOf(new Date())
  305. // so if isPrototypeOf is false test with instanceof
  306. // instanceof needs a function on right side
  307. if (instance == null) return false; // Note: ==null checks for undefined too
  308. if ((typeof(type) !== 'object') && (typeof(type) !== 'function')) return false;
  309. if (instance === type){
  310. if (mode===1) return false;
  311. if (mode===2) return rtl.isPasClass(instance);
  312. return true;
  313. }
  314. if (type.isPrototypeOf && type.isPrototypeOf(instance)){
  315. if (mode===1) return rtl.isPasClassInstance(instance);
  316. if (mode===2) return rtl.isPasClass(instance);
  317. return true;
  318. }
  319. if ((typeof type == 'function') && (instance instanceof type)) return true;
  320. return false;
  321. },
  322. Exception: null,
  323. EInvalidCast: null,
  324. EAbstractError: null,
  325. ERangeError: null,
  326. raiseE: function(typename){
  327. var t = rtl[typename];
  328. if (t==null){
  329. var mod = pas.SysUtils;
  330. if (!mod) mod = pas.sysutils;
  331. if (mod){
  332. t = mod[typename];
  333. if (!t) t = mod[typename.toLowerCase()];
  334. if (!t) t = mod['Exception'];
  335. if (!t) t = mod['exception'];
  336. }
  337. }
  338. if (t){
  339. if (t.Create){
  340. throw t.$create("Create");
  341. } else if (t.create){
  342. throw t.$create("create");
  343. }
  344. }
  345. if (typename === "EInvalidCast") throw "invalid type cast";
  346. if (typename === "EAbstractError") throw "Abstract method called";
  347. if (typename === "ERangeError") throw "range error";
  348. throw typename;
  349. },
  350. as: function(instance,type){
  351. if((instance === null) || rtl.is(instance,type)) return instance;
  352. rtl.raiseE("EInvalidCast");
  353. },
  354. asExt: function(instance,type,mode){
  355. if((instance === null) || rtl.isExt(instance,type,mode)) return instance;
  356. rtl.raiseE("EInvalidCast");
  357. },
  358. createInterface: function(module, name, guid, fnnames, ancestor, initfn){
  359. //console.log('createInterface name="'+name+'" guid="'+guid+'" names='+fnnames);
  360. var i = ancestor?Object.create(ancestor):{};
  361. module[name] = i;
  362. i.$module = module;
  363. i.$name = name;
  364. i.$fullname = module.$name+'.'+name;
  365. i.$guid = guid;
  366. i.$guidr = null;
  367. i.$names = fnnames?fnnames:[];
  368. if (rtl.isFunction(initfn)){
  369. // rtti
  370. if (rtl.debug_rtti) rtl.debug('createInterface '+i.$fullname);
  371. var t = i.$module.$rtti.$Interface(name,{ "interface": i, module: module });
  372. i.$rtti = t;
  373. if (ancestor) t.ancestor = ancestor.$rtti;
  374. if (!t.ancestor) t.ancestor = null;
  375. initfn.call(i);
  376. }
  377. return i;
  378. },
  379. strToGUIDR: function(s,g){
  380. var p = 0;
  381. function n(l){
  382. var h = s.substr(p,l);
  383. p+=l;
  384. return parseInt(h,16);
  385. }
  386. p+=1; // skip {
  387. g.D1 = n(8);
  388. p+=1; // skip -
  389. g.D2 = n(4);
  390. p+=1; // skip -
  391. g.D3 = n(4);
  392. p+=1; // skip -
  393. if (!g.D4) g.D4=[];
  394. g.D4[0] = n(2);
  395. g.D4[1] = n(2);
  396. p+=1; // skip -
  397. for(var i=2; i<8; i++) g.D4[i] = n(2);
  398. return g;
  399. },
  400. guidrToStr: function(g){
  401. if (g.$intf) return g.$intf.$guid;
  402. var h = rtl.hexStr;
  403. var s='{'+h(g.D1,8)+'-'+h(g.D2,4)+'-'+h(g.D3,4)+'-'+h(g.D4[0],2)+h(g.D4[1],2)+'-';
  404. for (var i=2; i<8; i++) s+=h(g.D4[i],2);
  405. s+='}';
  406. return s;
  407. },
  408. createTGUID: function(guid){
  409. var TGuid = (pas.System)?pas.System.TGuid:pas.system.tguid;
  410. var g = rtl.strToGUIDR(guid,new TGuid());
  411. return g;
  412. },
  413. getIntfGUIDR: function(intfTypeOrVar){
  414. if (!intfTypeOrVar) return null;
  415. if (!intfTypeOrVar.$guidr){
  416. var g = rtl.createTGUID(intfTypeOrVar.$guid);
  417. if (!intfTypeOrVar.hasOwnProperty('$guid')) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
  418. g.$intf = intfTypeOrVar;
  419. intfTypeOrVar.$guidr = g;
  420. }
  421. return intfTypeOrVar.$guidr;
  422. },
  423. addIntf: function (aclass, intf, map){
  424. function jmp(fn){
  425. if (typeof(fn)==="function"){
  426. return function(){ return fn.apply(this.$o,arguments); };
  427. } else {
  428. return function(){ rtl.raiseE('EAbstractError'); };
  429. }
  430. }
  431. if(!map) map = {};
  432. var t = intf;
  433. var item = Object.create(t);
  434. aclass.$intfmaps[intf.$guid] = item;
  435. do{
  436. var names = t.$names;
  437. if (!names) break;
  438. for (var i=0; i<names.length; i++){
  439. var intfname = names[i];
  440. var fnname = map[intfname];
  441. if (!fnname) fnname = intfname;
  442. //console.log('addIntf: intftype='+t.$name+' index='+i+' intfname="'+intfname+'" fnname="'+fnname+'" proc='+typeof(fn));
  443. item[intfname] = jmp(aclass[fnname]);
  444. }
  445. t = Object.getPrototypeOf(t);
  446. }while(t!=null);
  447. },
  448. getIntfG: function (obj, guid, query){
  449. if (!obj) return null;
  450. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query);
  451. // search
  452. var maps = obj.$intfmaps;
  453. if (!maps) return null;
  454. var item = maps[guid];
  455. if (!item) return null;
  456. // check delegation
  457. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query+' item='+typeof(item));
  458. if (typeof item === 'function') return item.call(obj); // COM: contains _AddRef
  459. // check cache
  460. var intf = null;
  461. if (obj.$interfaces){
  462. intf = obj.$interfaces[guid];
  463. //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' cache='+typeof(intf));
  464. }
  465. if (!intf){ // intf can be undefined!
  466. intf = Object.create(item);
  467. intf.$o = obj;
  468. if (!obj.$interfaces) obj.$interfaces = {};
  469. obj.$interfaces[guid] = intf;
  470. }
  471. if (typeof(query)==='object'){
  472. // called by queryIntfT
  473. var o = null;
  474. if (intf.QueryInterface(rtl.getIntfGUIDR(query),
  475. {get:function(){ return o; }, set:function(v){ o=v; }}) === 0){
  476. return o;
  477. } else {
  478. return null;
  479. }
  480. } else if(query===2){
  481. // called by TObject.GetInterfaceByStr
  482. if (intf.$kind === 'com') intf._AddRef();
  483. }
  484. return intf;
  485. },
  486. getIntfT: function(obj,intftype){
  487. return rtl.getIntfG(obj,intftype.$guid);
  488. },
  489. queryIntfT: function(obj,intftype){
  490. return rtl.getIntfG(obj,intftype.$guid,intftype);
  491. },
  492. queryIntfIsT: function(obj,intftype){
  493. var i = rtl.queryIntfG(obj,intftype.$guid);
  494. if (!i) return false;
  495. if (i.$kind === 'com') i._Release();
  496. return true;
  497. },
  498. asIntfT: function (obj,intftype){
  499. var i = rtl.getIntfG(obj,intftype.$guid);
  500. if (i!==null) return i;
  501. rtl.raiseEInvalidCast();
  502. },
  503. intfIsClass: function(intf,classtype){
  504. return (intf!=null) && (rtl.is(intf.$o,classtype));
  505. },
  506. intfAsClass: function(intf,classtype){
  507. if (intf==null) return null;
  508. return rtl.as(intf.$o,classtype);
  509. },
  510. intfToClass: function(intf,classtype){
  511. if ((intf!==null) && rtl.is(intf.$o,classtype)) return intf.$o;
  512. return null;
  513. },
  514. // interface reference counting
  515. intfRefs: { // base object for temporary interface variables
  516. ref: function(id,intf){
  517. // called for temporary interface references needing delayed release
  518. var old = this[id];
  519. //console.log('rtl.intfRefs.ref: id='+id+' old="'+(old?old.$name:'null')+'" intf="'+(intf?intf.$name:'null'));
  520. if (old){
  521. // called again, e.g. in a loop
  522. delete this[id];
  523. old._Release(); // may fail
  524. }
  525. this[id]=intf;
  526. return intf;
  527. },
  528. free: function(){
  529. //console.log('rtl.intfRefs.free...');
  530. for (var id in this){
  531. if (this.hasOwnProperty(id)) this[id]._Release;
  532. }
  533. }
  534. },
  535. createIntfRefs: function(){
  536. //console.log('rtl.createIntfRefs');
  537. return Object.create(rtl.intfRefs);
  538. },
  539. setIntfP: function(path,name,value,skipAddRef){
  540. var old = path[name];
  541. //console.log('rtl.setIntfP path='+path+' name='+name+' old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  542. if (old === value) return;
  543. if (old !== null){
  544. path[name]=null;
  545. old._Release();
  546. }
  547. if (value !== null){
  548. if (!skipAddRef) value._AddRef();
  549. path[name]=value;
  550. }
  551. },
  552. setIntfL: function(old,value,skipAddRef){
  553. //console.log('rtl.setIntfL old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
  554. if (old !== value){
  555. if (value!==null){
  556. if (!skipAddRef) value._AddRef();
  557. }
  558. if (old!==null){
  559. old._Release(); // Release after AddRef, to avoid double Release if Release creates an exception
  560. }
  561. } else if (skipAddRef){
  562. if (old!==null){
  563. old._Release(); // value has an AddRef
  564. }
  565. }
  566. return value;
  567. },
  568. _AddRef: function(intf){
  569. //if (intf) console.log('rtl._AddRef intf="'+(intf?intf.$name:'null')+'"');
  570. if (intf) intf._AddRef();
  571. return intf;
  572. },
  573. _Release: function(intf){
  574. //if (intf) console.log('rtl._Release intf="'+(intf?intf.$name:'null')+'"');
  575. if (intf) intf._Release();
  576. return intf;
  577. },
  578. checkMethodCall: function(obj,type){
  579. if (rtl.isObject(obj) && rtl.is(obj,type)) return;
  580. rtl.raiseE("EInvalidCast");
  581. },
  582. rc: function(i,minval,maxval){
  583. // range check integer
  584. if ((Math.floor(i)===i) && (i>=minval) && (i<=maxval)) return i;
  585. rtl.raiseE('ERangeError');
  586. },
  587. rcc: function(c,minval,maxval){
  588. // range check char
  589. if ((typeof(c)==='string') && (c.length===1)){
  590. var i = c.charCodeAt(0);
  591. if ((i>=minval) && (i<=maxval)) return c;
  592. }
  593. rtl.raiseE('ERangeError');
  594. },
  595. rcSetCharAt: function(s,index,c){
  596. // range check setCharAt
  597. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  598. return rtl.setCharAt(s,index,c);
  599. },
  600. rcCharAt: function(s,index){
  601. // range check charAt
  602. if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
  603. return s.charAt(index);
  604. },
  605. rcArrR: function(arr,index){
  606. // range check read array
  607. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  608. if (arguments.length>2){
  609. // arr,index1,index2,...
  610. arr=arr[index];
  611. for (var i=2; i<arguments.length; i++) arr=rtl.rcArrR(arr,arguments[i]);
  612. return arr;
  613. }
  614. return arr[index];
  615. }
  616. rtl.raiseE('ERangeError');
  617. },
  618. rcArrW: function(arr,index,value){
  619. // range check write array
  620. // arr,index1,index2,...,value
  621. for (var i=3; i<arguments.length; i++){
  622. arr=rtl.rcArrR(arr,index);
  623. index=arguments[i-1];
  624. value=arguments[i];
  625. }
  626. if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
  627. return arr[index]=value;
  628. }
  629. rtl.raiseE('ERangeError');
  630. },
  631. length: function(arr){
  632. return (arr == null) ? 0 : arr.length;
  633. },
  634. arraySetLength: function(arr,defaultvalue,newlength){
  635. // multi dim: (arr,defaultvalue,dim1,dim2,...)
  636. if (arr == null) arr = [];
  637. var p = arguments;
  638. function setLength(a,argNo){
  639. var oldlen = a.length;
  640. var newlen = p[argNo];
  641. if (oldlen!==newlength){
  642. a.length = newlength;
  643. if (argNo === p.length-1){
  644. if (rtl.isArray(defaultvalue)){
  645. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  646. } else if (rtl.isFunction(defaultvalue)){
  647. for (var i=oldlen; i<newlen; i++) a[i]=new defaultvalue(); // e.g. record
  648. } else if (rtl.isObject(defaultvalue)) {
  649. for (var i=oldlen; i<newlen; i++) a[i]={}; // e.g. set
  650. } else {
  651. for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue;
  652. }
  653. } else {
  654. for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
  655. }
  656. }
  657. if (argNo < p.length-1){
  658. // multi argNo
  659. for (var i=0; i<newlen; i++) a[i]=setLength(a[i],argNo+1);
  660. }
  661. return a;
  662. }
  663. return setLength(arr,2);
  664. },
  665. arrayEq: function(a,b){
  666. if (a===null) return b===null;
  667. if (b===null) return false;
  668. if (a.length!==b.length) return false;
  669. for (var i=0; i<a.length; i++) if (a[i]!==b[i]) return false;
  670. return true;
  671. },
  672. arrayClone: function(type,src,srcpos,end,dst,dstpos){
  673. // type: 0 for references, "refset" for calling refSet(), a function for new type()
  674. // src must not be null
  675. // This function does not range check.
  676. if (rtl.isFunction(type)){
  677. for (; srcpos<end; srcpos++) dst[dstpos++] = new type(src[srcpos]); // clone record
  678. } else if((typeof(type)==="string") && (type === 'refSet')) {
  679. for (; srcpos<end; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]); // ref set
  680. } else {
  681. for (; srcpos<end; srcpos++) dst[dstpos++] = src[srcpos]; // reference
  682. };
  683. },
  684. arrayConcat: function(type){
  685. // type: see rtl.arrayClone
  686. var a = [];
  687. var l = 0;
  688. for (var i=1; i<arguments.length; i++) l+=arguments[i].length;
  689. a.length = l;
  690. l=0;
  691. for (var i=1; i<arguments.length; i++){
  692. var src = arguments[i];
  693. if (src == null) continue;
  694. rtl.arrayClone(type,src,0,src.length,a,l);
  695. l+=src.length;
  696. };
  697. return a;
  698. },
  699. arrayCopy: function(type, srcarray, index, count){
  700. // type: see rtl.arrayClone
  701. // if count is missing, use srcarray.length
  702. if (srcarray == null) return [];
  703. if (index < 0) index = 0;
  704. if (count === undefined) count=srcarray.length;
  705. var end = index+count;
  706. if (end>srcarray.length) end = srcarray.length;
  707. if (index>=end) return [];
  708. if (type===0){
  709. return srcarray.slice(index,end);
  710. } else {
  711. var a = [];
  712. a.length = end-index;
  713. rtl.arrayClone(type,srcarray,index,end,a,0);
  714. return a;
  715. }
  716. },
  717. setCharAt: function(s,index,c){
  718. return s.substr(0,index)+c+s.substr(index+1);
  719. },
  720. getResStr: function(mod,name){
  721. var rs = mod.$resourcestrings[name];
  722. return rs.current?rs.current:rs.org;
  723. },
  724. createSet: function(){
  725. var s = {};
  726. for (var i=0; i<arguments.length; i++){
  727. if (arguments[i]!=null){
  728. s[arguments[i]]=true;
  729. } else {
  730. var first=arguments[i+=1];
  731. var last=arguments[i+=1];
  732. for(var j=first; j<=last; j++) s[j]=true;
  733. }
  734. }
  735. return s;
  736. },
  737. cloneSet: function(s){
  738. var r = {};
  739. for (var key in s) r[key]=true;
  740. return r;
  741. },
  742. refSet: function(s){
  743. s.$shared = true;
  744. return s;
  745. },
  746. includeSet: function(s,enumvalue){
  747. if (s.$shared) s = rtl.cloneSet(s);
  748. s[enumvalue] = true;
  749. return s;
  750. },
  751. excludeSet: function(s,enumvalue){
  752. if (s.$shared) s = rtl.cloneSet(s);
  753. delete s[enumvalue];
  754. return s;
  755. },
  756. diffSet: function(s,t){
  757. var r = {};
  758. for (var key in s) if (!t[key]) r[key]=true;
  759. delete r.$shared;
  760. return r;
  761. },
  762. unionSet: function(s,t){
  763. var r = {};
  764. for (var key in s) r[key]=true;
  765. for (var key in t) r[key]=true;
  766. delete r.$shared;
  767. return r;
  768. },
  769. intersectSet: function(s,t){
  770. var r = {};
  771. for (var key in s) if (t[key]) r[key]=true;
  772. delete r.$shared;
  773. return r;
  774. },
  775. symDiffSet: function(s,t){
  776. var r = {};
  777. for (var key in s) if (!t[key]) r[key]=true;
  778. for (var key in t) if (!s[key]) r[key]=true;
  779. delete r.$shared;
  780. return r;
  781. },
  782. eqSet: function(s,t){
  783. for (var key in s) if (!t[key] && (key!='$shared')) return false;
  784. for (var key in t) if (!s[key] && (key!='$shared')) return false;
  785. return true;
  786. },
  787. neSet: function(s,t){
  788. return !rtl.eqSet(s,t);
  789. },
  790. leSet: function(s,t){
  791. for (var key in s) if (!t[key] && (key!='$shared')) return false;
  792. return true;
  793. },
  794. geSet: function(s,t){
  795. for (var key in t) if (!s[key] && (key!='$shared')) return false;
  796. return true;
  797. },
  798. strSetLength: function(s,newlen){
  799. var oldlen = s.length;
  800. if (oldlen > newlen){
  801. return s.substring(0,newlen);
  802. } else if (s.repeat){
  803. // Note: repeat needs ECMAScript6!
  804. return s+' '.repeat(newlen-oldlen);
  805. } else {
  806. while (oldlen<newlen){
  807. s+=' ';
  808. oldlen++;
  809. };
  810. return s;
  811. }
  812. },
  813. spaceLeft: function(s,width){
  814. var l=s.length;
  815. if (l>=width) return s;
  816. if (s.repeat){
  817. // Note: repeat needs ECMAScript6!
  818. return ' '.repeat(width-l) + s;
  819. } else {
  820. while (l<width){
  821. s=' '+s;
  822. l++;
  823. };
  824. };
  825. },
  826. floatToStr : function(d,w,p){
  827. // input 1-3 arguments: double, width, precision
  828. if (arguments.length>2){
  829. return rtl.spaceLeft(d.toFixed(p),w);
  830. } else {
  831. // exponent width
  832. var pad = "";
  833. var ad = Math.abs(d);
  834. if (ad<1.0e+10) {
  835. pad='00';
  836. } else if (ad<1.0e+100) {
  837. pad='0';
  838. }
  839. if (arguments.length<2) {
  840. w=9;
  841. } else if (w<9) {
  842. w=9;
  843. }
  844. var p = w-8;
  845. var s=(d>0 ? " " : "" ) + d.toExponential(p);
  846. s=s.replace(/e(.)/,'E$1'+pad);
  847. return rtl.spaceLeft(s,w);
  848. }
  849. },
  850. initRTTI: function(){
  851. if (rtl.debug_rtti) rtl.debug('initRTTI');
  852. // base types
  853. rtl.tTypeInfo = { name: "tTypeInfo" };
  854. function newBaseTI(name,kind,ancestor){
  855. if (!ancestor) ancestor = rtl.tTypeInfo;
  856. if (rtl.debug_rtti) rtl.debug('initRTTI.newBaseTI "'+name+'" '+kind+' ("'+ancestor.name+'")');
  857. var t = Object.create(ancestor);
  858. t.name = name;
  859. t.kind = kind;
  860. rtl[name] = t;
  861. return t;
  862. };
  863. function newBaseInt(name,minvalue,maxvalue,ordtype){
  864. var t = newBaseTI(name,1 /* tkInteger */,rtl.tTypeInfoInteger);
  865. t.minvalue = minvalue;
  866. t.maxvalue = maxvalue;
  867. t.ordtype = ordtype;
  868. return t;
  869. };
  870. newBaseTI("tTypeInfoInteger",1 /* tkInteger */);
  871. newBaseInt("shortint",-0x80,0x7f,0);
  872. newBaseInt("byte",0,0xff,1);
  873. newBaseInt("smallint",-0x8000,0x7fff,2);
  874. newBaseInt("word",0,0xffff,3);
  875. newBaseInt("longint",-0x80000000,0x7fffffff,4);
  876. newBaseInt("longword",0,0xffffffff,5);
  877. newBaseInt("nativeint",-0x10000000000000,0xfffffffffffff,6);
  878. newBaseInt("nativeuint",0,0xfffffffffffff,7);
  879. newBaseTI("char",2 /* tkChar */);
  880. newBaseTI("string",3 /* tkString */);
  881. newBaseTI("tTypeInfoEnum",4 /* tkEnumeration */,rtl.tTypeInfoInteger);
  882. newBaseTI("tTypeInfoSet",5 /* tkSet */);
  883. newBaseTI("double",6 /* tkDouble */);
  884. newBaseTI("boolean",7 /* tkBool */);
  885. newBaseTI("tTypeInfoProcVar",8 /* tkProcVar */);
  886. newBaseTI("tTypeInfoMethodVar",9 /* tkMethod */,rtl.tTypeInfoProcVar);
  887. newBaseTI("tTypeInfoArray",10 /* tkArray */);
  888. newBaseTI("tTypeInfoDynArray",11 /* tkDynArray */);
  889. newBaseTI("tTypeInfoPointer",15 /* tkPointer */);
  890. var t = newBaseTI("pointer",15 /* tkPointer */,rtl.tTypeInfoPointer);
  891. t.reftype = null;
  892. newBaseTI("jsvalue",16 /* tkJSValue */);
  893. newBaseTI("tTypeInfoRefToProcVar",17 /* tkRefToProcVar */,rtl.tTypeInfoProcVar);
  894. // member kinds
  895. rtl.tTypeMember = {};
  896. function newMember(name,kind){
  897. var m = Object.create(rtl.tTypeMember);
  898. m.name = name;
  899. m.kind = kind;
  900. rtl[name] = m;
  901. };
  902. newMember("tTypeMemberField",1); // tmkField
  903. newMember("tTypeMemberMethod",2); // tmkMethod
  904. newMember("tTypeMemberProperty",3); // tmkProperty
  905. // base object for storing members: a simple object
  906. rtl.tTypeMembers = {};
  907. // tTypeInfoStruct - base object for tTypeInfoClass, tTypeInfoRecord, tTypeInfoInterface
  908. var tis = newBaseTI("tTypeInfoStruct",0);
  909. tis.$addMember = function(name,ancestor,options){
  910. if (rtl.debug_rtti){
  911. if (!rtl.hasString(name) || (name.charAt()==='$')) throw 'invalid member "'+name+'", this="'+this.name+'"';
  912. if (!rtl.is(ancestor,rtl.tTypeMember)) throw 'invalid ancestor "'+ancestor+':'+ancestor.name+'", "'+this.name+'.'+name+'"';
  913. if ((options!=undefined) && (typeof(options)!='object')) throw 'invalid options "'+options+'", "'+this.name+'.'+name+'"';
  914. };
  915. var t = Object.create(ancestor);
  916. t.name = name;
  917. this.members[name] = t;
  918. this.names.push(name);
  919. if (rtl.isObject(options)){
  920. for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
  921. };
  922. return t;
  923. };
  924. tis.addField = function(name,type,options){
  925. var t = this.$addMember(name,rtl.tTypeMemberField,options);
  926. if (rtl.debug_rtti){
  927. if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
  928. };
  929. t.typeinfo = type;
  930. this.fields.push(name);
  931. return t;
  932. };
  933. tis.addFields = function(){
  934. var i=0;
  935. while(i<arguments.length){
  936. var name = arguments[i++];
  937. var type = arguments[i++];
  938. if ((i<arguments.length) && (typeof(arguments[i])==='object')){
  939. this.addField(name,type,arguments[i++]);
  940. } else {
  941. this.addField(name,type);
  942. };
  943. };
  944. };
  945. tis.addMethod = function(name,methodkind,params,result,options){
  946. var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
  947. t.methodkind = methodkind;
  948. t.procsig = rtl.newTIProcSig(params);
  949. t.procsig.resulttype = result?result:null;
  950. this.methods.push(name);
  951. return t;
  952. };
  953. tis.addProperty = function(name,flags,result,getter,setter,options){
  954. var t = this.$addMember(name,rtl.tTypeMemberProperty,options);
  955. t.flags = flags;
  956. t.typeinfo = result;
  957. t.getter = getter;
  958. t.setter = setter;
  959. // Note: in options: params, stored, defaultvalue
  960. if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
  961. this.properties.push(name);
  962. if (!rtl.isString(t.stored)) t.stored = "";
  963. return t;
  964. };
  965. tis.getField = function(index){
  966. return this.members[this.fields[index]];
  967. };
  968. tis.getMethod = function(index){
  969. return this.members[this.methods[index]];
  970. };
  971. tis.getProperty = function(index){
  972. return this.members[this.properties[index]];
  973. };
  974. newBaseTI("tTypeInfoRecord",12 /* tkRecord */,rtl.tTypeInfoStruct);
  975. newBaseTI("tTypeInfoClass",13 /* tkClass */,rtl.tTypeInfoStruct);
  976. newBaseTI("tTypeInfoClassRef",14 /* tkClassRef */);
  977. newBaseTI("tTypeInfoInterface",15 /* tkInterface */,rtl.tTypeInfoStruct);
  978. },
  979. tSectionRTTI: {
  980. $module: null,
  981. $inherited: function(name,ancestor,o){
  982. if (rtl.debug_rtti){
  983. rtl.debug('tSectionRTTI.newTI "'+(this.$module?this.$module.$name:"(no module)")
  984. +'"."'+name+'" ('+ancestor.name+') '+(o?'init':'forward'));
  985. };
  986. var t = this[name];
  987. if (t){
  988. if (!t.$forward) throw 'duplicate type "'+name+'"';
  989. if (!ancestor.isPrototypeOf(t)) throw 'typeinfo ancestor mismatch "'+name+'" ancestor="'+ancestor.name+'" t.name="'+t.name+'"';
  990. } else {
  991. t = Object.create(ancestor);
  992. t.name = name;
  993. t.module = this.module;
  994. this[name] = t;
  995. }
  996. if (o){
  997. delete t.$forward;
  998. for (var key in o) if (o.hasOwnProperty(key)) t[key]=o[key];
  999. } else {
  1000. t.$forward = true;
  1001. }
  1002. return t;
  1003. },
  1004. $Scope: function(name,ancestor,o){
  1005. var t=this.$inherited(name,ancestor,o);
  1006. t.members = {};
  1007. t.names = [];
  1008. t.fields = [];
  1009. t.methods = [];
  1010. t.properties = [];
  1011. return t;
  1012. },
  1013. $TI: function(name,kind,o){ var t=this.$inherited(name,rtl.tTypeInfo,o); t.kind = kind; return t; },
  1014. $Int: function(name,o){ return this.$inherited(name,rtl.tTypeInfoInteger,o); },
  1015. $Enum: function(name,o){ return this.$inherited(name,rtl.tTypeInfoEnum,o); },
  1016. $Set: function(name,o){ return this.$inherited(name,rtl.tTypeInfoSet,o); },
  1017. $StaticArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoArray,o); },
  1018. $DynArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoDynArray,o); },
  1019. $ProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoProcVar,o); },
  1020. $RefToProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoRefToProcVar,o); },
  1021. $MethodVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoMethodVar,o); },
  1022. $Record: function(name,o){ return this.$Scope(name,rtl.tTypeInfoRecord,o); },
  1023. $Class: function(name,o){ return this.$Scope(name,rtl.tTypeInfoClass,o); },
  1024. $ClassRef: function(name,o){ return this.$inherited(name,rtl.tTypeInfoClassRef,o); },
  1025. $Pointer: function(name,o){ return this.$inherited(name,rtl.tTypeInfoPointer,o); },
  1026. $Interface: function(name,o){ return this.$Scope(name,rtl.tTypeInfoInterface,o); }
  1027. },
  1028. newTIParam: function(param){
  1029. // param is an array, 0=name, 1=type, 2=optional flags
  1030. var t = {
  1031. name: param[0],
  1032. typeinfo: param[1],
  1033. flags: (rtl.isNumber(param[2]) ? param[2] : 0)
  1034. };
  1035. return t;
  1036. },
  1037. newTIParams: function(list){
  1038. // list: optional array of [paramname,typeinfo,optional flags]
  1039. var params = [];
  1040. if (rtl.isArray(list)){
  1041. for (var i=0; i<list.length; i++) params.push(rtl.newTIParam(list[i]));
  1042. };
  1043. return params;
  1044. },
  1045. newTIProcSig: function(params,result,flags){
  1046. var s = {
  1047. params: rtl.newTIParams(params),
  1048. resulttype: result,
  1049. flags: flags
  1050. };
  1051. return s;
  1052. }
  1053. }
  1054. rtl.module("System",[],function () {
  1055. "use strict";
  1056. var $mod = this;
  1057. var $impl = $mod.$impl;
  1058. this.LineEnding = "\n";
  1059. this.sLineBreak = $mod.LineEnding;
  1060. this.MaxSmallint = 32767;
  1061. this.MinSmallint = -32768;
  1062. this.MaxShortInt = 127;
  1063. this.MinShortInt = -128;
  1064. this.MaxByte = 0xFF;
  1065. this.MaxWord = 0xFFFF;
  1066. this.MaxLongint = 0x7fffffff;
  1067. this.MaxCardinal = 0xffffffff;
  1068. this.Maxint = 2147483647;
  1069. this.IsMultiThread = false;
  1070. this.TTextLineBreakStyle = {"0": "tlbsLF", tlbsLF: 0, "1": "tlbsCRLF", tlbsCRLF: 1, "2": "tlbsCR", tlbsCR: 2};
  1071. this.TGuid = function (s) {
  1072. if (s) {
  1073. this.D1 = s.D1;
  1074. this.D2 = s.D2;
  1075. this.D3 = s.D3;
  1076. this.D4 = s.D4.slice(0);
  1077. } else {
  1078. this.D1 = 0;
  1079. this.D2 = 0;
  1080. this.D3 = 0;
  1081. this.D4 = rtl.arraySetLength(null,0,8);
  1082. };
  1083. this.$equal = function (b) {
  1084. return (this.D1 === b.D1) && ((this.D2 === b.D2) && ((this.D3 === b.D3) && rtl.arrayEq(this.D4,b.D4)));
  1085. };
  1086. };
  1087. rtl.createClass($mod,"TObject",null,function () {
  1088. this.$init = function () {
  1089. };
  1090. this.$final = function () {
  1091. };
  1092. this.Create = function () {
  1093. };
  1094. this.Destroy = function () {
  1095. };
  1096. this.Free = function () {
  1097. this.$destroy("Destroy");
  1098. };
  1099. this.ClassType = function () {
  1100. return this;
  1101. };
  1102. this.ClassNameIs = function (Name) {
  1103. var Result = false;
  1104. Result = $impl.SameText(Name,this.$classname);
  1105. return Result;
  1106. };
  1107. this.InheritsFrom = function (aClass) {
  1108. return (aClass!=null) && ((this==aClass) || aClass.isPrototypeOf(this));
  1109. };
  1110. this.AfterConstruction = function () {
  1111. };
  1112. this.BeforeDestruction = function () {
  1113. };
  1114. this.GetInterface = function (iid, obj) {
  1115. var Result = false;
  1116. var i = iid.$intf;
  1117. if (i){
  1118. i = rtl.getIntfG(this,i.$guid,2);
  1119. if (i){
  1120. obj.set(i);
  1121. return true;
  1122. }
  1123. };
  1124. Result = this.GetInterfaceByStr(rtl.guidrToStr(iid),obj);
  1125. return Result;
  1126. };
  1127. this.GetInterface$1 = function (iidstr, obj) {
  1128. var Result = false;
  1129. Result = this.GetInterfaceByStr(iidstr,obj);
  1130. return Result;
  1131. };
  1132. this.GetInterfaceByStr = function (iidstr, obj) {
  1133. var Result = false;
  1134. if ($mod.IObjectInstance.$equal(rtl.createTGUID(iidstr))) {
  1135. obj.set(this);
  1136. return true;
  1137. };
  1138. var i = rtl.getIntfG(this,iidstr,2);
  1139. obj.set(i);
  1140. return i!==null;
  1141. Result = false;
  1142. return Result;
  1143. };
  1144. this.GetInterfaceWeak = function (iid, obj) {
  1145. var Result = false;
  1146. Result = this.GetInterface(iid,obj);
  1147. if (Result){
  1148. var o = obj.get();
  1149. if (o.$kind==='com'){
  1150. o._Release();
  1151. }
  1152. };
  1153. return Result;
  1154. };
  1155. this.Equals = function (Obj) {
  1156. var Result = false;
  1157. Result = Obj === this;
  1158. return Result;
  1159. };
  1160. this.ToString = function () {
  1161. var Result = "";
  1162. Result = this.$classname;
  1163. return Result;
  1164. };
  1165. });
  1166. this.S_OK = 0;
  1167. this.S_FALSE = 1;
  1168. this.E_NOINTERFACE = -2147467262;
  1169. this.E_UNEXPECTED = -2147418113;
  1170. this.E_NOTIMPL = -2147467263;
  1171. rtl.createInterface($mod,"IUnknown","{00000000-0000-0000-C000-000000000046}",["QueryInterface","_AddRef","_Release"],null,function () {
  1172. this.$kind = "com";
  1173. var $r = this.$rtti;
  1174. $r.addMethod("QueryInterface",1,[["iid",$mod.$rtti["TGuid"],2],["obj",null,4]],rtl.longint);
  1175. $r.addMethod("_AddRef",1,null,rtl.longint);
  1176. $r.addMethod("_Release",1,null,rtl.longint);
  1177. });
  1178. rtl.createInterface($mod,"IInvokable","{88387EF6-BCEE-3E17-9E85-5D491ED4FC10}",[],$mod.IUnknown,function () {
  1179. });
  1180. rtl.createInterface($mod,"IEnumerator","{ECEC7568-4E50-30C9-A2F0-439342DE2ADB}",["GetCurrent","MoveNext","Reset"],$mod.IUnknown);
  1181. rtl.createInterface($mod,"IEnumerable","{9791C368-4E51-3424-A3CE-D4911D54F385}",["GetEnumerator"],$mod.IUnknown);
  1182. rtl.createClass($mod,"TInterfacedObject",$mod.TObject,function () {
  1183. this.$init = function () {
  1184. $mod.TObject.$init.call(this);
  1185. this.fRefCount = 0;
  1186. };
  1187. this.QueryInterface = function (iid, obj) {
  1188. var Result = 0;
  1189. if (this.GetInterface(iid,obj)) {
  1190. Result = 0}
  1191. else Result = -2147467262;
  1192. return Result;
  1193. };
  1194. this._AddRef = function () {
  1195. var Result = 0;
  1196. this.fRefCount += 1;
  1197. Result = this.fRefCount;
  1198. return Result;
  1199. };
  1200. this._Release = function () {
  1201. var Result = 0;
  1202. this.fRefCount -= 1;
  1203. Result = this.fRefCount;
  1204. if (this.fRefCount === 0) this.$destroy("Destroy");
  1205. return Result;
  1206. };
  1207. this.BeforeDestruction = function () {
  1208. if (this.fRefCount !== 0) rtl.raiseE('EHeapMemoryError');
  1209. };
  1210. this.$intfmaps = {};
  1211. rtl.addIntf(this,$mod.IUnknown);
  1212. });
  1213. rtl.createClass($mod,"TAggregatedObject",$mod.TObject,function () {
  1214. this.$init = function () {
  1215. $mod.TObject.$init.call(this);
  1216. this.fController = null;
  1217. };
  1218. this.GetController = function () {
  1219. var Result = null;
  1220. var $ok = false;
  1221. try {
  1222. Result = rtl.setIntfL(Result,this.fController);
  1223. $ok = true;
  1224. } finally {
  1225. if (!$ok) rtl._Release(Result);
  1226. };
  1227. return Result;
  1228. };
  1229. this.QueryInterface = function (iid, obj) {
  1230. var Result = 0;
  1231. Result = this.fController.QueryInterface(iid,obj);
  1232. return Result;
  1233. };
  1234. this._AddRef = function () {
  1235. var Result = 0;
  1236. Result = this.fController._AddRef();
  1237. return Result;
  1238. };
  1239. this._Release = function () {
  1240. var Result = 0;
  1241. Result = this.fController._Release();
  1242. return Result;
  1243. };
  1244. this.Create$1 = function (aController) {
  1245. $mod.TObject.Create.call(this);
  1246. this.fController = aController;
  1247. };
  1248. });
  1249. rtl.createClass($mod,"TContainedObject",$mod.TAggregatedObject,function () {
  1250. this.QueryInterface = function (iid, obj) {
  1251. var Result = 0;
  1252. if (this.GetInterface(iid,obj)) {
  1253. Result = 0}
  1254. else Result = -2147467262;
  1255. return Result;
  1256. };
  1257. this.$intfmaps = {};
  1258. rtl.addIntf(this,$mod.IUnknown);
  1259. });
  1260. this.IObjectInstance = new $mod.TGuid({D1: 0xD91C9AF4, D2: 0x3C93, D3: 0x420F, D4: [0xA3,0x03,0xBF,0x5B,0xA8,0x2B,0xFD,0x23]});
  1261. this.IsConsole = false;
  1262. this.OnParamCount = null;
  1263. this.OnParamStr = null;
  1264. this.ParamCount = function () {
  1265. var Result = 0;
  1266. if ($mod.OnParamCount != null) {
  1267. Result = $mod.OnParamCount()}
  1268. else Result = 0;
  1269. return Result;
  1270. };
  1271. this.ParamStr = function (Index) {
  1272. var Result = "";
  1273. if ($mod.OnParamStr != null) {
  1274. Result = $mod.OnParamStr(Index)}
  1275. else if (Index === 0) {
  1276. Result = "js"}
  1277. else Result = "";
  1278. return Result;
  1279. };
  1280. this.Frac = function (A) {
  1281. return A % 1;
  1282. };
  1283. this.Odd = function (A) {
  1284. return A&1 != 0;
  1285. };
  1286. this.Random = function (Range) {
  1287. return Math.floor(Math.random()*Range);
  1288. };
  1289. this.Sqr = function (A) {
  1290. return A*A;
  1291. };
  1292. this.Sqr$1 = function (A) {
  1293. return A*A;
  1294. };
  1295. this.Trunc = function (A) {
  1296. if (!Math.trunc) {
  1297. Math.trunc = function(v) {
  1298. v = +v;
  1299. if (!isFinite(v)) return v;
  1300. return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
  1301. };
  1302. }
  1303. $mod.Trunc = Math.trunc;
  1304. return Math.trunc(A);
  1305. };
  1306. this.DefaultTextLineBreakStyle = $mod.TTextLineBreakStyle.tlbsLF;
  1307. this.Int = function (A) {
  1308. var Result = 0.0;
  1309. Result = Math.trunc(A);
  1310. return Result;
  1311. };
  1312. this.Copy = function (S, Index, Size) {
  1313. if (Index<1) Index = 1;
  1314. return (Size>0) ? S.substring(Index-1,Index+Size-1) : "";
  1315. };
  1316. this.Copy$1 = function (S, Index) {
  1317. if (Index<1) Index = 1;
  1318. return S.substr(Index-1);
  1319. };
  1320. this.Delete = function (S, Index, Size) {
  1321. var h = "";
  1322. if (((Index < 1) || (Index > S.get().length)) || (Size <= 0)) return;
  1323. h = S.get();
  1324. S.set($mod.Copy(h,1,Index - 1) + $mod.Copy$1(h,Index + Size));
  1325. };
  1326. this.Pos = function (Search, InString) {
  1327. return InString.indexOf(Search)+1;
  1328. };
  1329. this.Pos$1 = function (Search, InString, StartAt) {
  1330. return InString.indexOf(Search,StartAt-1)+1;
  1331. };
  1332. this.Insert = function (Insertion, Target, Index) {
  1333. var t = "";
  1334. if (Insertion === "") return;
  1335. t = Target.get();
  1336. if (Index < 1) {
  1337. Target.set(Insertion + t)}
  1338. else if (Index > t.length) {
  1339. Target.set(t + Insertion)}
  1340. else Target.set(($mod.Copy(t,1,Index - 1) + Insertion) + $mod.Copy(t,Index,t.length));
  1341. };
  1342. this.upcase = function (c) {
  1343. return c.toUpperCase();
  1344. };
  1345. this.val = function (S, NI, Code) {
  1346. var x = 0.0;
  1347. Code.set(0);
  1348. x = Number(S);
  1349. if (isNaN(x) || (x !== $mod.Int(x))) {
  1350. Code.set(1)}
  1351. else NI.set($mod.Trunc(x));
  1352. };
  1353. this.val$1 = function (S, SI, Code) {
  1354. var X = 0.0;
  1355. Code.set(0);
  1356. X = Number(S);
  1357. if (isNaN(X) || (X !== $mod.Int(X))) {
  1358. Code.set(1)}
  1359. else if ((X < -128) || (X > 127)) {
  1360. Code.set(2)}
  1361. else SI.set($mod.Trunc(X));
  1362. };
  1363. this.val$2 = function (S, B, Code) {
  1364. var x = 0.0;
  1365. Code.set(0);
  1366. x = Number(S);
  1367. if (isNaN(x) || (x !== $mod.Int(x))) {
  1368. Code.set(1)}
  1369. else if ((x < 0) || (x > 255)) {
  1370. Code.set(2)}
  1371. else B.set($mod.Trunc(x));
  1372. };
  1373. this.val$3 = function (S, SI, Code) {
  1374. var x = 0.0;
  1375. Code.set(0);
  1376. x = Number(S);
  1377. if (isNaN(x) || (x !== $mod.Int(x))) {
  1378. Code.set(1)}
  1379. else if ((x < -32768) || (x > 32767)) {
  1380. Code.set(2)}
  1381. else SI.set($mod.Trunc(x));
  1382. };
  1383. this.val$4 = function (S, W, Code) {
  1384. var x = 0.0;
  1385. Code.set(0);
  1386. x = Number(S);
  1387. if (isNaN(x)) {
  1388. Code.set(1)}
  1389. else if ((x < 0) || (x > 65535)) {
  1390. Code.set(2)}
  1391. else W.set($mod.Trunc(x));
  1392. };
  1393. this.val$5 = function (S, I, Code) {
  1394. var x = 0.0;
  1395. Code.set(0);
  1396. x = Number(S);
  1397. if (isNaN(x)) {
  1398. Code.set(1)}
  1399. else if (x > 2147483647) {
  1400. Code.set(2)}
  1401. else I.set($mod.Trunc(x));
  1402. };
  1403. this.val$6 = function (S, C, Code) {
  1404. var x = 0.0;
  1405. Code.set(0);
  1406. x = Number(S);
  1407. if (isNaN(x) || (x !== $mod.Int(x))) {
  1408. Code.set(1)}
  1409. else if ((x < 0) || (x > 4294967295)) {
  1410. Code.set(2)}
  1411. else C.set($mod.Trunc(x));
  1412. };
  1413. this.val$7 = function (S, d, Code) {
  1414. var x = 0.0;
  1415. x = Number(S);
  1416. if (isNaN(x)) {
  1417. Code.set(1)}
  1418. else {
  1419. Code.set(0);
  1420. d.set(x);
  1421. };
  1422. };
  1423. this.StringOfChar = function (c, l) {
  1424. var Result = "";
  1425. var i = 0;
  1426. Result = "";
  1427. for (var $l1 = 1, $end2 = l; $l1 <= $end2; $l1++) {
  1428. i = $l1;
  1429. Result = Result + c;
  1430. };
  1431. return Result;
  1432. };
  1433. this.Write = function () {
  1434. var i = 0;
  1435. for (var $l1 = 0, $end2 = rtl.length(arguments) - 1; $l1 <= $end2; $l1++) {
  1436. i = $l1;
  1437. if ($impl.WriteCallBack != null) {
  1438. $impl.WriteCallBack(arguments[i],false)}
  1439. else $impl.WriteBuf = $impl.WriteBuf + ("" + arguments[i]);
  1440. };
  1441. };
  1442. this.Writeln = function () {
  1443. var i = 0;
  1444. var l = 0;
  1445. var s = "";
  1446. l = rtl.length(arguments) - 1;
  1447. if ($impl.WriteCallBack != null) {
  1448. for (var $l1 = 0, $end2 = l; $l1 <= $end2; $l1++) {
  1449. i = $l1;
  1450. $impl.WriteCallBack(arguments[i],i === l);
  1451. };
  1452. } else {
  1453. s = $impl.WriteBuf;
  1454. for (var $l3 = 0, $end4 = l; $l3 <= $end4; $l3++) {
  1455. i = $l3;
  1456. s = s + ("" + arguments[i]);
  1457. };
  1458. console.log(s);
  1459. $impl.WriteBuf = "";
  1460. };
  1461. };
  1462. this.SetWriteCallBack = function (H) {
  1463. var Result = null;
  1464. Result = $impl.WriteCallBack;
  1465. $impl.WriteCallBack = H;
  1466. return Result;
  1467. };
  1468. this.Assigned = function (V) {
  1469. return (V!=undefined) && (V!=null) && (!rtl.isArray(V) || (V.length > 0));
  1470. };
  1471. this.StrictEqual = function (A, B) {
  1472. return A === B;
  1473. };
  1474. this.StrictInequal = function (A, B) {
  1475. return A !== B;
  1476. };
  1477. $mod.$init = function () {
  1478. rtl.exitcode = 0;
  1479. };
  1480. },null,function () {
  1481. "use strict";
  1482. var $mod = this;
  1483. var $impl = $mod.$impl;
  1484. $impl.SameText = function (s1, s2) {
  1485. return s1.toLowerCase() == s2.toLowerCase();
  1486. };
  1487. $impl.WriteBuf = "";
  1488. $impl.WriteCallBack = null;
  1489. });
  1490. rtl.module("Types",["System"],function () {
  1491. "use strict";
  1492. var $mod = this;
  1493. this.TDirection = {"0": "FromBeginning", FromBeginning: 0, "1": "FromEnd", FromEnd: 1};
  1494. this.TDuplicates = {"0": "dupIgnore", dupIgnore: 0, "1": "dupAccept", dupAccept: 1, "2": "dupError", dupError: 2};
  1495. this.TSize = function (s) {
  1496. if (s) {
  1497. this.cx = s.cx;
  1498. this.cy = s.cy;
  1499. } else {
  1500. this.cx = 0;
  1501. this.cy = 0;
  1502. };
  1503. this.$equal = function (b) {
  1504. return (this.cx === b.cx) && (this.cy === b.cy);
  1505. };
  1506. };
  1507. this.TPoint = function (s) {
  1508. if (s) {
  1509. this.x = s.x;
  1510. this.y = s.y;
  1511. } else {
  1512. this.x = 0;
  1513. this.y = 0;
  1514. };
  1515. this.$equal = function (b) {
  1516. return (this.x === b.x) && (this.y === b.y);
  1517. };
  1518. };
  1519. this.TRect = function (s) {
  1520. if (s) {
  1521. this.Left = s.Left;
  1522. this.Top = s.Top;
  1523. this.Right = s.Right;
  1524. this.Bottom = s.Bottom;
  1525. } else {
  1526. this.Left = 0;
  1527. this.Top = 0;
  1528. this.Right = 0;
  1529. this.Bottom = 0;
  1530. };
  1531. this.$equal = function (b) {
  1532. return (this.Left === b.Left) && ((this.Top === b.Top) && ((this.Right === b.Right) && (this.Bottom === b.Bottom)));
  1533. };
  1534. };
  1535. this.EqualRect = function (r1, r2) {
  1536. var Result = false;
  1537. Result = (((r1.Left === r2.Left) && (r1.Right === r2.Right)) && (r1.Top === r2.Top)) && (r1.Bottom === r2.Bottom);
  1538. return Result;
  1539. };
  1540. this.Rect = function (Left, Top, Right, Bottom) {
  1541. var Result = new $mod.TRect();
  1542. Result.Left = Left;
  1543. Result.Top = Top;
  1544. Result.Right = Right;
  1545. Result.Bottom = Bottom;
  1546. return Result;
  1547. };
  1548. this.Bounds = function (ALeft, ATop, AWidth, AHeight) {
  1549. var Result = new $mod.TRect();
  1550. Result.Left = ALeft;
  1551. Result.Top = ATop;
  1552. Result.Right = ALeft + AWidth;
  1553. Result.Bottom = ATop + AHeight;
  1554. return Result;
  1555. };
  1556. this.Point = function (x, y) {
  1557. var Result = new $mod.TPoint();
  1558. Result.x = x;
  1559. Result.y = y;
  1560. return Result;
  1561. };
  1562. this.PtInRect = function (aRect, p) {
  1563. var Result = false;
  1564. Result = (((p.y >= aRect.Top) && (p.y < aRect.Bottom)) && (p.x >= aRect.Left)) && (p.x < aRect.Right);
  1565. return Result;
  1566. };
  1567. this.IntersectRect = function (aRect, R1, R2) {
  1568. var Result = false;
  1569. var lRect = new $mod.TRect();
  1570. lRect = new $mod.TRect(R1);
  1571. if (R2.Left > R1.Left) lRect.Left = R2.Left;
  1572. if (R2.Top > R1.Top) lRect.Top = R2.Top;
  1573. if (R2.Right < R1.Right) lRect.Right = R2.Right;
  1574. if (R2.Bottom < R1.Bottom) lRect.Bottom = R2.Bottom;
  1575. if ($mod.IsRectEmpty(lRect)) {
  1576. aRect.set(new $mod.TRect($mod.Rect(0,0,0,0)));
  1577. Result = false;
  1578. } else {
  1579. Result = true;
  1580. aRect.set(new $mod.TRect(lRect));
  1581. };
  1582. return Result;
  1583. };
  1584. this.UnionRect = function (aRect, R1, R2) {
  1585. var Result = false;
  1586. var lRect = new $mod.TRect();
  1587. lRect = new $mod.TRect(R1);
  1588. if (R2.Left < R1.Left) lRect.Left = R2.Left;
  1589. if (R2.Top < R1.Top) lRect.Top = R2.Top;
  1590. if (R2.Right > R1.Right) lRect.Right = R2.Right;
  1591. if (R2.Bottom > R1.Bottom) lRect.Bottom = R2.Bottom;
  1592. if ($mod.IsRectEmpty(lRect)) {
  1593. aRect.set(new $mod.TRect($mod.Rect(0,0,0,0)));
  1594. Result = false;
  1595. } else {
  1596. aRect.set(new $mod.TRect(lRect));
  1597. Result = true;
  1598. };
  1599. return Result;
  1600. };
  1601. this.IsRectEmpty = function (aRect) {
  1602. var Result = false;
  1603. Result = (aRect.Right <= aRect.Left) || (aRect.Bottom <= aRect.Top);
  1604. return Result;
  1605. };
  1606. this.OffsetRect = function (aRect, DX, DY) {
  1607. var Result = false;
  1608. var $with1 = aRect.get();
  1609. $with1.Left += DX;
  1610. $with1.Top += DY;
  1611. $with1.Right += DX;
  1612. $with1.Bottom += DY;
  1613. Result = true;
  1614. return Result;
  1615. };
  1616. this.CenterPoint = function (aRect) {
  1617. var Result = new $mod.TPoint();
  1618. function Avg(a, b) {
  1619. var Result = 0;
  1620. if (a < b) {
  1621. Result = a + ((b - a) >>> 1)}
  1622. else Result = b + ((a - b) >>> 1);
  1623. return Result;
  1624. };
  1625. Result.x = Avg(aRect.Left,aRect.Right);
  1626. Result.y = Avg(aRect.Top,aRect.Bottom);
  1627. return Result;
  1628. };
  1629. this.InflateRect = function (aRect, dx, dy) {
  1630. var Result = false;
  1631. var $with1 = aRect.get();
  1632. $with1.Left -= dx;
  1633. $with1.Top -= dy;
  1634. $with1.Right += dx;
  1635. $with1.Bottom += dy;
  1636. Result = true;
  1637. return Result;
  1638. };
  1639. this.Size = function (AWidth, AHeight) {
  1640. var Result = new $mod.TSize();
  1641. Result.cx = AWidth;
  1642. Result.cy = AHeight;
  1643. return Result;
  1644. };
  1645. this.Size$1 = function (aRect) {
  1646. var Result = new $mod.TSize();
  1647. Result.cx = aRect.Right - aRect.Left;
  1648. Result.cy = aRect.Bottom - aRect.Top;
  1649. return Result;
  1650. };
  1651. });
  1652. rtl.module("JS",["System","Types"],function () {
  1653. "use strict";
  1654. var $mod = this;
  1655. rtl.createClass($mod,"EJS",pas.System.TObject,function () {
  1656. this.$init = function () {
  1657. pas.System.TObject.$init.call(this);
  1658. this.FMessage = "";
  1659. };
  1660. this.Create$1 = function (Msg) {
  1661. this.FMessage = Msg;
  1662. };
  1663. });
  1664. this.TLocaleCompareOptions = function (s) {
  1665. if (s) {
  1666. this.localematched = s.localematched;
  1667. this.usage = s.usage;
  1668. this.sensitivity = s.sensitivity;
  1669. this.ignorePunctuation = s.ignorePunctuation;
  1670. this.numeric = s.numeric;
  1671. this.caseFirst = s.caseFirst;
  1672. } else {
  1673. this.localematched = "";
  1674. this.usage = "";
  1675. this.sensitivity = "";
  1676. this.ignorePunctuation = false;
  1677. this.numeric = false;
  1678. this.caseFirst = "";
  1679. };
  1680. this.$equal = function (b) {
  1681. return (this.localematched === b.localematched) && ((this.usage === b.usage) && ((this.sensitivity === b.sensitivity) && ((this.ignorePunctuation === b.ignorePunctuation) && ((this.numeric === b.numeric) && (this.caseFirst === b.caseFirst)))));
  1682. };
  1683. };
  1684. this.New = function (aElements) {
  1685. var Result = null;
  1686. var L = 0;
  1687. var I = 0;
  1688. var S = "";
  1689. L = rtl.length(aElements);
  1690. if ((L % 2) === 1) throw $mod.EJS.$create("Create$1",["Number of arguments must be even"]);
  1691. I = 0;
  1692. while (I < L) {
  1693. if (!rtl.isString(aElements[I])) {
  1694. S = String(I);
  1695. throw $mod.EJS.$create("Create$1",[("Argument " + S) + " must be a string."]);
  1696. };
  1697. I += 2;
  1698. };
  1699. I = 0;
  1700. Result = new Object();
  1701. while (I < L) {
  1702. S = "" + aElements[I];
  1703. Result[S] = aElements[I + 1];
  1704. I += 2;
  1705. };
  1706. return Result;
  1707. };
  1708. this.hasValue = function (v) {
  1709. if(v){ return true; } else { return false; };
  1710. };
  1711. this.isBoolean = function (v) {
  1712. return typeof(v) == 'boolean';
  1713. };
  1714. this.isCallback = function (v) {
  1715. return rtl.isObject(v) && rtl.isObject(v.scope) && (rtl.isString(v.fn) || rtl.isFunction(v.fn));
  1716. };
  1717. this.isChar = function (v) {
  1718. return (typeof(v)!="string") && (v.length==1);
  1719. };
  1720. this.isClass = function (v) {
  1721. return (typeof(v)=="object") && (v!=null) && (v.$class == v);
  1722. };
  1723. this.isClassInstance = function (v) {
  1724. return (typeof(v)=="object") && (v!=null) && (v.$class == Object.getPrototypeOf(v));
  1725. };
  1726. this.isInteger = function (v) {
  1727. return Math.floor(v)===v;
  1728. };
  1729. this.isNull = function (v) {
  1730. return v === null;
  1731. };
  1732. this.isRecord = function (v) {
  1733. return (typeof(v)=="function") && (typeof(v.$create) == "function");
  1734. };
  1735. this.isUndefined = function (v) {
  1736. return v == undefined;
  1737. };
  1738. this.isDefined = function (v) {
  1739. return !(v == undefined);
  1740. };
  1741. this.isUTF16Char = function (v) {
  1742. if (typeof(v)!="string") return false;
  1743. if ((v.length==0) || (v.length>2)) return false;
  1744. var code = v.charCodeAt(0);
  1745. if (code < 0xD800){
  1746. if (v.length == 1) return true;
  1747. } else if (code <= 0xDBFF){
  1748. if (v.length==2){
  1749. code = v.charCodeAt(1);
  1750. if (code >= 0xDC00 && code <= 0xDFFF) return true;
  1751. };
  1752. };
  1753. return false;
  1754. };
  1755. this.jsInstanceOf = function (aFunction, aFunctionWithPrototype) {
  1756. return aFunction instanceof aFunctionWithPrototype;
  1757. };
  1758. this.toNumber = function (v) {
  1759. return v-0;
  1760. };
  1761. this.toInteger = function (v) {
  1762. var Result = 0;
  1763. if ($mod.isInteger(v)) {
  1764. Result = Math.floor(v)}
  1765. else Result = 0;
  1766. return Result;
  1767. };
  1768. this.toObject = function (Value) {
  1769. var Result = null;
  1770. if (rtl.isObject(Value)) {
  1771. Result = rtl.getObject(Value)}
  1772. else Result = null;
  1773. return Result;
  1774. };
  1775. this.toArray = function (Value) {
  1776. var Result = null;
  1777. if (rtl.isArray(Value)) {
  1778. Result = rtl.getObject(Value)}
  1779. else Result = null;
  1780. return Result;
  1781. };
  1782. this.toBoolean = function (Value) {
  1783. var Result = false;
  1784. if ($mod.isBoolean(Value)) {
  1785. Result = !(Value == false)}
  1786. else Result = false;
  1787. return Result;
  1788. };
  1789. this.ToString = function (Value) {
  1790. var Result = "";
  1791. if (rtl.isString(Value)) {
  1792. Result = "" + Value}
  1793. else Result = "";
  1794. return Result;
  1795. };
  1796. this.TJSValueType = {"0": "jvtNull", jvtNull: 0, "1": "jvtBoolean", jvtBoolean: 1, "2": "jvtInteger", jvtInteger: 2, "3": "jvtFloat", jvtFloat: 3, "4": "jvtString", jvtString: 4, "5": "jvtObject", jvtObject: 5, "6": "jvtArray", jvtArray: 6};
  1797. this.GetValueType = function (JS) {
  1798. var Result = 0;
  1799. var t = "";
  1800. if ($mod.isNull(JS)) {
  1801. Result = $mod.TJSValueType.jvtNull}
  1802. else {
  1803. t = typeof(JS);
  1804. if (t === "string") {
  1805. Result = $mod.TJSValueType.jvtString}
  1806. else if (t === "boolean") {
  1807. Result = $mod.TJSValueType.jvtBoolean}
  1808. else if (t === "object") {
  1809. if (rtl.isArray(JS)) {
  1810. Result = $mod.TJSValueType.jvtArray}
  1811. else Result = $mod.TJSValueType.jvtObject;
  1812. } else if (t === "number") if ($mod.isInteger(JS)) {
  1813. Result = $mod.TJSValueType.jvtInteger}
  1814. else Result = $mod.TJSValueType.jvtFloat;
  1815. };
  1816. return Result;
  1817. };
  1818. });
  1819. rtl.module("Web",["System","Types","JS"],function () {
  1820. "use strict";
  1821. var $mod = this;
  1822. this.TJSClientRect = function (s) {
  1823. if (s) {
  1824. this.left = s.left;
  1825. this.top = s.top;
  1826. this.right = s.right;
  1827. this.bottom = s.bottom;
  1828. } else {
  1829. this.left = 0.0;
  1830. this.top = 0.0;
  1831. this.right = 0.0;
  1832. this.bottom = 0.0;
  1833. };
  1834. this.$equal = function (b) {
  1835. return (this.left === b.left) && ((this.top === b.top) && ((this.right === b.right) && (this.bottom === b.bottom)));
  1836. };
  1837. };
  1838. this.TJSElementCreationOptions = function (s) {
  1839. if (s) {
  1840. this.named = s.named;
  1841. } else {
  1842. this.named = "";
  1843. };
  1844. this.$equal = function (b) {
  1845. return this.named === b.named;
  1846. };
  1847. };
  1848. this.TJSEventInit = function (s) {
  1849. if (s) {
  1850. this.bubbles = s.bubbles;
  1851. this.cancelable = s.cancelable;
  1852. this.scoped = s.scoped;
  1853. this.composed = s.composed;
  1854. } else {
  1855. this.bubbles = false;
  1856. this.cancelable = false;
  1857. this.scoped = false;
  1858. this.composed = false;
  1859. };
  1860. this.$equal = function (b) {
  1861. return (this.bubbles === b.bubbles) && ((this.cancelable === b.cancelable) && ((this.scoped === b.scoped) && (this.composed === b.composed)));
  1862. };
  1863. };
  1864. rtl.createClassExt($mod,"TJSAnimationEvent",Event,"",function () {
  1865. this.$init = function () {
  1866. };
  1867. this.$final = function () {
  1868. };
  1869. });
  1870. rtl.createClassExt($mod,"TJSLoadEvent",Event,"",function () {
  1871. this.$init = function () {
  1872. };
  1873. this.$final = function () {
  1874. };
  1875. });
  1876. rtl.createClassExt($mod,"TJsPageTransitionEvent",Event,"",function () {
  1877. this.$init = function () {
  1878. };
  1879. this.$final = function () {
  1880. };
  1881. });
  1882. rtl.createClass($mod,"TJSIDBTransactionMode",pas.System.TObject,function () {
  1883. this.readonly = "readonly";
  1884. this.readwrite = "readwrite";
  1885. this.versionchange = "versionchange";
  1886. });
  1887. this.TJSIDBIndexParameters = function (s) {
  1888. if (s) {
  1889. this.unique = s.unique;
  1890. this.multiEntry = s.multiEntry;
  1891. this.locale = s.locale;
  1892. } else {
  1893. this.unique = false;
  1894. this.multiEntry = false;
  1895. this.locale = "";
  1896. };
  1897. this.$equal = function (b) {
  1898. return (this.unique === b.unique) && ((this.multiEntry === b.multiEntry) && (this.locale === b.locale));
  1899. };
  1900. };
  1901. this.TJSCreateObjectStoreOptions = function (s) {
  1902. if (s) {
  1903. this.keyPath = s.keyPath;
  1904. this.autoIncrement = s.autoIncrement;
  1905. } else {
  1906. this.keyPath = undefined;
  1907. this.autoIncrement = false;
  1908. };
  1909. this.$equal = function (b) {
  1910. return (this.keyPath === b.keyPath) && (this.autoIncrement === b.autoIncrement);
  1911. };
  1912. };
  1913. this.TJSPositionError = function (s) {
  1914. if (s) {
  1915. this.code = s.code;
  1916. this.message = s.message;
  1917. } else {
  1918. this.code = 0;
  1919. this.message = "";
  1920. };
  1921. this.$equal = function (b) {
  1922. return (this.code === b.code) && (this.message === b.message);
  1923. };
  1924. };
  1925. this.TJSPositionOptions = function (s) {
  1926. if (s) {
  1927. this.enableHighAccuracy = s.enableHighAccuracy;
  1928. this.timeout = s.timeout;
  1929. this.maximumAge = s.maximumAge;
  1930. } else {
  1931. this.enableHighAccuracy = false;
  1932. this.timeout = 0;
  1933. this.maximumAge = 0;
  1934. };
  1935. this.$equal = function (b) {
  1936. return (this.enableHighAccuracy === b.enableHighAccuracy) && ((this.timeout === b.timeout) && (this.maximumAge === b.maximumAge));
  1937. };
  1938. };
  1939. this.TJSCoordinates = function (s) {
  1940. if (s) {
  1941. this.latitude = s.latitude;
  1942. this.longitude = s.longitude;
  1943. this.altitude = s.altitude;
  1944. this.accuracy = s.accuracy;
  1945. this.altitudeAccuracy = s.altitudeAccuracy;
  1946. this.heading = s.heading;
  1947. this.speed = s.speed;
  1948. } else {
  1949. this.latitude = 0.0;
  1950. this.longitude = 0.0;
  1951. this.altitude = 0.0;
  1952. this.accuracy = 0.0;
  1953. this.altitudeAccuracy = 0.0;
  1954. this.heading = 0.0;
  1955. this.speed = 0.0;
  1956. };
  1957. this.$equal = function (b) {
  1958. return (this.latitude === b.latitude) && ((this.longitude === b.longitude) && ((this.altitude === b.altitude) && ((this.accuracy === b.accuracy) && ((this.altitudeAccuracy === b.altitudeAccuracy) && ((this.heading === b.heading) && (this.speed === b.speed))))));
  1959. };
  1960. };
  1961. this.TJSPosition = function (s) {
  1962. if (s) {
  1963. this.coords = new $mod.TJSCoordinates(s.coords);
  1964. this.timestamp = s.timestamp;
  1965. } else {
  1966. this.coords = new $mod.TJSCoordinates();
  1967. this.timestamp = "";
  1968. };
  1969. this.$equal = function (b) {
  1970. return this.coords.$equal(b.coords) && (this.timestamp === b.timestamp);
  1971. };
  1972. };
  1973. this.TJSServiceWorkerContainerOptions = function (s) {
  1974. if (s) {
  1975. this.scope = s.scope;
  1976. } else {
  1977. this.scope = "";
  1978. };
  1979. this.$equal = function (b) {
  1980. return this.scope === b.scope;
  1981. };
  1982. };
  1983. this.TJSTextMetrics = function (s) {
  1984. if (s) {
  1985. this.width = s.width;
  1986. this.actualBoundingBoxLeft = s.actualBoundingBoxLeft;
  1987. this.actualBoundingBoxRight = s.actualBoundingBoxRight;
  1988. this.fontBoundingBoxAscent = s.fontBoundingBoxAscent;
  1989. this.fontBoundingBoxDescent = s.fontBoundingBoxDescent;
  1990. this.actualBoundingBoxAscent = s.actualBoundingBoxAscent;
  1991. this.actualBoundingBoxDescent = s.actualBoundingBoxDescent;
  1992. this.emHeightAscent = s.emHeightAscent;
  1993. this.emHeightDescent = s.emHeightDescent;
  1994. this.hangingBaseline = s.hangingBaseline;
  1995. this.alphabeticBaseline = s.alphabeticBaseline;
  1996. this.ideographicBaseline = s.ideographicBaseline;
  1997. } else {
  1998. this.width = 0.0;
  1999. this.actualBoundingBoxLeft = 0.0;
  2000. this.actualBoundingBoxRight = 0.0;
  2001. this.fontBoundingBoxAscent = 0.0;
  2002. this.fontBoundingBoxDescent = 0.0;
  2003. this.actualBoundingBoxAscent = 0.0;
  2004. this.actualBoundingBoxDescent = 0.0;
  2005. this.emHeightAscent = 0.0;
  2006. this.emHeightDescent = 0.0;
  2007. this.hangingBaseline = 0.0;
  2008. this.alphabeticBaseline = 0.0;
  2009. this.ideographicBaseline = 0.0;
  2010. };
  2011. this.$equal = function (b) {
  2012. return (this.width === b.width) && ((this.actualBoundingBoxLeft === b.actualBoundingBoxLeft) && ((this.actualBoundingBoxRight === b.actualBoundingBoxRight) && ((this.fontBoundingBoxAscent === b.fontBoundingBoxAscent) && ((this.fontBoundingBoxDescent === b.fontBoundingBoxDescent) && ((this.actualBoundingBoxAscent === b.actualBoundingBoxAscent) && ((this.actualBoundingBoxDescent === b.actualBoundingBoxDescent) && ((this.emHeightAscent === b.emHeightAscent) && ((this.emHeightDescent === b.emHeightDescent) && ((this.hangingBaseline === b.hangingBaseline) && ((this.alphabeticBaseline === b.alphabeticBaseline) && (this.ideographicBaseline === b.ideographicBaseline)))))))))));
  2013. };
  2014. };
  2015. this.TJSWheelEventInit = function (s) {
  2016. if (s) {
  2017. this.deltaX = s.deltaX;
  2018. this.deltaY = s.deltaY;
  2019. this.deltaZ = s.deltaZ;
  2020. this.deltaMode = s.deltaMode;
  2021. } else {
  2022. this.deltaX = 0.0;
  2023. this.deltaY = 0.0;
  2024. this.deltaZ = 0.0;
  2025. this.deltaMode = 0;
  2026. };
  2027. this.$equal = function (b) {
  2028. return (this.deltaX === b.deltaX) && ((this.deltaY === b.deltaY) && ((this.deltaZ === b.deltaZ) && (this.deltaMode === b.deltaMode)));
  2029. };
  2030. };
  2031. rtl.createClass($mod,"TJSKeyNames",pas.System.TObject,function () {
  2032. this.Alt = "Alt";
  2033. this.AltGraph = "AltGraph";
  2034. this.CapsLock = "CapsLock";
  2035. this.Control = "Control";
  2036. this.Fn = "Fn";
  2037. this.FnLock = "FnLock";
  2038. this.Hyper = "Hyper";
  2039. this.Meta = "Meta";
  2040. this.NumLock = "NumLock";
  2041. this.ScrollLock = "ScrollLock";
  2042. this.Shift = "Shift";
  2043. this.Super = "Super";
  2044. this.symbol = "Symbol";
  2045. this.SymbolLock = "SymbolLock";
  2046. this.Enter = "Enter";
  2047. this.Tab = "Tab";
  2048. this.Space = " ";
  2049. this.ArrowDown = "ArrowDown";
  2050. this.ArrowLeft = "ArrowLeft";
  2051. this.ArrowRight = "ArrowRight";
  2052. this.ArrowUp = "ArrowUp";
  2053. this._End = "End";
  2054. this.Home = "Home";
  2055. this.PageDown = "PageDown";
  2056. this.PageUp = "PageUp";
  2057. this.BackSpace = "Backspace";
  2058. this.Clear = "Clear";
  2059. this.Copy = "Copy";
  2060. this.CrSel = "CrSel";
  2061. this.Cut = "Cut";
  2062. this.Delete = "Delete";
  2063. this.EraseEof = "EraseEof";
  2064. this.ExSel = "ExSel";
  2065. this.Insert = "Insert";
  2066. this.Paste = "Paste";
  2067. this.Redo = "Redo";
  2068. this.Undo = "Undo";
  2069. this.Accept = "Accept";
  2070. this.Again = "Again";
  2071. this.Attn = "Attn";
  2072. this.Cancel = "Cancel";
  2073. this.ContextMenu = "Contextmenu";
  2074. this.Escape = "Escape";
  2075. this.Execute = "Execute";
  2076. this.Find = "Find";
  2077. this.Finish = "Finish";
  2078. this.Help = "Help";
  2079. this.Pause = "Pause";
  2080. this.Play = "Play";
  2081. this.Props = "Props";
  2082. this.Select = "Select";
  2083. this.ZoomIn = "ZoomIn";
  2084. this.ZoomOut = "ZoomOut";
  2085. this.BrightnessDown = "BrightnessDown";
  2086. this.BrightnessUp = "BrightnessUp";
  2087. this.Eject = "Eject";
  2088. this.LogOff = "LogOff";
  2089. this.Power = "Power";
  2090. this.PowerOff = "PowerOff";
  2091. this.PrintScreen = "PrintScreen";
  2092. this.Hibernate = "Hibernate";
  2093. this.Standby = "Standby";
  2094. this.WakeUp = "WakeUp";
  2095. this.AllCandidates = "AllCandidates";
  2096. this.Alphanumeric = "Alphanumeric";
  2097. this.CodeInput = "CodeInput";
  2098. this.Compose = "Compose";
  2099. this.Convert = "Convert";
  2100. this.Dead = "Dead";
  2101. this.FinalMode = "FinalMode";
  2102. this.GroupFirst = "GroupFirst";
  2103. this.GroupLast = "GroupLast";
  2104. this.GroupNext = "GroupNext";
  2105. this.GroupPrevious = "GroupPrevious";
  2106. this.ModelChange = "ModelChange";
  2107. this.NextCandidate = "NextCandidate";
  2108. this.NonConvert = "NonConvert";
  2109. this.PreviousCandidate = "PreviousCandidate";
  2110. this.Process = "Process";
  2111. this.SingleCandidate = "SingleCandidate";
  2112. this.HangulMode = "HangulMode";
  2113. this.HanjaMode = "HanjaMode";
  2114. this.JunjaMode = "JunjaMode";
  2115. this.Eisu = "Eisu";
  2116. this.Hankaku = "Hankaku";
  2117. this.Hiranga = "Hiranga";
  2118. this.HirangaKatakana = "HirangaKatakana";
  2119. this.KanaMode = "KanaMode";
  2120. this.Katakana = "Katakana";
  2121. this.Romaji = "Romaji";
  2122. this.Zenkaku = "Zenkaku";
  2123. this.ZenkakuHanaku = "ZenkakuHanaku";
  2124. this.F1 = "F1";
  2125. this.F2 = "F2";
  2126. this.F3 = "F3";
  2127. this.F4 = "F4";
  2128. this.F5 = "F5";
  2129. this.F6 = "F6";
  2130. this.F7 = "F7";
  2131. this.F8 = "F8";
  2132. this.F9 = "F9";
  2133. this.F10 = "F10";
  2134. this.F11 = "F11";
  2135. this.F12 = "F12";
  2136. this.F13 = "F13";
  2137. this.F14 = "F14";
  2138. this.F15 = "F15";
  2139. this.F16 = "F16";
  2140. this.F17 = "F17";
  2141. this.F18 = "F18";
  2142. this.F19 = "F19";
  2143. this.F20 = "F20";
  2144. this.Soft1 = "Soft1";
  2145. this.Soft2 = "Soft2";
  2146. this.Soft3 = "Soft3";
  2147. this.Soft4 = "Soft4";
  2148. this.Decimal = "Decimal";
  2149. this.Key11 = "Key11";
  2150. this.Key12 = "Key12";
  2151. this.Multiply = "Multiply";
  2152. this.Add = "Add";
  2153. this.NumClear = "Clear";
  2154. this.Divide = "Divide";
  2155. this.Subtract = "Subtract";
  2156. this.Separator = "Separator";
  2157. this.AppSwitch = "AppSwitch";
  2158. this.Call = "Call";
  2159. this.Camera = "Camera";
  2160. this.CameraFocus = "CameraFocus";
  2161. this.EndCall = "EndCall";
  2162. this.GoBack = "GoBack";
  2163. this.GoHome = "GoHome";
  2164. this.HeadsetHook = "HeadsetHook";
  2165. this.LastNumberRedial = "LastNumberRedial";
  2166. this.Notification = "Notification";
  2167. this.MannerMode = "MannerMode";
  2168. this.VoiceDial = "VoiceDial";
  2169. });
  2170. });
  2171. rtl.module("webgl",["System","JS","Web"],function () {
  2172. "use strict";
  2173. var $mod = this;
  2174. });
  2175. rtl.module("WebGL2",["System","webgl","JS","Web"],function () {
  2176. "use strict";
  2177. var $mod = this;
  2178. });