Mat4.js 198 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356
  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("browserconsole",["System","JS","Web"],function () {
  2172. "use strict";
  2173. var $mod = this;
  2174. var $impl = $mod.$impl;
  2175. this.DefaultMaxConsoleLines = 25;
  2176. this.DefaultConsoleStyle = (((((((((((".pasconsole { " + pas.System.sLineBreak) + "font-family: courier;") + pas.System.sLineBreak) + "font-size: 14px;") + pas.System.sLineBreak) + "background: #FFFFFF;") + pas.System.sLineBreak) + "color: #000000;") + pas.System.sLineBreak) + "display: block;") + pas.System.sLineBreak) + "}";
  2177. this.DefaultCRTConsoleStyle = (((((((((((".pasconsole { " + pas.System.sLineBreak) + "font-family: courier;") + pas.System.sLineBreak) + "font-size: 14px;") + pas.System.sLineBreak) + "background: #000;") + pas.System.sLineBreak) + "color: #14fdce;") + pas.System.sLineBreak) + "display: block;") + pas.System.sLineBreak) + "}";
  2178. this.ConsoleElementID = "";
  2179. this.ConsoleStyle = "";
  2180. this.MaxConsoleLines = 0;
  2181. this.ConsoleLinesToBrowserLog = false;
  2182. this.ResetConsole = function () {
  2183. if ($impl.LinesParent === null) return;
  2184. while ($impl.LinesParent.firstElementChild !== null) $impl.LinesParent.removeChild($impl.LinesParent.firstElementChild);
  2185. $impl.AppendLine();
  2186. };
  2187. this.InitConsole = function () {
  2188. if ($impl.ConsoleElement === null) return;
  2189. if ($impl.ConsoleElement.nodeName.toLowerCase() !== "body") {
  2190. while ($impl.ConsoleElement.firstElementChild !== null) $impl.ConsoleElement.removeChild($impl.ConsoleElement.firstElementChild);
  2191. };
  2192. $impl.StyleElement = document.createElement("style");
  2193. $impl.StyleElement.innerText = $mod.ConsoleStyle;
  2194. $impl.ConsoleElement.appendChild($impl.StyleElement);
  2195. $impl.LinesParent = document.createElement("div");
  2196. $impl.ConsoleElement.appendChild($impl.LinesParent);
  2197. };
  2198. this.HookConsole = function () {
  2199. $impl.ConsoleElement = null;
  2200. if ($mod.ConsoleElementID !== "") $impl.ConsoleElement = document.getElementById($mod.ConsoleElementID);
  2201. if ($impl.ConsoleElement === null) $impl.ConsoleElement = document.body;
  2202. if ($impl.ConsoleElement === null) return;
  2203. $mod.InitConsole();
  2204. $mod.ResetConsole();
  2205. pas.System.SetWriteCallBack($impl.WriteConsole);
  2206. };
  2207. $mod.$init = function () {
  2208. $mod.ConsoleLinesToBrowserLog = true;
  2209. $mod.ConsoleElementID = "pasjsconsole";
  2210. $mod.ConsoleStyle = $mod.DefaultConsoleStyle;
  2211. $mod.MaxConsoleLines = 25;
  2212. $mod.HookConsole();
  2213. };
  2214. },null,function () {
  2215. "use strict";
  2216. var $mod = this;
  2217. var $impl = $mod.$impl;
  2218. $impl.LastLine = null;
  2219. $impl.StyleElement = null;
  2220. $impl.LinesParent = null;
  2221. $impl.ConsoleElement = null;
  2222. $impl.AppendLine = function () {
  2223. var CurrentCount = 0;
  2224. var S = null;
  2225. CurrentCount = 0;
  2226. S = $impl.LinesParent.firstChild;
  2227. while (S != null) {
  2228. CurrentCount += 1;
  2229. S = S.nextSibling;
  2230. };
  2231. while (CurrentCount > $mod.MaxConsoleLines) {
  2232. CurrentCount -= 1;
  2233. $impl.LinesParent.removeChild($impl.LinesParent.firstChild);
  2234. };
  2235. $impl.LastLine = document.createElement("div");
  2236. $impl.LastLine.className = "pasconsole";
  2237. $impl.LinesParent.appendChild($impl.LastLine);
  2238. };
  2239. $impl.WriteConsole = function (S, NewLine) {
  2240. var CL = "";
  2241. CL = $impl.LastLine.innerText;
  2242. CL = CL + ("" + S);
  2243. $impl.LastLine.innerText = CL;
  2244. if (NewLine) {
  2245. if ($mod.ConsoleLinesToBrowserLog) window.console.log(CL);
  2246. $impl.AppendLine();
  2247. };
  2248. };
  2249. });
  2250. rtl.module("vectors",["System","browserconsole","JS"],function () {
  2251. "use strict";
  2252. var $mod = this;
  2253. rtl.createClassExt($mod,"TVec2",Array,"",function () {
  2254. this.$init = function () {
  2255. };
  2256. this.$final = function () {
  2257. };
  2258. this.SetX = function (newValue) {
  2259. this[0] = newValue;
  2260. };
  2261. this.SetY = function (newValue) {
  2262. this[1] = newValue;
  2263. };
  2264. this.GetX = function () {
  2265. var Result = 0.0;
  2266. Result = rtl.getNumber(this[0]);
  2267. return Result;
  2268. };
  2269. this.GetY = function () {
  2270. var Result = 0.0;
  2271. Result = rtl.getNumber(this[1]);
  2272. return Result;
  2273. };
  2274. this.Create = function () {
  2275. };
  2276. });
  2277. });
  2278. rtl.module("webgl",["System","JS","Web"],function () {
  2279. "use strict";
  2280. var $mod = this;
  2281. });
  2282. rtl.module("RTLConsts",["System"],function () {
  2283. "use strict";
  2284. var $mod = this;
  2285. this.SArgumentMissing = 'Missing argument in format "%s"';
  2286. this.SInvalidFormat = 'Invalid format specifier : "%s"';
  2287. this.SInvalidArgIndex = 'Invalid argument index in format: "%s"';
  2288. this.SListCapacityError = "List capacity (%s) exceeded.";
  2289. this.SListCountError = "List count (%s) out of bounds.";
  2290. this.SListIndexError = "List index (%s) out of bounds";
  2291. this.SSortedListError = "Operation not allowed on sorted list";
  2292. this.SDuplicateString = "String list does not allow duplicates";
  2293. this.SErrFindNeedsSortedList = "Cannot use find on unsorted list";
  2294. this.SInvalidName = 'Invalid component name: "%s"';
  2295. this.SInvalidBoolean = '"%s" is not a valid boolean.';
  2296. this.SDuplicateName = 'Duplicate component name: "%s"';
  2297. this.SErrInvalidDate = 'Invalid date: "%s"';
  2298. this.SErrInvalidTimeFormat = 'Invalid time format: "%s"';
  2299. this.SInvalidDateFormat = 'Invalid date format: "%s"';
  2300. this.SCantReadPropertyS = 'Cannot read property "%s"';
  2301. this.SCantWritePropertyS = 'Cannot write property "%s"';
  2302. this.SErrPropertyNotFound = 'Unknown property: "%s"';
  2303. this.SIndexedPropertyNeedsParams = 'Indexed property "%s" needs parameters';
  2304. this.SErrInvalidInteger = 'Invalid integer value: "%s"';
  2305. this.SErrInvalidFloat = 'Invalid floating-point value: "%s"';
  2306. this.SInvalidDateTime = "Invalid date-time value: %s";
  2307. this.SInvalidCurrency = "Invalid currency value: %s";
  2308. this.SErrInvalidDayOfWeek = "%d is not a valid day of the week";
  2309. this.SErrInvalidTimeStamp = 'Invalid date\/timestamp : "%s"';
  2310. this.SErrInvalidDateWeek = "%d %d %d is not a valid dateweek";
  2311. this.SErrInvalidDayOfYear = "Year %d does not have a day number %d";
  2312. this.SErrInvalidDateMonthWeek = "Year %d, month %d, Week %d and day %d is not a valid date.";
  2313. this.SErrInvalidDayOfWeekInMonth = "Year %d Month %d NDow %d DOW %d is not a valid date";
  2314. this.SInvalidJulianDate = "%f Julian cannot be represented as a DateTime";
  2315. this.SErrInvalidHourMinuteSecMsec = "%d:%d:%d.%d is not a valid time specification";
  2316. this.SInvalidGUID = '"%s" is not a valid GUID value';
  2317. });
  2318. rtl.module("SysUtils",["System","RTLConsts","JS"],function () {
  2319. "use strict";
  2320. var $mod = this;
  2321. var $impl = $mod.$impl;
  2322. this.FreeAndNil = function (Obj) {
  2323. var o = null;
  2324. o = Obj.get();
  2325. if (o === null) return;
  2326. Obj.set(null);
  2327. o.$destroy("Destroy");
  2328. };
  2329. this.TFloatRec = function (s) {
  2330. if (s) {
  2331. this.Exponent = s.Exponent;
  2332. this.Negative = s.Negative;
  2333. this.Digits = s.Digits;
  2334. } else {
  2335. this.Exponent = 0;
  2336. this.Negative = false;
  2337. this.Digits = [];
  2338. };
  2339. this.$equal = function (b) {
  2340. return (this.Exponent === b.Exponent) && ((this.Negative === b.Negative) && (this.Digits === b.Digits));
  2341. };
  2342. };
  2343. this.TEndian = {"0": "Little", Little: 0, "1": "Big", Big: 1};
  2344. rtl.createClass($mod,"Exception",pas.System.TObject,function () {
  2345. this.$init = function () {
  2346. pas.System.TObject.$init.call(this);
  2347. this.fMessage = "";
  2348. this.fHelpContext = 0;
  2349. };
  2350. this.Create$1 = function (Msg) {
  2351. this.fMessage = Msg;
  2352. };
  2353. this.CreateFmt = function (Msg, Args) {
  2354. this.fMessage = $mod.Format(Msg,Args);
  2355. };
  2356. this.CreateHelp = function (Msg, AHelpContext) {
  2357. this.fMessage = Msg;
  2358. this.fHelpContext = AHelpContext;
  2359. };
  2360. this.CreateFmtHelp = function (Msg, Args, AHelpContext) {
  2361. this.fMessage = $mod.Format(Msg,Args);
  2362. this.fHelpContext = AHelpContext;
  2363. };
  2364. this.ToString = function () {
  2365. var Result = "";
  2366. Result = (this.$classname + ": ") + this.fMessage;
  2367. return Result;
  2368. };
  2369. });
  2370. rtl.createClass($mod,"EExternal",$mod.Exception,function () {
  2371. });
  2372. rtl.createClass($mod,"EMathError",$mod.EExternal,function () {
  2373. });
  2374. rtl.createClass($mod,"EInvalidOp",$mod.EMathError,function () {
  2375. });
  2376. rtl.createClass($mod,"EZeroDivide",$mod.EMathError,function () {
  2377. });
  2378. rtl.createClass($mod,"EOverflow",$mod.EMathError,function () {
  2379. });
  2380. rtl.createClass($mod,"EUnderflow",$mod.EMathError,function () {
  2381. });
  2382. rtl.createClass($mod,"EAbort",$mod.Exception,function () {
  2383. });
  2384. rtl.createClass($mod,"EInvalidCast",$mod.Exception,function () {
  2385. });
  2386. rtl.createClass($mod,"EAssertionFailed",$mod.Exception,function () {
  2387. });
  2388. rtl.createClass($mod,"EObjectCheck",$mod.Exception,function () {
  2389. });
  2390. rtl.createClass($mod,"EConvertError",$mod.Exception,function () {
  2391. });
  2392. rtl.createClass($mod,"EFormatError",$mod.Exception,function () {
  2393. });
  2394. rtl.createClass($mod,"EIntError",$mod.EExternal,function () {
  2395. });
  2396. rtl.createClass($mod,"EDivByZero",$mod.EIntError,function () {
  2397. });
  2398. rtl.createClass($mod,"ERangeError",$mod.EIntError,function () {
  2399. });
  2400. rtl.createClass($mod,"EIntOverflow",$mod.EIntError,function () {
  2401. });
  2402. rtl.createClass($mod,"EInOutError",$mod.Exception,function () {
  2403. this.$init = function () {
  2404. $mod.Exception.$init.call(this);
  2405. this.ErrorCode = 0;
  2406. };
  2407. });
  2408. rtl.createClass($mod,"EHeapMemoryError",$mod.Exception,function () {
  2409. });
  2410. rtl.createClass($mod,"EExternalException",$mod.EExternal,function () {
  2411. });
  2412. rtl.createClass($mod,"EInvalidPointer",$mod.EHeapMemoryError,function () {
  2413. });
  2414. rtl.createClass($mod,"EOutOfMemory",$mod.EHeapMemoryError,function () {
  2415. });
  2416. rtl.createClass($mod,"EVariantError",$mod.Exception,function () {
  2417. this.$init = function () {
  2418. $mod.Exception.$init.call(this);
  2419. this.ErrCode = 0;
  2420. };
  2421. this.CreateCode = function (Code) {
  2422. this.ErrCode = Code;
  2423. };
  2424. });
  2425. rtl.createClass($mod,"EAccessViolation",$mod.EExternal,function () {
  2426. });
  2427. rtl.createClass($mod,"EBusError",$mod.EAccessViolation,function () {
  2428. });
  2429. rtl.createClass($mod,"EPrivilege",$mod.EExternal,function () {
  2430. });
  2431. rtl.createClass($mod,"EStackOverflow",$mod.EExternal,function () {
  2432. });
  2433. rtl.createClass($mod,"EControlC",$mod.EExternal,function () {
  2434. });
  2435. rtl.createClass($mod,"EAbstractError",$mod.Exception,function () {
  2436. });
  2437. rtl.createClass($mod,"EPropReadOnly",$mod.Exception,function () {
  2438. });
  2439. rtl.createClass($mod,"EPropWriteOnly",$mod.Exception,function () {
  2440. });
  2441. rtl.createClass($mod,"EIntfCastError",$mod.Exception,function () {
  2442. });
  2443. rtl.createClass($mod,"EInvalidContainer",$mod.Exception,function () {
  2444. });
  2445. rtl.createClass($mod,"EInvalidInsert",$mod.Exception,function () {
  2446. });
  2447. rtl.createClass($mod,"EPackageError",$mod.Exception,function () {
  2448. });
  2449. rtl.createClass($mod,"EOSError",$mod.Exception,function () {
  2450. this.$init = function () {
  2451. $mod.Exception.$init.call(this);
  2452. this.ErrorCode = 0;
  2453. };
  2454. });
  2455. rtl.createClass($mod,"ESafecallException",$mod.Exception,function () {
  2456. });
  2457. rtl.createClass($mod,"ENoThreadSupport",$mod.Exception,function () {
  2458. });
  2459. rtl.createClass($mod,"ENoWideStringSupport",$mod.Exception,function () {
  2460. });
  2461. rtl.createClass($mod,"ENotImplemented",$mod.Exception,function () {
  2462. });
  2463. rtl.createClass($mod,"EArgumentException",$mod.Exception,function () {
  2464. });
  2465. rtl.createClass($mod,"EArgumentOutOfRangeException",$mod.EArgumentException,function () {
  2466. });
  2467. rtl.createClass($mod,"EArgumentNilException",$mod.EArgumentException,function () {
  2468. });
  2469. rtl.createClass($mod,"EPathTooLongException",$mod.Exception,function () {
  2470. });
  2471. rtl.createClass($mod,"ENotSupportedException",$mod.Exception,function () {
  2472. });
  2473. rtl.createClass($mod,"EDirectoryNotFoundException",$mod.Exception,function () {
  2474. });
  2475. rtl.createClass($mod,"EFileNotFoundException",$mod.Exception,function () {
  2476. });
  2477. rtl.createClass($mod,"EPathNotFoundException",$mod.Exception,function () {
  2478. });
  2479. rtl.createClass($mod,"ENoConstructException",$mod.Exception,function () {
  2480. });
  2481. this.EmptyStr = "";
  2482. this.EmptyWideStr = "";
  2483. this.HexDisplayPrefix = "$";
  2484. this.LeadBytes = {};
  2485. this.CharInSet = function (Ch, CSet) {
  2486. var Result = false;
  2487. var I = 0;
  2488. Result = false;
  2489. I = rtl.length(CSet) - 1;
  2490. while (!Result && (I >= 0)) {
  2491. Result = Ch === CSet[I];
  2492. I -= 1;
  2493. };
  2494. return Result;
  2495. };
  2496. this.LeftStr = function (S, Count) {
  2497. return (Count>0) ? S.substr(0,Count) : "";
  2498. };
  2499. this.RightStr = function (S, Count) {
  2500. var l = S.length;
  2501. return (Count<1) ? "" : ( Count>=l ? S : S.substr(l-Count));
  2502. };
  2503. this.Trim = function (S) {
  2504. return S.trim();
  2505. };
  2506. this.TrimLeft = function (S) {
  2507. return S.replace(/^[\s\uFEFF\xA0\x00-\x1f]+/,'');
  2508. };
  2509. this.TrimRight = function (S) {
  2510. return S.replace(/[\s\uFEFF\xA0\x00-\x1f]+$/,'');
  2511. };
  2512. this.UpperCase = function (s) {
  2513. return s.toUpperCase();
  2514. };
  2515. this.LowerCase = function (s) {
  2516. return s.toLowerCase();
  2517. };
  2518. this.CompareStr = function (s1, s2) {
  2519. var l1 = s1.length;
  2520. var l2 = s2.length;
  2521. if (l1<=l2){
  2522. var s = s2.substr(0,l1);
  2523. if (s1<s){ return -1;
  2524. } else if (s1>s){ return 1;
  2525. } else { return l1<l2 ? -1 : 0; };
  2526. } else {
  2527. var s = s1.substr(0,l2);
  2528. if (s<s2){ return -1;
  2529. } else { return 1; };
  2530. };
  2531. };
  2532. this.SameStr = function (s1, s2) {
  2533. return s1 == s2;
  2534. };
  2535. this.CompareText = function (s1, s2) {
  2536. var l1 = s1.toLowerCase();
  2537. var l2 = s2.toLowerCase();
  2538. if (l1>l2){ return 1;
  2539. } else if (l1<l2){ return -1;
  2540. } else { return 0; };
  2541. };
  2542. this.SameText = function (s1, s2) {
  2543. return s1.toLowerCase() == s2.toLowerCase();
  2544. };
  2545. this.AnsiCompareText = function (s1, s2) {
  2546. return s1.localeCompare(s2);
  2547. };
  2548. this.AnsiSameText = function (s1, s2) {
  2549. return s1.localeCompare(s2) == 0;
  2550. };
  2551. this.AnsiCompareStr = function (s1, s2) {
  2552. var Result = 0;
  2553. Result = $mod.CompareText(s1,s2);
  2554. return Result;
  2555. };
  2556. this.AppendStr = function (Dest, S) {
  2557. Dest.set(Dest.get() + S);
  2558. };
  2559. this.Format = function (Fmt, Args) {
  2560. var Result = "";
  2561. var ChPos = 0;
  2562. var OldPos = 0;
  2563. var ArgPos = 0;
  2564. var DoArg = 0;
  2565. var Len = 0;
  2566. var Hs = "";
  2567. var ToAdd = "";
  2568. var Index = 0;
  2569. var Width = 0;
  2570. var Prec = 0;
  2571. var Left = false;
  2572. var Fchar = "";
  2573. var vq = 0;
  2574. function ReadFormat() {
  2575. var Result = "";
  2576. var Value = 0;
  2577. function ReadInteger() {
  2578. var Code = 0;
  2579. var ArgN = 0;
  2580. if (Value !== -1) return;
  2581. OldPos = ChPos;
  2582. while (((ChPos <= Len) && (Fmt.charAt(ChPos - 1) <= "9")) && (Fmt.charAt(ChPos - 1) >= "0")) ChPos += 1;
  2583. if (ChPos > Len) $impl.DoFormatError(1,Fmt);
  2584. if (Fmt.charAt(ChPos - 1) === "*") {
  2585. if (Index === -1) {
  2586. ArgN = ArgPos}
  2587. else {
  2588. ArgN = Index;
  2589. Index += 1;
  2590. };
  2591. if ((ChPos > OldPos) || (ArgN > (rtl.length(Args) - 1))) $impl.DoFormatError(1,Fmt);
  2592. ArgPos = ArgN + 1;
  2593. if (rtl.isNumber(Args[ArgN]) && pas.JS.isInteger(Args[ArgN])) {
  2594. Value = Math.floor(Args[ArgN])}
  2595. else $impl.DoFormatError(1,Fmt);
  2596. ChPos += 1;
  2597. } else {
  2598. if (OldPos < ChPos) {
  2599. pas.System.val(pas.System.Copy(Fmt,OldPos,ChPos - OldPos),{get: function () {
  2600. return Value;
  2601. }, set: function (v) {
  2602. Value = v;
  2603. }},{get: function () {
  2604. return Code;
  2605. }, set: function (v) {
  2606. Code = v;
  2607. }});
  2608. if (Code > 0) $impl.DoFormatError(1,Fmt);
  2609. } else Value = -1;
  2610. };
  2611. };
  2612. function ReadIndex() {
  2613. if (Fmt.charAt(ChPos - 1) !== ":") {
  2614. ReadInteger()}
  2615. else Value = 0;
  2616. if (Fmt.charAt(ChPos - 1) === ":") {
  2617. if (Value === -1) $impl.DoFormatError(2,Fmt);
  2618. Index = Value;
  2619. Value = -1;
  2620. ChPos += 1;
  2621. };
  2622. };
  2623. function ReadLeft() {
  2624. if (Fmt.charAt(ChPos - 1) === "-") {
  2625. Left = true;
  2626. ChPos += 1;
  2627. } else Left = false;
  2628. };
  2629. function ReadWidth() {
  2630. ReadInteger();
  2631. if (Value !== -1) {
  2632. Width = Value;
  2633. Value = -1;
  2634. };
  2635. };
  2636. function ReadPrec() {
  2637. if (Fmt.charAt(ChPos - 1) === ".") {
  2638. ChPos += 1;
  2639. ReadInteger();
  2640. if (Value === -1) Value = 0;
  2641. Prec = Value;
  2642. };
  2643. };
  2644. Index = -1;
  2645. Width = -1;
  2646. Prec = -1;
  2647. Value = -1;
  2648. ChPos += 1;
  2649. if (Fmt.charAt(ChPos - 1) === "%") {
  2650. Result = "%";
  2651. return Result;
  2652. };
  2653. ReadIndex();
  2654. ReadLeft();
  2655. ReadWidth();
  2656. ReadPrec();
  2657. Result = pas.System.upcase(Fmt.charAt(ChPos - 1));
  2658. return Result;
  2659. };
  2660. function Checkarg(AT, err) {
  2661. var Result = false;
  2662. Result = false;
  2663. if (Index === -1) {
  2664. DoArg = ArgPos}
  2665. else DoArg = Index;
  2666. ArgPos = DoArg + 1;
  2667. if ((DoArg > (rtl.length(Args) - 1)) || (pas.JS.GetValueType(Args[DoArg]) !== AT)) {
  2668. if (err) $impl.DoFormatError(3,Fmt);
  2669. ArgPos -= 1;
  2670. return Result;
  2671. };
  2672. Result = true;
  2673. return Result;
  2674. };
  2675. Result = "";
  2676. Len = Fmt.length;
  2677. ChPos = 1;
  2678. OldPos = 1;
  2679. ArgPos = 0;
  2680. while (ChPos <= Len) {
  2681. while ((ChPos <= Len) && (Fmt.charAt(ChPos - 1) !== "%")) ChPos += 1;
  2682. if (ChPos > OldPos) Result = Result + pas.System.Copy(Fmt,OldPos,ChPos - OldPos);
  2683. if (ChPos < Len) {
  2684. Fchar = ReadFormat();
  2685. var $tmp1 = Fchar;
  2686. if ($tmp1 === "D") {
  2687. Checkarg(pas.JS.TJSValueType.jvtInteger,true);
  2688. ToAdd = $mod.IntToStr(Math.floor(Args[DoArg]));
  2689. Width = Math.abs(Width);
  2690. Index = Prec - ToAdd.length;
  2691. if (ToAdd.charAt(0) !== "-") {
  2692. ToAdd = pas.System.StringOfChar("0",Index) + ToAdd}
  2693. else pas.System.Insert(pas.System.StringOfChar("0",Index + 1),{get: function () {
  2694. return ToAdd;
  2695. }, set: function (v) {
  2696. ToAdd = v;
  2697. }},2);
  2698. } else if ($tmp1 === "U") {
  2699. Checkarg(pas.JS.TJSValueType.jvtInteger,true);
  2700. if (Math.floor(Args[DoArg]) < 0) $impl.DoFormatError(3,Fmt);
  2701. ToAdd = $mod.IntToStr(Math.floor(Args[DoArg]));
  2702. Width = Math.abs(Width);
  2703. Index = Prec - ToAdd.length;
  2704. ToAdd = pas.System.StringOfChar("0",Index) + ToAdd;
  2705. } else if ($tmp1 === "E") {
  2706. if (Checkarg(pas.JS.TJSValueType.jvtFloat,false) || Checkarg(pas.JS.TJSValueType.jvtInteger,true)) ToAdd = $mod.FloatToStrF(rtl.getNumber(Args[DoArg]),$mod.TFloatFormat.ffFixed,9999,Prec);
  2707. } else if ($tmp1 === "F") {
  2708. if (Checkarg(pas.JS.TJSValueType.jvtFloat,false) || Checkarg(pas.JS.TJSValueType.jvtInteger,true)) ToAdd = $mod.FloatToStrF(rtl.getNumber(Args[DoArg]),$mod.TFloatFormat.ffFixed,9999,Prec);
  2709. } else if ($tmp1 === "G") {
  2710. if (Checkarg(pas.JS.TJSValueType.jvtFloat,false) || Checkarg(pas.JS.TJSValueType.jvtInteger,true)) ToAdd = $mod.FloatToStrF(rtl.getNumber(Args[DoArg]),$mod.TFloatFormat.ffGeneral,Prec,3);
  2711. } else if ($tmp1 === "N") {
  2712. if (Checkarg(pas.JS.TJSValueType.jvtFloat,false) || Checkarg(pas.JS.TJSValueType.jvtInteger,true)) ToAdd = $mod.FloatToStrF(rtl.getNumber(Args[DoArg]),$mod.TFloatFormat.ffNumber,9999,Prec);
  2713. } else if ($tmp1 === "M") {
  2714. if (Checkarg(pas.JS.TJSValueType.jvtFloat,false) || Checkarg(pas.JS.TJSValueType.jvtInteger,true)) ToAdd = $mod.FloatToStrF(rtl.getNumber(Args[DoArg]),$mod.TFloatFormat.ffCurrency,9999,Prec);
  2715. } else if ($tmp1 === "S") {
  2716. Checkarg(pas.JS.TJSValueType.jvtString,true);
  2717. Hs = "" + Args[DoArg];
  2718. Index = Hs.length;
  2719. if ((Prec !== -1) && (Index > Prec)) Index = Prec;
  2720. ToAdd = pas.System.Copy(Hs,1,Index);
  2721. } else if ($tmp1 === "P") {
  2722. Checkarg(pas.JS.TJSValueType.jvtInteger,true);
  2723. ToAdd = $mod.IntToHex(Math.floor(Args[DoArg]),31);
  2724. } else if ($tmp1 === "X") {
  2725. Checkarg(pas.JS.TJSValueType.jvtInteger,true);
  2726. vq = Math.floor(Args[DoArg]);
  2727. Index = 31;
  2728. if (Prec > Index) {
  2729. ToAdd = $mod.IntToHex(vq,Index)}
  2730. else {
  2731. Index = 1;
  2732. while (((1 << (Index * 4)) <= vq) && (Index < 16)) Index += 1;
  2733. if (Index > Prec) Prec = Index;
  2734. ToAdd = $mod.IntToHex(vq,Prec);
  2735. };
  2736. } else if ($tmp1 === "%") ToAdd = "%";
  2737. if (Width !== -1) if (ToAdd.length < Width) if (!Left) {
  2738. ToAdd = pas.System.StringOfChar(" ",Width - ToAdd.length) + ToAdd}
  2739. else ToAdd = ToAdd + pas.System.StringOfChar(" ",Width - ToAdd.length);
  2740. Result = Result + ToAdd;
  2741. };
  2742. ChPos += 1;
  2743. OldPos = ChPos;
  2744. };
  2745. return Result;
  2746. };
  2747. this.LocaleCompare = function (s1, s2, locales) {
  2748. return s1.localeCompare(s2,locales) == 0;
  2749. };
  2750. this.NormalizeStr = function (S, Norm) {
  2751. return S.normalize(Norm);
  2752. };
  2753. var Alpha = rtl.createSet(null,65,90,null,97,122,95);
  2754. var AlphaNum = rtl.unionSet(Alpha,rtl.createSet(null,48,57));
  2755. var Dot = ".";
  2756. this.IsValidIdent = function (Ident, AllowDots, StrictDots) {
  2757. var Result = false;
  2758. var First = false;
  2759. var I = 0;
  2760. var Len = 0;
  2761. Len = Ident.length;
  2762. if (Len < 1) return false;
  2763. First = true;
  2764. Result = false;
  2765. I = 1;
  2766. while (I <= Len) {
  2767. if (First) {
  2768. if (!(Ident.charCodeAt(I - 1) in Alpha)) return Result;
  2769. First = false;
  2770. } else if (AllowDots && (Ident.charAt(I - 1) === Dot)) {
  2771. if (StrictDots) {
  2772. if (I >= Len) return Result;
  2773. First = true;
  2774. };
  2775. } else if (!(Ident.charCodeAt(I - 1) in AlphaNum)) return Result;
  2776. I = I + 1;
  2777. };
  2778. Result = true;
  2779. return Result;
  2780. };
  2781. this.TStringReplaceFlag = {"0": "rfReplaceAll", rfReplaceAll: 0, "1": "rfIgnoreCase", rfIgnoreCase: 1};
  2782. this.StringReplace = function (aOriginal, aSearch, aReplace, Flags) {
  2783. var Result = "";
  2784. var REFlags = "";
  2785. var REString = "";
  2786. REFlags = "";
  2787. if ($mod.TStringReplaceFlag.rfReplaceAll in Flags) REFlags = "g";
  2788. if ($mod.TStringReplaceFlag.rfIgnoreCase in Flags) REFlags = REFlags + "i";
  2789. REString = aSearch.replace(new RegExp($impl.RESpecials,"g"),"\\$1");
  2790. Result = aOriginal.replace(new RegExp(REString,REFlags),aReplace);
  2791. return Result;
  2792. };
  2793. this.QuoteString = function (aOriginal, AQuote) {
  2794. var Result = "";
  2795. var REString = "";
  2796. REString = AQuote.replace(new RegExp(aOriginal,"g"),"\\\\$1");
  2797. Result = (AQuote + aOriginal.replace(new RegExp(REString,"g"),"$1\\$1")) + AQuote;
  2798. return Result;
  2799. };
  2800. this.IsDelimiter = function (Delimiters, S, Index) {
  2801. var Result = false;
  2802. Result = false;
  2803. if ((Index > 0) && (Index <= S.length)) Result = pas.System.Pos(S.charAt(Index - 1),Delimiters) !== 0;
  2804. return Result;
  2805. };
  2806. this.AdjustLineBreaks = function (S) {
  2807. var Result = "";
  2808. Result = $mod.AdjustLineBreaks$1(S,pas.System.DefaultTextLineBreakStyle);
  2809. return Result;
  2810. };
  2811. this.AdjustLineBreaks$1 = function (S, Style) {
  2812. var Result = "";
  2813. var I = 0;
  2814. var L = 0;
  2815. var Res = "";
  2816. function Add(C) {
  2817. Res = Res + C;
  2818. };
  2819. I = 0;
  2820. L = S.length;
  2821. Result = "";
  2822. while (I <= L) {
  2823. var $tmp1 = S.charAt(I - 1);
  2824. if ($tmp1 === "\n") {
  2825. if (Style in rtl.createSet(pas.System.TTextLineBreakStyle.tlbsCRLF,pas.System.TTextLineBreakStyle.tlbsCR)) Add("\r");
  2826. if (Style === pas.System.TTextLineBreakStyle.tlbsCRLF) Add("\n");
  2827. I += 1;
  2828. } else if ($tmp1 === "\r") {
  2829. if (Style === pas.System.TTextLineBreakStyle.tlbsCRLF) Add("\r");
  2830. Add("\n");
  2831. I += 1;
  2832. if (S.charAt(I - 1) === "\n") I += 1;
  2833. } else {
  2834. Add(S.charAt(I - 1));
  2835. I += 1;
  2836. };
  2837. };
  2838. Result = Res;
  2839. return Result;
  2840. };
  2841. var Quotes = rtl.createSet(39,34);
  2842. this.WrapText = function (Line, BreakStr, BreakChars, MaxCol) {
  2843. var Result = "";
  2844. var L = "";
  2845. var C = "";
  2846. var LQ = "";
  2847. var BC = "";
  2848. var P = 0;
  2849. var BLen = 0;
  2850. var Len = 0;
  2851. var HB = false;
  2852. var IBC = false;
  2853. Result = "";
  2854. L = Line;
  2855. BLen = BreakStr.length;
  2856. if (BLen > 0) {
  2857. BC = BreakStr.charAt(0)}
  2858. else BC = "\x00";
  2859. Len = L.length;
  2860. while (Len > 0) {
  2861. P = 1;
  2862. LQ = "\x00";
  2863. HB = false;
  2864. IBC = false;
  2865. while (((P <= Len) && ((P <= MaxCol) || !IBC)) && ((LQ !== "\x00") || !HB)) {
  2866. C = L.charAt(P - 1);
  2867. if (C === LQ) {
  2868. LQ = "\x00"}
  2869. else if (C.charCodeAt() in Quotes) LQ = C;
  2870. if (LQ !== "\x00") {
  2871. P += 1}
  2872. else {
  2873. HB = (C === BC) && (BreakStr === pas.System.Copy(L,P,BLen));
  2874. if (HB) {
  2875. P += BLen}
  2876. else {
  2877. if (P >= MaxCol) IBC = $mod.CharInSet(C,BreakChars);
  2878. P += 1;
  2879. };
  2880. };
  2881. };
  2882. Result = Result + pas.System.Copy(L,1,P - 1);
  2883. pas.System.Delete({get: function () {
  2884. return L;
  2885. }, set: function (v) {
  2886. L = v;
  2887. }},1,P - 1);
  2888. Len = L.length;
  2889. if ((Len > 0) && !HB) Result = Result + BreakStr;
  2890. };
  2891. return Result;
  2892. };
  2893. this.WrapText$1 = function (Line, MaxCol) {
  2894. var Result = "";
  2895. Result = $mod.WrapText(Line,pas.System.sLineBreak,[" ","-","\t"],MaxCol);
  2896. return Result;
  2897. };
  2898. this.IntToStr = function (Value) {
  2899. var Result = "";
  2900. Result = "" + Value;
  2901. return Result;
  2902. };
  2903. this.TryStrToInt = function (S, res) {
  2904. var Result = false;
  2905. var NI = 0;
  2906. Result = $mod.TryStrToInt$1(S,{get: function () {
  2907. return NI;
  2908. }, set: function (v) {
  2909. NI = v;
  2910. }});
  2911. if (Result) res.set(NI);
  2912. return Result;
  2913. };
  2914. this.TryStrToInt$1 = function (S, res) {
  2915. var Result = false;
  2916. var Radix = 10;
  2917. var F = "";
  2918. var N = "";
  2919. var J = undefined;
  2920. N = S;
  2921. F = pas.System.Copy(N,1,1);
  2922. if (F === "$") {
  2923. Radix = 16}
  2924. else if (F === "&") {
  2925. Radix = 8}
  2926. else if (F === "%") Radix = 2;
  2927. if (Radix !== 10) pas.System.Delete({get: function () {
  2928. return N;
  2929. }, set: function (v) {
  2930. N = v;
  2931. }},1,1);
  2932. J = parseInt(N,Radix);
  2933. Result = !isNaN(J);
  2934. if (Result) res.set(Math.floor(J));
  2935. return Result;
  2936. };
  2937. this.StrToIntDef = function (S, aDef) {
  2938. var Result = 0;
  2939. var R = 0;
  2940. if ($mod.TryStrToInt$1(S,{get: function () {
  2941. return R;
  2942. }, set: function (v) {
  2943. R = v;
  2944. }})) {
  2945. Result = R}
  2946. else Result = aDef;
  2947. return Result;
  2948. };
  2949. this.StrToIntDef$1 = function (S, aDef) {
  2950. var Result = 0;
  2951. var R = 0;
  2952. if ($mod.TryStrToInt$1(S,{get: function () {
  2953. return R;
  2954. }, set: function (v) {
  2955. R = v;
  2956. }})) {
  2957. Result = R}
  2958. else Result = aDef;
  2959. return Result;
  2960. };
  2961. this.StrToInt = function (S) {
  2962. var Result = 0;
  2963. var R = 0;
  2964. if (!$mod.TryStrToInt$1(S,{get: function () {
  2965. return R;
  2966. }, set: function (v) {
  2967. R = v;
  2968. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  2969. Result = R;
  2970. return Result;
  2971. };
  2972. this.StrToNativeInt = function (S) {
  2973. var Result = 0;
  2974. if (!$mod.TryStrToInt$1(S,{get: function () {
  2975. return Result;
  2976. }, set: function (v) {
  2977. Result = v;
  2978. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  2979. return Result;
  2980. };
  2981. this.StrToInt64 = function (S) {
  2982. var Result = 0;
  2983. var N = 0;
  2984. if (!$mod.TryStrToInt$1(S,{get: function () {
  2985. return N;
  2986. }, set: function (v) {
  2987. N = v;
  2988. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  2989. Result = N;
  2990. return Result;
  2991. };
  2992. this.StrToInt64Def = function (S, ADefault) {
  2993. var Result = 0;
  2994. if ($mod.TryStrToInt64(S,{get: function () {
  2995. return Result;
  2996. }, set: function (v) {
  2997. Result = v;
  2998. }})) Result = ADefault;
  2999. return Result;
  3000. };
  3001. this.TryStrToInt64 = function (S, res) {
  3002. var Result = false;
  3003. var R = 0;
  3004. Result = $mod.TryStrToInt$1(S,{get: function () {
  3005. return R;
  3006. }, set: function (v) {
  3007. R = v;
  3008. }});
  3009. if (Result) res.set(R);
  3010. return Result;
  3011. };
  3012. this.StrToQWord = function (S) {
  3013. var Result = 0;
  3014. var N = 0;
  3015. if (!$mod.TryStrToInt$1(S,{get: function () {
  3016. return N;
  3017. }, set: function (v) {
  3018. N = v;
  3019. }}) || (N < 0)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  3020. Result = N;
  3021. return Result;
  3022. };
  3023. this.StrToQWordDef = function (S, ADefault) {
  3024. var Result = 0;
  3025. if (!$mod.TryStrToQWord(S,{get: function () {
  3026. return Result;
  3027. }, set: function (v) {
  3028. Result = v;
  3029. }})) Result = ADefault;
  3030. return Result;
  3031. };
  3032. this.TryStrToQWord = function (S, res) {
  3033. var Result = false;
  3034. var R = 0;
  3035. Result = $mod.TryStrToInt$1(S,{get: function () {
  3036. return R;
  3037. }, set: function (v) {
  3038. R = v;
  3039. }}) && (R >= 0);
  3040. if (Result) res.set(R);
  3041. return Result;
  3042. };
  3043. this.StrToUInt64 = function (S) {
  3044. var Result = 0;
  3045. var N = 0;
  3046. if (!$mod.TryStrToInt$1(S,{get: function () {
  3047. return N;
  3048. }, set: function (v) {
  3049. N = v;
  3050. }}) || (N < 0)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  3051. Result = N;
  3052. return Result;
  3053. };
  3054. this.StrToUInt64Def = function (S, ADefault) {
  3055. var Result = 0;
  3056. if (!$mod.TryStrToUInt64(S,{get: function () {
  3057. return Result;
  3058. }, set: function (v) {
  3059. Result = v;
  3060. }})) Result = ADefault;
  3061. return Result;
  3062. };
  3063. this.TryStrToUInt64 = function (S, res) {
  3064. var Result = false;
  3065. var R = 0;
  3066. Result = $mod.TryStrToInt$1(S,{get: function () {
  3067. return R;
  3068. }, set: function (v) {
  3069. R = v;
  3070. }}) && (R >= 0);
  3071. if (Result) res.set(R);
  3072. return Result;
  3073. };
  3074. this.StrToDWord = function (S) {
  3075. var Result = 0;
  3076. if (!$mod.TryStrToDWord(S,{get: function () {
  3077. return Result;
  3078. }, set: function (v) {
  3079. Result = v;
  3080. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
  3081. return Result;
  3082. };
  3083. this.StrToDWordDef = function (S, ADefault) {
  3084. var Result = 0;
  3085. if (!$mod.TryStrToDWord(S,{get: function () {
  3086. return Result;
  3087. }, set: function (v) {
  3088. Result = v;
  3089. }})) Result = ADefault;
  3090. return Result;
  3091. };
  3092. this.TryStrToDWord = function (S, res) {
  3093. var Result = false;
  3094. var R = 0;
  3095. Result = ($mod.TryStrToInt$1(S,{get: function () {
  3096. return R;
  3097. }, set: function (v) {
  3098. R = v;
  3099. }}) && (R >= 0)) && (R <= 0xFFFFFFFF);
  3100. if (Result) res.set(R);
  3101. return Result;
  3102. };
  3103. var HexDigits = "0123456789ABCDEF";
  3104. this.IntToHex = function (Value, Digits) {
  3105. var Result = "";
  3106. if (Digits === 0) Digits = 1;
  3107. Result = "";
  3108. while (Value > 0) {
  3109. Result = HexDigits.charAt(((Value & 15) + 1) - 1) + Result;
  3110. Value = Value >>> 4;
  3111. };
  3112. while (Result.length < Digits) Result = "0" + Result;
  3113. return Result;
  3114. };
  3115. this.MaxCurrency = 450359962737.0495;
  3116. this.MinCurrency = -450359962737.0496;
  3117. this.TFloatFormat = {"0": "ffFixed", ffFixed: 0, "1": "ffGeneral", ffGeneral: 1, "2": "ffExponent", ffExponent: 2, "3": "ffNumber", ffNumber: 3, "4": "ffCurrency", ffCurrency: 4};
  3118. var Rounds = "234567890";
  3119. this.FloatToDecimal = function (Value, Precision, Decimals) {
  3120. var Result = new $mod.TFloatRec();
  3121. var Buffer = "";
  3122. var InfNan = "";
  3123. var error = 0;
  3124. var N = 0;
  3125. var L = 0;
  3126. var Start = 0;
  3127. var C = 0;
  3128. var GotNonZeroBeforeDot = false;
  3129. var BeforeDot = false;
  3130. if (Value === 0) ;
  3131. Result.Digits = rtl.arraySetLength(Result.Digits,"",19);
  3132. Buffer=Value.toPrecision(21); // Double precision;
  3133. N = 1;
  3134. L = Buffer.length;
  3135. while (Buffer.charAt(N - 1) === " ") N += 1;
  3136. Result.Negative = Buffer.charAt(N - 1) === "-";
  3137. if (Result.Negative) {
  3138. N += 1}
  3139. else if (Buffer.charAt(N - 1) === "+") N += 1;
  3140. if (L >= (N + 2)) {
  3141. InfNan = pas.System.Copy(Buffer,N,3);
  3142. if (InfNan === "Inf") {
  3143. Result.Digits[0] = "\x00";
  3144. Result.Exponent = 32767;
  3145. return Result;
  3146. };
  3147. if (InfNan === "Nan") {
  3148. Result.Digits[0] = "\x00";
  3149. Result.Exponent = -32768;
  3150. return Result;
  3151. };
  3152. };
  3153. Start = N;
  3154. Result.Exponent = 0;
  3155. BeforeDot = true;
  3156. GotNonZeroBeforeDot = false;
  3157. while ((L >= N) && (Buffer.charAt(N - 1) !== "E")) {
  3158. if (Buffer.charAt(N - 1) === ".") {
  3159. BeforeDot = false}
  3160. else {
  3161. if (BeforeDot) {
  3162. Result.Exponent += 1;
  3163. Result.Digits[N - Start] = Buffer.charAt(N - 1);
  3164. if (Buffer.charAt(N - 1) !== "0") GotNonZeroBeforeDot = true;
  3165. } else Result.Digits[(N - Start) - 1] = Buffer.charAt(N - 1);
  3166. };
  3167. N += 1;
  3168. };
  3169. N += 1;
  3170. if (N <= L) {
  3171. pas.System.val$5(pas.System.Copy(Buffer,N,(L - N) + 1),{get: function () {
  3172. return C;
  3173. }, set: function (v) {
  3174. C = v;
  3175. }},{get: function () {
  3176. return error;
  3177. }, set: function (v) {
  3178. error = v;
  3179. }});
  3180. Result.Exponent += C;
  3181. };
  3182. if (BeforeDot) {
  3183. N = (N - Start) - 1}
  3184. else N = (N - Start) - 2;
  3185. L = rtl.length(Result.Digits);
  3186. if (N < L) Result.Digits[N] = "0";
  3187. if ((Decimals + Result.Exponent) < Precision) {
  3188. N = Decimals + Result.Exponent}
  3189. else N = Precision;
  3190. if (N >= L) N = L - 1;
  3191. if (N === 0) {
  3192. if (Result.Digits[0] >= "5") {
  3193. Result.Digits[0] = "1";
  3194. Result.Digits[1] = "\x00";
  3195. Result.Exponent += 1;
  3196. } else Result.Digits[0] = "\x00";
  3197. } else if (N > 0) {
  3198. if (Result.Digits[N] >= "5") {
  3199. do {
  3200. Result.Digits[N] = "\x00";
  3201. N -= 1;
  3202. Result.Digits[N] = Rounds.charAt($mod.StrToInt(Result.Digits[N]) - 1);
  3203. } while (!((N === 0) || (Result.Digits[N] < ":")));
  3204. if (Result.Digits[0] === ":") {
  3205. Result.Digits[0] = "1";
  3206. Result.Exponent += 1;
  3207. };
  3208. } else {
  3209. Result.Digits[N] = "0";
  3210. while ((N > -1) && (Result.Digits[N] === "0")) {
  3211. Result.Digits[N] = "\x00";
  3212. N -= 1;
  3213. };
  3214. };
  3215. } else Result.Digits[0] = "\x00";
  3216. if ((Result.Digits[0] === "\x00") && !GotNonZeroBeforeDot) {
  3217. Result.Exponent = 0;
  3218. Result.Negative = false;
  3219. };
  3220. return Result;
  3221. };
  3222. this.FloatToStr = function (Value) {
  3223. var Result = "";
  3224. Result = $mod.FloatToStrF(Value,$mod.TFloatFormat.ffGeneral,15,0);
  3225. return Result;
  3226. };
  3227. this.FloatToStrF = function (Value, format, Precision, Digits) {
  3228. var Result = "";
  3229. var DS = "";
  3230. DS = $mod.DecimalSeparator;
  3231. var $tmp1 = format;
  3232. if ($tmp1 === $mod.TFloatFormat.ffGeneral) {
  3233. Result = $impl.FormatGeneralFloat(Value,Precision,DS)}
  3234. else if ($tmp1 === $mod.TFloatFormat.ffExponent) {
  3235. Result = $impl.FormatExponentFloat(Value,Precision,Digits,DS)}
  3236. else if ($tmp1 === $mod.TFloatFormat.ffFixed) {
  3237. Result = $impl.FormatFixedFloat(Value,Digits,DS)}
  3238. else if ($tmp1 === $mod.TFloatFormat.ffNumber) {
  3239. Result = $impl.FormatNumberFloat(Value,Digits,DS,$mod.ThousandSeparator)}
  3240. else if ($tmp1 === $mod.TFloatFormat.ffCurrency) Result = $impl.FormatNumberCurrency(Value * 10000,Digits,DS,$mod.ThousandSeparator);
  3241. if (((format !== $mod.TFloatFormat.ffCurrency) && (Result.length > 1)) && (Result.charAt(0) === "-")) $impl.RemoveLeadingNegativeSign({get: function () {
  3242. return Result;
  3243. }, set: function (v) {
  3244. Result = v;
  3245. }},DS);
  3246. return Result;
  3247. };
  3248. this.TryStrToFloat = function (S, res) {
  3249. var Result = false;
  3250. var J = undefined;
  3251. var N = "";
  3252. N = S;
  3253. if ($mod.ThousandSeparator !== "") N = $mod.StringReplace(N,$mod.ThousandSeparator,"",rtl.createSet($mod.TStringReplaceFlag.rfReplaceAll));
  3254. if ($mod.DecimalSeparator !== ".") N = $mod.StringReplace(N,$mod.DecimalSeparator,".",{});
  3255. J = parseFloat(N);
  3256. Result = !isNaN(J);
  3257. if (Result) res.set(rtl.getNumber(J));
  3258. return Result;
  3259. };
  3260. this.StrToFloatDef = function (S, aDef) {
  3261. var Result = 0.0;
  3262. if (!$mod.TryStrToFloat(S,{get: function () {
  3263. return Result;
  3264. }, set: function (v) {
  3265. Result = v;
  3266. }})) Result = aDef;
  3267. return Result;
  3268. };
  3269. this.StrToFloat = function (S) {
  3270. var Result = 0.0;
  3271. if (!$mod.TryStrToFloat(S,{get: function () {
  3272. return Result;
  3273. }, set: function (v) {
  3274. Result = v;
  3275. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidFloat,[S]]);
  3276. return Result;
  3277. };
  3278. var MaxPrecision = 18;
  3279. this.FormatFloat = function (Fmt, aValue) {
  3280. var Result = "";
  3281. var E = 0.0;
  3282. var FV = new $mod.TFloatRec();
  3283. var Section = "";
  3284. var SectionLength = 0;
  3285. var ThousandSep = false;
  3286. var IsScientific = false;
  3287. var DecimalPos = 0;
  3288. var FirstDigit = 0;
  3289. var LastDigit = 0;
  3290. var RequestedDigits = 0;
  3291. var ExpSize = 0;
  3292. var Available = 0;
  3293. var Current = 0;
  3294. var PadZeroes = 0;
  3295. var DistToDecimal = 0;
  3296. function InitVars() {
  3297. E = aValue;
  3298. Section = "";
  3299. SectionLength = 0;
  3300. ThousandSep = false;
  3301. IsScientific = false;
  3302. DecimalPos = 0;
  3303. FirstDigit = 2147483647;
  3304. LastDigit = 0;
  3305. RequestedDigits = 0;
  3306. ExpSize = 0;
  3307. Available = -1;
  3308. };
  3309. function ToResult(AChar) {
  3310. Result = Result + AChar;
  3311. };
  3312. function AddToResult(AStr) {
  3313. Result = Result + AStr;
  3314. };
  3315. function WriteDigit(ADigit) {
  3316. if (ADigit === "\x00") return;
  3317. DistToDecimal -= 1;
  3318. if (DistToDecimal === -1) {
  3319. AddToResult($mod.DecimalSeparator);
  3320. ToResult(ADigit);
  3321. } else {
  3322. ToResult(ADigit);
  3323. if ((ThousandSep && ((DistToDecimal % 3) === 0)) && (DistToDecimal > 1)) AddToResult($mod.ThousandSeparator);
  3324. };
  3325. };
  3326. function GetDigit() {
  3327. var Result = "";
  3328. Result = "\x00";
  3329. if (Current <= Available) {
  3330. Result = FV.Digits[Current];
  3331. Current += 1;
  3332. } else if (DistToDecimal <= LastDigit) {
  3333. DistToDecimal -= 1}
  3334. else Result = "0";
  3335. return Result;
  3336. };
  3337. function CopyDigit() {
  3338. if (PadZeroes === 0) {
  3339. WriteDigit(GetDigit())}
  3340. else if (PadZeroes < 0) {
  3341. PadZeroes += 1;
  3342. if (DistToDecimal <= FirstDigit) {
  3343. WriteDigit("0")}
  3344. else DistToDecimal -= 1;
  3345. } else {
  3346. while (PadZeroes > 0) {
  3347. WriteDigit(GetDigit());
  3348. PadZeroes -= 1;
  3349. };
  3350. WriteDigit(GetDigit());
  3351. };
  3352. };
  3353. function GetSections(SP) {
  3354. var Result = 0;
  3355. var FL = 0;
  3356. var i = 0;
  3357. var C = "";
  3358. var Q = "";
  3359. var inQuote = false;
  3360. Result = 1;
  3361. SP.get()[1] = -1;
  3362. SP.get()[2] = -1;
  3363. SP.get()[3] = -1;
  3364. inQuote = false;
  3365. Q = "\x00";
  3366. i = 1;
  3367. FL = Fmt.length;
  3368. while (i <= FL) {
  3369. C = Fmt.charAt(i - 1);
  3370. var $tmp1 = C;
  3371. if ($tmp1 === ";") {
  3372. if (!inQuote) {
  3373. if (Result > 3) throw $mod.Exception.$create("Create$1",["Invalid float format"]);
  3374. SP.get()[Result] = i + 1;
  3375. Result += 1;
  3376. };
  3377. } else if (($tmp1 === '"') || ($tmp1 === "'")) {
  3378. if (inQuote) {
  3379. inQuote = C !== Q}
  3380. else {
  3381. inQuote = true;
  3382. Q = C;
  3383. };
  3384. };
  3385. i += 1;
  3386. };
  3387. if (SP.get()[Result] === -1) SP.get()[Result] = FL + 1;
  3388. return Result;
  3389. };
  3390. function AnalyzeFormat() {
  3391. var I = 0;
  3392. var Len = 0;
  3393. var Q = "";
  3394. var C = "";
  3395. var InQuote = false;
  3396. Len = Section.length;
  3397. I = 1;
  3398. InQuote = false;
  3399. Q = "\x00";
  3400. while (I <= Len) {
  3401. C = Section.charAt(I - 1);
  3402. if (C.charCodeAt() in rtl.createSet(34,39)) {
  3403. if (InQuote) {
  3404. InQuote = C !== Q}
  3405. else {
  3406. InQuote = true;
  3407. Q = C;
  3408. };
  3409. } else if (!InQuote) {
  3410. var $tmp1 = C;
  3411. if ($tmp1 === ".") {
  3412. if (DecimalPos === 0) DecimalPos = RequestedDigits + 1}
  3413. else if ($tmp1 === ",") {
  3414. ThousandSep = $mod.ThousandSeparator !== "\x00"}
  3415. else if (($tmp1 === "e") || ($tmp1 === "E")) {
  3416. I += 1;
  3417. if (I < Len) {
  3418. C = Section.charAt(I - 1);
  3419. IsScientific = C.charCodeAt() in rtl.createSet(45,43);
  3420. if (IsScientific) while ((I < Len) && (Section.charAt((I + 1) - 1) === "0")) {
  3421. ExpSize += 1;
  3422. I += 1;
  3423. };
  3424. if (ExpSize > 4) ExpSize = 4;
  3425. };
  3426. } else if ($tmp1 === "#") {
  3427. RequestedDigits += 1}
  3428. else if ($tmp1 === "0") {
  3429. if (RequestedDigits < FirstDigit) FirstDigit = RequestedDigits + 1;
  3430. RequestedDigits += 1;
  3431. LastDigit = RequestedDigits + 1;
  3432. };
  3433. };
  3434. I += 1;
  3435. };
  3436. if (DecimalPos === 0) DecimalPos = RequestedDigits + 1;
  3437. LastDigit = DecimalPos - LastDigit;
  3438. if (LastDigit > 0) LastDigit = 0;
  3439. FirstDigit = DecimalPos - FirstDigit;
  3440. if (FirstDigit < 0) FirstDigit = 0;
  3441. };
  3442. function ValueOutSideScope() {
  3443. var Result = false;
  3444. Result = (((FV.Exponent >= 18) && !IsScientific) || (FV.Exponent === 0x7FF)) || (FV.Exponent === 0x800);
  3445. return Result;
  3446. };
  3447. function CalcRunVars() {
  3448. var D = 0;
  3449. var P = 0;
  3450. if (IsScientific) {
  3451. P = RequestedDigits;
  3452. D = 9999;
  3453. } else {
  3454. P = 18;
  3455. D = (RequestedDigits - DecimalPos) + 1;
  3456. };
  3457. FV = new $mod.TFloatRec($mod.FloatToDecimal(aValue,P,D));
  3458. DistToDecimal = DecimalPos - 1;
  3459. if (IsScientific) {
  3460. PadZeroes = 0}
  3461. else {
  3462. PadZeroes = FV.Exponent - (DecimalPos - 1);
  3463. if (PadZeroes >= 0) DistToDecimal = FV.Exponent;
  3464. };
  3465. Available = -1;
  3466. while ((Available < (rtl.length(FV.Digits) - 1)) && (FV.Digits[Available + 1] !== "\x00")) Available += 1;
  3467. };
  3468. function FormatExponent(ASign, aExponent) {
  3469. var Result = "";
  3470. Result = $mod.IntToStr(aExponent);
  3471. Result = pas.System.StringOfChar("0",ExpSize - Result.length) + Result;
  3472. if (aExponent < 0) {
  3473. Result = "-" + Result}
  3474. else if ((aExponent > 0) && (ASign === "+")) Result = ASign + Result;
  3475. return Result;
  3476. };
  3477. var I = 0;
  3478. var S = 0;
  3479. var C = "";
  3480. var Q = "";
  3481. var PA = [];
  3482. var InLiteral = false;
  3483. PA = rtl.arraySetLength(PA,0,4);
  3484. Result = "";
  3485. InitVars();
  3486. if (E > 0) {
  3487. S = 1}
  3488. else if (E < 0) {
  3489. S = 2}
  3490. else S = 3;
  3491. PA[0] = 0;
  3492. I = GetSections({get: function () {
  3493. return PA;
  3494. }, set: function (v) {
  3495. PA = v;
  3496. }});
  3497. if ((I < S) || ((PA[S] - PA[S - 1]) === 0)) S = 1;
  3498. SectionLength = (PA[S] - PA[S - 1]) - 1;
  3499. Section = pas.System.Copy(Fmt,PA[S - 1] + 1,SectionLength);
  3500. Section = rtl.strSetLength(Section,SectionLength);
  3501. AnalyzeFormat();
  3502. CalcRunVars();
  3503. if ((SectionLength === 0) || ValueOutSideScope()) {
  3504. Section=E.toPrecision(15);
  3505. Result = Section;
  3506. };
  3507. I = 1;
  3508. Current = 0;
  3509. Q = " ";
  3510. InLiteral = false;
  3511. if (FV.Negative && (S === 1)) ToResult("-");
  3512. while (I <= SectionLength) {
  3513. C = Section.charAt(I - 1);
  3514. if (C.charCodeAt() in rtl.createSet(34,39)) {
  3515. if (InLiteral) {
  3516. InLiteral = C !== Q}
  3517. else {
  3518. InLiteral = true;
  3519. Q = C;
  3520. };
  3521. } else if (InLiteral) {
  3522. ToResult(C)}
  3523. else {
  3524. var $tmp1 = C;
  3525. if (($tmp1 === "0") || ($tmp1 === "#")) {
  3526. CopyDigit()}
  3527. else if (($tmp1 === ".") || ($tmp1 === ",")) {}
  3528. else if (($tmp1 === "e") || ($tmp1 === "E")) {
  3529. ToResult(C);
  3530. I += 1;
  3531. if (I <= Section.length) {
  3532. C = Section.charAt(I - 1);
  3533. if (C.charCodeAt() in rtl.createSet(43,45)) {
  3534. AddToResult(FormatExponent(C,(FV.Exponent - DecimalPos) + 1));
  3535. while ((I < SectionLength) && (Section.charAt((I + 1) - 1) === "0")) I += 1;
  3536. };
  3537. };
  3538. } else {
  3539. ToResult(C);
  3540. };
  3541. };
  3542. I += 1;
  3543. };
  3544. return Result;
  3545. };
  3546. this.TrueBoolStrs = [];
  3547. this.FalseBoolStrs = [];
  3548. this.StrToBool = function (S) {
  3549. var Result = false;
  3550. if (!$mod.TryStrToBool(S,{get: function () {
  3551. return Result;
  3552. }, set: function (v) {
  3553. Result = v;
  3554. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidBoolean,[S]]);
  3555. return Result;
  3556. };
  3557. this.BoolToStr = function (B, UseBoolStrs) {
  3558. var Result = "";
  3559. if (UseBoolStrs) {
  3560. $impl.CheckBoolStrs();
  3561. if (B) {
  3562. Result = $mod.TrueBoolStrs[0]}
  3563. else Result = $mod.FalseBoolStrs[0];
  3564. } else if (B) {
  3565. Result = "-1"}
  3566. else Result = "0";
  3567. return Result;
  3568. };
  3569. this.BoolToStr$1 = function (B, TrueS, FalseS) {
  3570. var Result = "";
  3571. if (B) {
  3572. Result = TrueS}
  3573. else Result = FalseS;
  3574. return Result;
  3575. };
  3576. this.StrToBoolDef = function (S, Default) {
  3577. var Result = false;
  3578. if (!$mod.TryStrToBool(S,{get: function () {
  3579. return Result;
  3580. }, set: function (v) {
  3581. Result = v;
  3582. }})) Result = Default;
  3583. return Result;
  3584. };
  3585. this.TryStrToBool = function (S, Value) {
  3586. var Result = false;
  3587. var Temp = "";
  3588. var I = 0;
  3589. var D = 0.0;
  3590. var Code = 0;
  3591. Temp = $mod.UpperCase(S);
  3592. pas.System.val$7(Temp,{get: function () {
  3593. return D;
  3594. }, set: function (v) {
  3595. D = v;
  3596. }},{get: function () {
  3597. return Code;
  3598. }, set: function (v) {
  3599. Code = v;
  3600. }});
  3601. Result = true;
  3602. if (Code === 0) {
  3603. Value.set(D !== 0.0)}
  3604. else {
  3605. $impl.CheckBoolStrs();
  3606. for (var $l1 = 0, $end2 = rtl.length($mod.TrueBoolStrs) - 1; $l1 <= $end2; $l1++) {
  3607. I = $l1;
  3608. if (Temp === $mod.UpperCase($mod.TrueBoolStrs[I])) {
  3609. Value.set(true);
  3610. return Result;
  3611. };
  3612. };
  3613. for (var $l3 = 0, $end4 = rtl.length($mod.FalseBoolStrs) - 1; $l3 <= $end4; $l3++) {
  3614. I = $l3;
  3615. if (Temp === $mod.UpperCase($mod.FalseBoolStrs[I])) {
  3616. Value.set(false);
  3617. return Result;
  3618. };
  3619. };
  3620. Result = false;
  3621. };
  3622. return Result;
  3623. };
  3624. this.ConfigExtension = ".cfg";
  3625. this.SysConfigDir = "";
  3626. this.OnGetEnvironmentVariable = null;
  3627. this.OnGetEnvironmentString = null;
  3628. this.OnGetEnvironmentVariableCount = null;
  3629. this.GetEnvironmentVariable = function (EnvVar) {
  3630. var Result = "";
  3631. if ($mod.OnGetEnvironmentVariable != null) {
  3632. Result = $mod.OnGetEnvironmentVariable(EnvVar)}
  3633. else Result = "";
  3634. return Result;
  3635. };
  3636. this.GetEnvironmentVariableCount = function () {
  3637. var Result = 0;
  3638. if ($mod.OnGetEnvironmentVariableCount != null) {
  3639. Result = $mod.OnGetEnvironmentVariableCount()}
  3640. else Result = 0;
  3641. return Result;
  3642. };
  3643. this.GetEnvironmentString = function (Index) {
  3644. var Result = "";
  3645. if ($mod.OnGetEnvironmentString != null) {
  3646. Result = $mod.OnGetEnvironmentString(Index)}
  3647. else Result = "";
  3648. return Result;
  3649. };
  3650. this.ShowException = function (ExceptObject, ExceptAddr) {
  3651. var S = "";
  3652. S = "Application raised an exception " + ExceptObject.$classname;
  3653. if ($mod.Exception.isPrototypeOf(ExceptObject)) S = (S + " : ") + ExceptObject.fMessage;
  3654. window.alert(S);
  3655. if (ExceptAddr === null) ;
  3656. };
  3657. this.Abort = function () {
  3658. throw $mod.EAbort.$create("Create$1",[$impl.SAbortError]);
  3659. };
  3660. this.TEventType = {"0": "etCustom", etCustom: 0, "1": "etInfo", etInfo: 1, "2": "etWarning", etWarning: 2, "3": "etError", etError: 3, "4": "etDebug", etDebug: 4};
  3661. this.TSystemTime = function (s) {
  3662. if (s) {
  3663. this.Year = s.Year;
  3664. this.Month = s.Month;
  3665. this.Day = s.Day;
  3666. this.DayOfWeek = s.DayOfWeek;
  3667. this.Hour = s.Hour;
  3668. this.Minute = s.Minute;
  3669. this.Second = s.Second;
  3670. this.MilliSecond = s.MilliSecond;
  3671. } else {
  3672. this.Year = 0;
  3673. this.Month = 0;
  3674. this.Day = 0;
  3675. this.DayOfWeek = 0;
  3676. this.Hour = 0;
  3677. this.Minute = 0;
  3678. this.Second = 0;
  3679. this.MilliSecond = 0;
  3680. };
  3681. this.$equal = function (b) {
  3682. return (this.Year === b.Year) && ((this.Month === b.Month) && ((this.Day === b.Day) && ((this.DayOfWeek === b.DayOfWeek) && ((this.Hour === b.Hour) && ((this.Minute === b.Minute) && ((this.Second === b.Second) && (this.MilliSecond === b.MilliSecond)))))));
  3683. };
  3684. };
  3685. this.TTimeStamp = function (s) {
  3686. if (s) {
  3687. this.Time = s.Time;
  3688. this.date = s.date;
  3689. } else {
  3690. this.Time = 0;
  3691. this.date = 0;
  3692. };
  3693. this.$equal = function (b) {
  3694. return (this.Time === b.Time) && (this.date === b.date);
  3695. };
  3696. };
  3697. this.TimeSeparator = ":";
  3698. this.DateSeparator = "-";
  3699. this.ShortDateFormat = "yyyy-mm-dd";
  3700. this.LongDateFormat = "ddd, yyyy-mm-dd";
  3701. this.ShortTimeFormat = "hh:nn";
  3702. this.LongTimeFormat = "hh:nn:ss";
  3703. this.DecimalSeparator = ".";
  3704. this.ThousandSeparator = "";
  3705. this.TimeAMString = "AM";
  3706. this.TimePMString = "PM";
  3707. this.HoursPerDay = 24;
  3708. this.MinsPerHour = 60;
  3709. this.SecsPerMin = 60;
  3710. this.MSecsPerSec = 1000;
  3711. this.MinsPerDay = 24 * 60;
  3712. this.SecsPerDay = 1440 * 60;
  3713. this.MSecsPerDay = 86400 * 1000;
  3714. this.MaxDateTime = 2958465.99999999;
  3715. this.MinDateTime = -693593.99999999;
  3716. this.JulianEpoch = -2415018.5;
  3717. this.UnixEpoch = -2415018.5 + 2440587.5;
  3718. this.DateDelta = 693594;
  3719. this.UnixDateDelta = 25569;
  3720. this.MonthDays = [[31,28,31,30,31,30,31,31,30,31,30,31],[31,29,31,30,31,30,31,31,30,31,30,31]];
  3721. this.ShortMonthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
  3722. this.LongMonthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"];
  3723. this.ShortDayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
  3724. this.LongDayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
  3725. rtl.createClass($mod,"TFormatSettings",pas.System.TObject,function () {
  3726. this.GetCurrencyDecimals = function () {
  3727. var Result = 0;
  3728. Result = $mod.CurrencyDecimals;
  3729. return Result;
  3730. };
  3731. this.GetCurrencyFormat = function () {
  3732. var Result = 0;
  3733. Result = $mod.CurrencyFormat;
  3734. return Result;
  3735. };
  3736. this.GetCurrencyString = function () {
  3737. var Result = "";
  3738. Result = $mod.CurrencyString;
  3739. return Result;
  3740. };
  3741. this.GetDateSeparator = function () {
  3742. var Result = "";
  3743. Result = $mod.DateSeparator;
  3744. return Result;
  3745. };
  3746. this.GetDecimalSeparator = function () {
  3747. var Result = "";
  3748. Result = $mod.DecimalSeparator;
  3749. return Result;
  3750. };
  3751. this.GetLongDateFormat = function () {
  3752. var Result = "";
  3753. Result = $mod.LongDateFormat;
  3754. return Result;
  3755. };
  3756. this.GetLongDayNames = function () {
  3757. var Result = rtl.arraySetLength(null,"",7);
  3758. Result = $mod.LongDayNames.slice(0);
  3759. return Result;
  3760. };
  3761. this.GetLongMonthNames = function () {
  3762. var Result = rtl.arraySetLength(null,"",12);
  3763. Result = $mod.LongMonthNames.slice(0);
  3764. return Result;
  3765. };
  3766. this.GetLongTimeFormat = function () {
  3767. var Result = "";
  3768. Result = $mod.LongTimeFormat;
  3769. return Result;
  3770. };
  3771. this.GetNegCurrFormat = function () {
  3772. var Result = 0;
  3773. Result = $mod.NegCurrFormat;
  3774. return Result;
  3775. };
  3776. this.GetShortDateFormat = function () {
  3777. var Result = "";
  3778. Result = $mod.ShortDateFormat;
  3779. return Result;
  3780. };
  3781. this.GetShortDayNames = function () {
  3782. var Result = rtl.arraySetLength(null,"",7);
  3783. Result = $mod.ShortDayNames.slice(0);
  3784. return Result;
  3785. };
  3786. this.GetShortMonthNames = function () {
  3787. var Result = rtl.arraySetLength(null,"",12);
  3788. Result = $mod.ShortMonthNames.slice(0);
  3789. return Result;
  3790. };
  3791. this.GetShortTimeFormat = function () {
  3792. var Result = "";
  3793. Result = $mod.ShortTimeFormat;
  3794. return Result;
  3795. };
  3796. this.GetThousandSeparator = function () {
  3797. var Result = "";
  3798. Result = $mod.ThousandSeparator;
  3799. return Result;
  3800. };
  3801. this.GetTimeAMString = function () {
  3802. var Result = "";
  3803. Result = $mod.TimeAMString;
  3804. return Result;
  3805. };
  3806. this.GetTimePMString = function () {
  3807. var Result = "";
  3808. Result = $mod.TimePMString;
  3809. return Result;
  3810. };
  3811. this.GetTimeSeparator = function () {
  3812. var Result = "";
  3813. Result = $mod.TimeSeparator;
  3814. return Result;
  3815. };
  3816. this.SetCurrencyFormat = function (AValue) {
  3817. $mod.CurrencyFormat = AValue;
  3818. };
  3819. this.SetCurrencyString = function (AValue) {
  3820. $mod.CurrencyString = AValue;
  3821. };
  3822. this.SetDateSeparator = function (Value) {
  3823. $mod.DateSeparator = Value;
  3824. };
  3825. this.SetDecimalSeparator = function (Value) {
  3826. $mod.DecimalSeparator = Value;
  3827. };
  3828. this.SetLongDateFormat = function (Value) {
  3829. $mod.LongDateFormat = Value;
  3830. };
  3831. this.SetLongDayNames = function (AValue) {
  3832. $mod.LongDayNames = AValue.slice(0);
  3833. };
  3834. this.SetLongMonthNames = function (AValue) {
  3835. $mod.LongMonthNames = AValue.slice(0);
  3836. };
  3837. this.SetLongTimeFormat = function (Value) {
  3838. $mod.LongTimeFormat = Value;
  3839. };
  3840. this.SetNegCurrFormat = function (AValue) {
  3841. $mod.NegCurrFormat = AValue;
  3842. };
  3843. this.SetShortDateFormat = function (Value) {
  3844. $mod.ShortDateFormat = Value;
  3845. };
  3846. this.SetShortDayNames = function (AValue) {
  3847. $mod.ShortDayNames = AValue.slice(0);
  3848. };
  3849. this.SetShortMonthNames = function (AValue) {
  3850. $mod.ShortMonthNames = AValue.slice(0);
  3851. };
  3852. this.SetShortTimeFormat = function (Value) {
  3853. $mod.ShortTimeFormat = Value;
  3854. };
  3855. this.SetCurrencyDecimals = function (AValue) {
  3856. $mod.CurrencyDecimals = AValue;
  3857. };
  3858. this.SetThousandSeparator = function (Value) {
  3859. $mod.ThousandSeparator = Value;
  3860. };
  3861. this.SetTimeAMString = function (Value) {
  3862. $mod.TimeAMString = Value;
  3863. };
  3864. this.SetTimePMString = function (Value) {
  3865. $mod.TimePMString = Value;
  3866. };
  3867. this.SetTimeSeparator = function (Value) {
  3868. $mod.TimeSeparator = Value;
  3869. };
  3870. });
  3871. this.FormatSettings = null;
  3872. this.TwoDigitYearCenturyWindow = 50;
  3873. this.DateTimeToJSDate = function (aDateTime) {
  3874. var Result = null;
  3875. var Y = 0;
  3876. var M = 0;
  3877. var D = 0;
  3878. var h = 0;
  3879. var n = 0;
  3880. var s = 0;
  3881. var z = 0;
  3882. $mod.DecodeDate(pas.System.Trunc(aDateTime),{get: function () {
  3883. return Y;
  3884. }, set: function (v) {
  3885. Y = v;
  3886. }},{get: function () {
  3887. return M;
  3888. }, set: function (v) {
  3889. M = v;
  3890. }},{get: function () {
  3891. return D;
  3892. }, set: function (v) {
  3893. D = v;
  3894. }});
  3895. $mod.DecodeTime(pas.System.Frac(aDateTime),{get: function () {
  3896. return h;
  3897. }, set: function (v) {
  3898. h = v;
  3899. }},{get: function () {
  3900. return n;
  3901. }, set: function (v) {
  3902. n = v;
  3903. }},{get: function () {
  3904. return s;
  3905. }, set: function (v) {
  3906. s = v;
  3907. }},{get: function () {
  3908. return z;
  3909. }, set: function (v) {
  3910. z = v;
  3911. }});
  3912. Result = new Date(Y,M,D,h,n,s,z);
  3913. return Result;
  3914. };
  3915. this.JSDateToDateTime = function (aDate) {
  3916. var Result = 0.0;
  3917. Result = $mod.EncodeDate(aDate.getFullYear(),aDate.getMonth() + 1,aDate.getDate()) + $mod.EncodeTime(aDate.getHours(),aDate.getMinutes(),aDate.getSeconds(),aDate.getMilliseconds());
  3918. return Result;
  3919. };
  3920. this.DateTimeToTimeStamp = function (DateTime) {
  3921. var Result = new $mod.TTimeStamp();
  3922. var D = 0.0;
  3923. D = DateTime * 86400000;
  3924. if (D < 0) {
  3925. D = D - 0.5}
  3926. else D = D + 0.5;
  3927. Result.Time = pas.System.Trunc(Math.abs(pas.System.Trunc(D)) % 86400000);
  3928. Result.date = 693594 + Math.floor(pas.System.Trunc(D) / 86400000);
  3929. return Result;
  3930. };
  3931. this.TimeStampToDateTime = function (TimeStamp) {
  3932. var Result = 0.0;
  3933. Result = $mod.ComposeDateTime(TimeStamp.date - 693594,TimeStamp.Time / 86400000);
  3934. return Result;
  3935. };
  3936. this.MSecsToTimeStamp = function (MSecs) {
  3937. var Result = new $mod.TTimeStamp();
  3938. Result.date = pas.System.Trunc(MSecs / 86400000);
  3939. MSecs = MSecs - (Result.date * 86400000);
  3940. Result.Time = Math.round(MSecs);
  3941. return Result;
  3942. };
  3943. this.TimeStampToMSecs = function (TimeStamp) {
  3944. var Result = 0;
  3945. Result = TimeStamp.Time + (TimeStamp.date * 86400000);
  3946. return Result;
  3947. };
  3948. this.TryEncodeDate = function (Year, Month, Day, date) {
  3949. var Result = false;
  3950. var c = 0;
  3951. var ya = 0;
  3952. Result = (((((Year > 0) && (Year < 10000)) && (Month >= 1)) && (Month <= 12)) && (Day > 0)) && (Day <= $mod.MonthDays[+$mod.IsLeapYear(Year)][Month - 1]);
  3953. if (Result) {
  3954. if (Month > 2) {
  3955. Month -= 3}
  3956. else {
  3957. Month += 9;
  3958. Year -= 1;
  3959. };
  3960. c = Math.floor(Year / 100);
  3961. ya = Year - (100 * c);
  3962. date.set(((((146097 * c) >>> 2) + ((1461 * ya) >>> 2)) + Math.floor(((153 * Month) + 2) / 5)) + Day);
  3963. date.set(date.get() - 693900);
  3964. };
  3965. return Result;
  3966. };
  3967. this.TryEncodeTime = function (Hour, Min, Sec, MSec, Time) {
  3968. var Result = false;
  3969. Result = (((Hour < 24) && (Min < 60)) && (Sec < 60)) && (MSec < 1000);
  3970. if (Result) Time.set(((((Hour * 3600000) + (Min * 60000)) + (Sec * 1000)) + MSec) / 86400000);
  3971. return Result;
  3972. };
  3973. this.EncodeDate = function (Year, Month, Day) {
  3974. var Result = 0.0;
  3975. if (!$mod.TryEncodeDate(Year,Month,Day,{get: function () {
  3976. return Result;
  3977. }, set: function (v) {
  3978. Result = v;
  3979. }})) throw $mod.EConvertError.$create("CreateFmt",["%s-%s-%s is not a valid date specification",[$mod.IntToStr(Year),$mod.IntToStr(Month),$mod.IntToStr(Day)]]);
  3980. return Result;
  3981. };
  3982. this.EncodeTime = function (Hour, Minute, Second, MilliSecond) {
  3983. var Result = 0.0;
  3984. if (!$mod.TryEncodeTime(Hour,Minute,Second,MilliSecond,{get: function () {
  3985. return Result;
  3986. }, set: function (v) {
  3987. Result = v;
  3988. }})) throw $mod.EConvertError.$create("CreateFmt",["%s:%s:%s.%s is not a valid time specification",[$mod.IntToStr(Hour),$mod.IntToStr(Minute),$mod.IntToStr(Second),$mod.IntToStr(MilliSecond)]]);
  3989. return Result;
  3990. };
  3991. this.ComposeDateTime = function (date, Time) {
  3992. var Result = 0.0;
  3993. if (date < 0) {
  3994. Result = pas.System.Trunc(date) - Math.abs(pas.System.Frac(Time))}
  3995. else Result = pas.System.Trunc(date) + Math.abs(pas.System.Frac(Time));
  3996. return Result;
  3997. };
  3998. this.DecodeDate = function (date, Year, Month, Day) {
  3999. var ly = 0;
  4000. var ld = 0;
  4001. var lm = 0;
  4002. var j = 0;
  4003. if (date <= -693594) {
  4004. Year.set(0);
  4005. Month.set(0);
  4006. Day.set(0);
  4007. } else {
  4008. if (date > 0) {
  4009. date = date + (1 / (86400000 * 2))}
  4010. else date = date - (1 / (86400000 * 2));
  4011. if (date > $mod.MaxDateTime) date = $mod.MaxDateTime;
  4012. j = ((pas.System.Trunc(date) + 693900) << 2) - 1;
  4013. ly = Math.floor(j / 146097);
  4014. j = j - (146097 * ly);
  4015. ld = j >>> 2;
  4016. j = Math.floor(((ld << 2) + 3) / 1461);
  4017. ld = (((ld << 2) + 7) - (1461 * j)) >>> 2;
  4018. lm = Math.floor(((5 * ld) - 3) / 153);
  4019. ld = Math.floor((((5 * ld) + 2) - (153 * lm)) / 5);
  4020. ly = (100 * ly) + j;
  4021. if (lm < 10) {
  4022. lm += 3}
  4023. else {
  4024. lm -= 9;
  4025. ly += 1;
  4026. };
  4027. Year.set(ly);
  4028. Month.set(lm);
  4029. Day.set(ld);
  4030. };
  4031. };
  4032. this.DecodeDateFully = function (DateTime, Year, Month, Day, DOW) {
  4033. var Result = false;
  4034. $mod.DecodeDate(DateTime,Year,Month,Day);
  4035. DOW.set($mod.DayOfWeek(DateTime));
  4036. Result = $mod.IsLeapYear(Year.get());
  4037. return Result;
  4038. };
  4039. this.DecodeTime = function (Time, Hour, Minute, Second, MilliSecond) {
  4040. var l = 0;
  4041. l = $mod.DateTimeToTimeStamp(Time).Time;
  4042. Hour.set(Math.floor(l / 3600000));
  4043. l = l % 3600000;
  4044. Minute.set(Math.floor(l / 60000));
  4045. l = l % 60000;
  4046. Second.set(Math.floor(l / 1000));
  4047. l = l % 1000;
  4048. MilliSecond.set(l);
  4049. };
  4050. this.DateTimeToSystemTime = function (DateTime, SystemTime) {
  4051. $mod.DecodeDateFully(DateTime,{p: SystemTime.get(), get: function () {
  4052. return this.p.Year;
  4053. }, set: function (v) {
  4054. this.p.Year = v;
  4055. }},{p: SystemTime.get(), get: function () {
  4056. return this.p.Month;
  4057. }, set: function (v) {
  4058. this.p.Month = v;
  4059. }},{p: SystemTime.get(), get: function () {
  4060. return this.p.Day;
  4061. }, set: function (v) {
  4062. this.p.Day = v;
  4063. }},{p: SystemTime.get(), get: function () {
  4064. return this.p.DayOfWeek;
  4065. }, set: function (v) {
  4066. this.p.DayOfWeek = v;
  4067. }});
  4068. $mod.DecodeTime(DateTime,{p: SystemTime.get(), get: function () {
  4069. return this.p.Hour;
  4070. }, set: function (v) {
  4071. this.p.Hour = v;
  4072. }},{p: SystemTime.get(), get: function () {
  4073. return this.p.Minute;
  4074. }, set: function (v) {
  4075. this.p.Minute = v;
  4076. }},{p: SystemTime.get(), get: function () {
  4077. return this.p.Second;
  4078. }, set: function (v) {
  4079. this.p.Second = v;
  4080. }},{p: SystemTime.get(), get: function () {
  4081. return this.p.MilliSecond;
  4082. }, set: function (v) {
  4083. this.p.MilliSecond = v;
  4084. }});
  4085. SystemTime.get().DayOfWeek -= 1;
  4086. };
  4087. this.SystemTimeToDateTime = function (SystemTime) {
  4088. var Result = 0.0;
  4089. Result = $mod.ComposeDateTime($impl.DoEncodeDate(SystemTime.Year,SystemTime.Month,SystemTime.Day),$impl.DoEncodeTime(SystemTime.Hour,SystemTime.Minute,SystemTime.Second,SystemTime.MilliSecond));
  4090. return Result;
  4091. };
  4092. this.DayOfWeek = function (DateTime) {
  4093. var Result = 0;
  4094. Result = 1 + ((pas.System.Trunc(DateTime) - 1) % 7);
  4095. if (Result <= 0) Result += 7;
  4096. return Result;
  4097. };
  4098. this.date = function () {
  4099. var Result = 0.0;
  4100. Result = pas.System.Trunc($mod.Now());
  4101. return Result;
  4102. };
  4103. this.Time = function () {
  4104. var Result = 0.0;
  4105. Result = $mod.Now() - $mod.date();
  4106. return Result;
  4107. };
  4108. this.Now = function () {
  4109. var Result = 0.0;
  4110. Result = $mod.JSDateToDateTime(new Date());
  4111. return Result;
  4112. };
  4113. this.IncMonth = function (DateTime, NumberOfMonths) {
  4114. var Result = 0.0;
  4115. var Year = 0;
  4116. var Month = 0;
  4117. var Day = 0;
  4118. $mod.DecodeDate(DateTime,{get: function () {
  4119. return Year;
  4120. }, set: function (v) {
  4121. Year = v;
  4122. }},{get: function () {
  4123. return Month;
  4124. }, set: function (v) {
  4125. Month = v;
  4126. }},{get: function () {
  4127. return Day;
  4128. }, set: function (v) {
  4129. Day = v;
  4130. }});
  4131. $mod.IncAMonth({get: function () {
  4132. return Year;
  4133. }, set: function (v) {
  4134. Year = v;
  4135. }},{get: function () {
  4136. return Month;
  4137. }, set: function (v) {
  4138. Month = v;
  4139. }},{get: function () {
  4140. return Day;
  4141. }, set: function (v) {
  4142. Day = v;
  4143. }},NumberOfMonths);
  4144. Result = $mod.ComposeDateTime($impl.DoEncodeDate(Year,Month,Day),DateTime);
  4145. return Result;
  4146. };
  4147. this.IncAMonth = function (Year, Month, Day, NumberOfMonths) {
  4148. var TempMonth = 0;
  4149. var S = 0;
  4150. if (NumberOfMonths >= 0) {
  4151. S = 1}
  4152. else S = -1;
  4153. Year.set(Year.get() + Math.floor(NumberOfMonths / 12));
  4154. TempMonth = (Month.get() + (NumberOfMonths % 12)) - 1;
  4155. if ((TempMonth > 11) || (TempMonth < 0)) {
  4156. TempMonth -= S * 12;
  4157. Year.set(Year.get() + S);
  4158. };
  4159. Month.set(TempMonth + 1);
  4160. if (Day.get() > $mod.MonthDays[+$mod.IsLeapYear(Year.get())][Month.get() - 1]) Day.set($mod.MonthDays[+$mod.IsLeapYear(Year.get())][Month.get() - 1]);
  4161. };
  4162. this.IsLeapYear = function (Year) {
  4163. var Result = false;
  4164. Result = ((Year % 4) === 0) && (((Year % 100) !== 0) || ((Year % 400) === 0));
  4165. return Result;
  4166. };
  4167. this.DateToStr = function (date) {
  4168. var Result = "";
  4169. Result = $mod.FormatDateTime("ddddd",date);
  4170. return Result;
  4171. };
  4172. this.TimeToStr = function (Time) {
  4173. var Result = "";
  4174. Result = $mod.FormatDateTime("tt",Time);
  4175. return Result;
  4176. };
  4177. this.DateTimeToStr = function (DateTime, ForceTimeIfZero) {
  4178. var Result = "";
  4179. Result = $mod.FormatDateTime($impl.DateTimeToStrFormat[+ForceTimeIfZero],DateTime);
  4180. return Result;
  4181. };
  4182. this.StrToDate = function (S) {
  4183. var Result = 0.0;
  4184. Result = $mod.StrToDate$2(S,$mod.ShortDateFormat,"\x00");
  4185. return Result;
  4186. };
  4187. this.StrToDate$1 = function (S, separator) {
  4188. var Result = 0.0;
  4189. Result = $mod.StrToDate$2(S,$mod.ShortDateFormat,separator);
  4190. return Result;
  4191. };
  4192. this.StrToDate$2 = function (S, useformat, separator) {
  4193. var Result = 0.0;
  4194. var MSg = "";
  4195. Result = $impl.IntStrToDate({get: function () {
  4196. return MSg;
  4197. }, set: function (v) {
  4198. MSg = v;
  4199. }},S,useformat,separator);
  4200. if (MSg !== "") throw $mod.EConvertError.$create("Create$1",[MSg]);
  4201. return Result;
  4202. };
  4203. this.StrToTime = function (S) {
  4204. var Result = 0.0;
  4205. Result = $mod.StrToTime$1(S,$mod.TimeSeparator);
  4206. return Result;
  4207. };
  4208. this.StrToTime$1 = function (S, separator) {
  4209. var Result = 0.0;
  4210. var Msg = "";
  4211. Result = $impl.IntStrToTime({get: function () {
  4212. return Msg;
  4213. }, set: function (v) {
  4214. Msg = v;
  4215. }},S,S.length,separator);
  4216. if (Msg !== "") throw $mod.EConvertError.$create("Create$1",[Msg]);
  4217. return Result;
  4218. };
  4219. this.StrToDateTime = function (S) {
  4220. var Result = 0.0;
  4221. var TimeStr = "";
  4222. var DateStr = "";
  4223. var PartsFound = 0;
  4224. PartsFound = $impl.SplitDateTimeStr(S,{get: function () {
  4225. return DateStr;
  4226. }, set: function (v) {
  4227. DateStr = v;
  4228. }},{get: function () {
  4229. return TimeStr;
  4230. }, set: function (v) {
  4231. TimeStr = v;
  4232. }});
  4233. var $tmp1 = PartsFound;
  4234. if ($tmp1 === 0) {
  4235. Result = $mod.StrToDate("")}
  4236. else if ($tmp1 === 1) {
  4237. if (DateStr.length > 0) {
  4238. Result = $mod.StrToDate$2(DateStr,$mod.ShortDateFormat,$mod.DateSeparator)}
  4239. else Result = $mod.StrToTime(TimeStr)}
  4240. else if ($tmp1 === 2) Result = $mod.ComposeDateTime($mod.StrToDate$2(DateStr,$mod.ShortDateFormat,$mod.DateSeparator),$mod.StrToTime(TimeStr));
  4241. return Result;
  4242. };
  4243. this.FormatDateTime = function (FormatStr, DateTime) {
  4244. var Result = "";
  4245. function StoreStr(APos, Len) {
  4246. Result = Result + pas.System.Copy(FormatStr,APos,Len);
  4247. };
  4248. function StoreString(AStr) {
  4249. Result = Result + AStr;
  4250. };
  4251. function StoreInt(Value, Digits) {
  4252. var S = "";
  4253. S = $mod.IntToStr(Value);
  4254. while (S.length < Digits) S = "0" + S;
  4255. StoreString(S);
  4256. };
  4257. var Year = 0;
  4258. var Month = 0;
  4259. var Day = 0;
  4260. var DayOfWeek = 0;
  4261. var Hour = 0;
  4262. var Minute = 0;
  4263. var Second = 0;
  4264. var MilliSecond = 0;
  4265. function StoreFormat(FormatStr, Nesting, TimeFlag) {
  4266. var Token = "";
  4267. var lastformattoken = "";
  4268. var prevlasttoken = "";
  4269. var Count = 0;
  4270. var Clock12 = false;
  4271. var tmp = 0;
  4272. var isInterval = false;
  4273. var P = 0;
  4274. var FormatCurrent = 0;
  4275. var FormatEnd = 0;
  4276. if (Nesting > 1) return;
  4277. FormatCurrent = 1;
  4278. FormatEnd = FormatStr.length;
  4279. Clock12 = false;
  4280. isInterval = false;
  4281. P = 1;
  4282. while (P <= FormatEnd) {
  4283. Token = FormatStr.charAt(P - 1);
  4284. var $tmp1 = Token;
  4285. if (($tmp1 === "'") || ($tmp1 === '"')) {
  4286. P += 1;
  4287. while ((P < FormatEnd) && (FormatStr.charAt(P - 1) !== Token)) P += 1;
  4288. } else if (($tmp1 === "A") || ($tmp1 === "a")) {
  4289. if ((($mod.CompareText(pas.System.Copy(FormatStr,P,3),"A\/P") === 0) || ($mod.CompareText(pas.System.Copy(FormatStr,P,4),"AMPM") === 0)) || ($mod.CompareText(pas.System.Copy(FormatStr,P,5),"AM\/PM") === 0)) {
  4290. Clock12 = true;
  4291. break;
  4292. };
  4293. };
  4294. P += 1;
  4295. };
  4296. Token = "ÿ";
  4297. lastformattoken = " ";
  4298. prevlasttoken = "H";
  4299. while (FormatCurrent <= FormatEnd) {
  4300. Token = $mod.UpperCase(FormatStr.charAt(FormatCurrent - 1)).charAt(0);
  4301. Count = 1;
  4302. P = FormatCurrent + 1;
  4303. var $tmp2 = Token;
  4304. if (($tmp2 === "'") || ($tmp2 === '"')) {
  4305. while ((P < FormatEnd) && (FormatStr.charAt(P - 1) !== Token)) P += 1;
  4306. P += 1;
  4307. Count = P - FormatCurrent;
  4308. StoreStr(FormatCurrent + 1,Count - 2);
  4309. } else if ($tmp2 === "A") {
  4310. if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,4),"AMPM") === 0) {
  4311. Count = 4;
  4312. if (Hour < 12) {
  4313. StoreString($mod.TimeAMString)}
  4314. else StoreString($mod.TimePMString);
  4315. } else if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,5),"AM\/PM") === 0) {
  4316. Count = 5;
  4317. if (Hour < 12) {
  4318. StoreStr(FormatCurrent,2)}
  4319. else StoreStr(FormatCurrent + 3,2);
  4320. } else if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,3),"A\/P") === 0) {
  4321. Count = 3;
  4322. if (Hour < 12) {
  4323. StoreStr(FormatCurrent,1)}
  4324. else StoreStr(FormatCurrent + 2,1);
  4325. } else throw $mod.EConvertError.$create("Create$1",["Illegal character in format string"]);
  4326. } else if ($tmp2 === "\/") {
  4327. StoreString($mod.DateSeparator);
  4328. } else if ($tmp2 === ":") {
  4329. StoreString($mod.TimeSeparator)}
  4330. else if ((((((((((($tmp2 === " ") || ($tmp2 === "C")) || ($tmp2 === "D")) || ($tmp2 === "H")) || ($tmp2 === "M")) || ($tmp2 === "N")) || ($tmp2 === "S")) || ($tmp2 === "T")) || ($tmp2 === "Y")) || ($tmp2 === "Z")) || ($tmp2 === "F")) {
  4331. while ((P <= FormatEnd) && ($mod.UpperCase(FormatStr.charAt(P - 1)) === Token)) P += 1;
  4332. Count = P - FormatCurrent;
  4333. var $tmp3 = Token;
  4334. if ($tmp3 === " ") {
  4335. StoreStr(FormatCurrent,Count)}
  4336. else if ($tmp3 === "Y") {
  4337. if (Count > 2) {
  4338. StoreInt(Year,4)}
  4339. else StoreInt(Year % 100,2);
  4340. } else if ($tmp3 === "M") {
  4341. if (isInterval && ((prevlasttoken === "H") || TimeFlag)) {
  4342. StoreInt(Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60),0)}
  4343. else if ((lastformattoken === "H") || TimeFlag) {
  4344. if (Count === 1) {
  4345. StoreInt(Minute,0)}
  4346. else StoreInt(Minute,2);
  4347. } else {
  4348. var $tmp4 = Count;
  4349. if ($tmp4 === 1) {
  4350. StoreInt(Month,0)}
  4351. else if ($tmp4 === 2) {
  4352. StoreInt(Month,2)}
  4353. else if ($tmp4 === 3) {
  4354. StoreString($mod.ShortMonthNames[Month - 1])}
  4355. else {
  4356. StoreString($mod.LongMonthNames[Month - 1]);
  4357. };
  4358. };
  4359. } else if ($tmp3 === "D") {
  4360. var $tmp5 = Count;
  4361. if ($tmp5 === 1) {
  4362. StoreInt(Day,0)}
  4363. else if ($tmp5 === 2) {
  4364. StoreInt(Day,2)}
  4365. else if ($tmp5 === 3) {
  4366. StoreString($mod.ShortDayNames[DayOfWeek])}
  4367. else if ($tmp5 === 4) {
  4368. StoreString($mod.LongDayNames[DayOfWeek])}
  4369. else if ($tmp5 === 5) {
  4370. StoreFormat($mod.ShortDateFormat,Nesting + 1,false)}
  4371. else {
  4372. StoreFormat($mod.LongDateFormat,Nesting + 1,false);
  4373. };
  4374. } else if ($tmp3 === "H") {
  4375. if (isInterval) {
  4376. StoreInt(Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24),0)}
  4377. else if (Clock12) {
  4378. tmp = Hour % 12;
  4379. if (tmp === 0) tmp = 12;
  4380. if (Count === 1) {
  4381. StoreInt(tmp,0)}
  4382. else StoreInt(tmp,2);
  4383. } else {
  4384. if (Count === 1) {
  4385. StoreInt(Hour,0)}
  4386. else StoreInt(Hour,2);
  4387. }}
  4388. else if ($tmp3 === "N") {
  4389. if (isInterval) {
  4390. StoreInt(Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60),0)}
  4391. else if (Count === 1) {
  4392. StoreInt(Minute,0)}
  4393. else StoreInt(Minute,2)}
  4394. else if ($tmp3 === "S") {
  4395. if (isInterval) {
  4396. StoreInt(Second + ((Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60)) * 60),0)}
  4397. else if (Count === 1) {
  4398. StoreInt(Second,0)}
  4399. else StoreInt(Second,2)}
  4400. else if ($tmp3 === "Z") {
  4401. if (Count === 1) {
  4402. StoreInt(MilliSecond,0)}
  4403. else StoreInt(MilliSecond,3)}
  4404. else if ($tmp3 === "T") {
  4405. if (Count === 1) {
  4406. StoreFormat($mod.ShortTimeFormat,Nesting + 1,true)}
  4407. else StoreFormat($mod.LongTimeFormat,Nesting + 1,true)}
  4408. else if ($tmp3 === "C") {
  4409. StoreFormat($mod.ShortDateFormat,Nesting + 1,false);
  4410. if (((Hour !== 0) || (Minute !== 0)) || (Second !== 0)) {
  4411. StoreString(" ");
  4412. StoreFormat($mod.LongTimeFormat,Nesting + 1,true);
  4413. };
  4414. } else if ($tmp3 === "F") {
  4415. StoreFormat($mod.ShortDateFormat,Nesting + 1,false);
  4416. StoreString(" ");
  4417. StoreFormat($mod.LongTimeFormat,Nesting + 1,true);
  4418. };
  4419. prevlasttoken = lastformattoken;
  4420. lastformattoken = Token;
  4421. } else {
  4422. StoreString(Token);
  4423. };
  4424. FormatCurrent += Count;
  4425. };
  4426. };
  4427. $mod.DecodeDateFully(DateTime,{get: function () {
  4428. return Year;
  4429. }, set: function (v) {
  4430. Year = v;
  4431. }},{get: function () {
  4432. return Month;
  4433. }, set: function (v) {
  4434. Month = v;
  4435. }},{get: function () {
  4436. return Day;
  4437. }, set: function (v) {
  4438. Day = v;
  4439. }},{get: function () {
  4440. return DayOfWeek;
  4441. }, set: function (v) {
  4442. DayOfWeek = v;
  4443. }});
  4444. $mod.DecodeTime(DateTime,{get: function () {
  4445. return Hour;
  4446. }, set: function (v) {
  4447. Hour = v;
  4448. }},{get: function () {
  4449. return Minute;
  4450. }, set: function (v) {
  4451. Minute = v;
  4452. }},{get: function () {
  4453. return Second;
  4454. }, set: function (v) {
  4455. Second = v;
  4456. }},{get: function () {
  4457. return MilliSecond;
  4458. }, set: function (v) {
  4459. MilliSecond = v;
  4460. }});
  4461. if (FormatStr !== "") {
  4462. StoreFormat(FormatStr,0,false)}
  4463. else StoreFormat("C",0,false);
  4464. return Result;
  4465. };
  4466. this.TryStrToDate = function (S, Value) {
  4467. var Result = false;
  4468. Result = $mod.TryStrToDate$2(S,Value,$mod.ShortDateFormat,"\x00");
  4469. return Result;
  4470. };
  4471. this.TryStrToDate$1 = function (S, Value, separator) {
  4472. var Result = false;
  4473. Result = $mod.TryStrToDate$2(S,Value,$mod.ShortDateFormat,separator);
  4474. return Result;
  4475. };
  4476. this.TryStrToDate$2 = function (S, Value, useformat, separator) {
  4477. var Result = false;
  4478. var Msg = "";
  4479. Result = S.length !== 0;
  4480. if (Result) {
  4481. Value.set($impl.IntStrToDate({get: function () {
  4482. return Msg;
  4483. }, set: function (v) {
  4484. Msg = v;
  4485. }},S,useformat,separator));
  4486. Result = Msg === "";
  4487. };
  4488. return Result;
  4489. };
  4490. this.TryStrToTime = function (S, Value) {
  4491. var Result = false;
  4492. Result = $mod.TryStrToTime$1(S,Value,"\x00");
  4493. return Result;
  4494. };
  4495. this.TryStrToTime$1 = function (S, Value, separator) {
  4496. var Result = false;
  4497. var Msg = "";
  4498. Result = S.length !== 0;
  4499. if (Result) {
  4500. Value.set($impl.IntStrToTime({get: function () {
  4501. return Msg;
  4502. }, set: function (v) {
  4503. Msg = v;
  4504. }},S,S.length,separator));
  4505. Result = Msg === "";
  4506. };
  4507. return Result;
  4508. };
  4509. this.TryStrToDateTime = function (S, Value) {
  4510. var Result = false;
  4511. var I = 0;
  4512. var dtdate = 0.0;
  4513. var dttime = 0.0;
  4514. Result = false;
  4515. I = pas.System.Pos($mod.TimeSeparator,S);
  4516. if (I > 0) {
  4517. while ((I > 0) && (S.charAt(I - 1) !== " ")) I -= 1;
  4518. if (I > 0) {
  4519. if (!$mod.TryStrToDate(pas.System.Copy(S,1,I - 1),{get: function () {
  4520. return dtdate;
  4521. }, set: function (v) {
  4522. dtdate = v;
  4523. }})) return Result;
  4524. if (!$mod.TryStrToTime(pas.System.Copy(S,I + 1,S.length - I),{get: function () {
  4525. return dttime;
  4526. }, set: function (v) {
  4527. dttime = v;
  4528. }})) return Result;
  4529. Value.set($mod.ComposeDateTime(dtdate,dttime));
  4530. Result = true;
  4531. } else Result = $mod.TryStrToTime(S,Value);
  4532. } else Result = $mod.TryStrToDate(S,Value);
  4533. return Result;
  4534. };
  4535. this.StrToDateDef = function (S, Defvalue) {
  4536. var Result = 0.0;
  4537. Result = $mod.StrToDateDef$1(S,Defvalue,"\x00");
  4538. return Result;
  4539. };
  4540. this.StrToDateDef$1 = function (S, Defvalue, separator) {
  4541. var Result = 0.0;
  4542. if (!$mod.TryStrToDate$1(S,{get: function () {
  4543. return Result;
  4544. }, set: function (v) {
  4545. Result = v;
  4546. }},separator)) Result = Defvalue;
  4547. return Result;
  4548. };
  4549. this.StrToTimeDef = function (S, Defvalue) {
  4550. var Result = 0.0;
  4551. Result = $mod.StrToTimeDef$1(S,Defvalue,"\x00");
  4552. return Result;
  4553. };
  4554. this.StrToTimeDef$1 = function (S, Defvalue, separator) {
  4555. var Result = 0.0;
  4556. if (!$mod.TryStrToTime$1(S,{get: function () {
  4557. return Result;
  4558. }, set: function (v) {
  4559. Result = v;
  4560. }},separator)) Result = Defvalue;
  4561. return Result;
  4562. };
  4563. this.StrToDateTimeDef = function (S, Defvalue) {
  4564. var Result = 0.0;
  4565. if (!$mod.TryStrToDateTime(S,{get: function () {
  4566. return Result;
  4567. }, set: function (v) {
  4568. Result = v;
  4569. }})) Result = Defvalue;
  4570. return Result;
  4571. };
  4572. this.CurrentYear = function () {
  4573. var Result = 0;
  4574. Result = (new Date()).getFullYear();
  4575. return Result;
  4576. };
  4577. this.ReplaceTime = function (dati, NewTime) {
  4578. dati.set($mod.ComposeDateTime(dati.get(),NewTime));
  4579. };
  4580. this.ReplaceDate = function (DateTime, NewDate) {
  4581. var tmp = 0.0;
  4582. tmp = NewDate;
  4583. $mod.ReplaceTime({get: function () {
  4584. return tmp;
  4585. }, set: function (v) {
  4586. tmp = v;
  4587. }},DateTime.get());
  4588. DateTime.set(tmp);
  4589. };
  4590. this.FloatToDateTime = function (Value) {
  4591. var Result = 0.0;
  4592. if ((Value < $mod.MinDateTime) || (Value > $mod.MaxDateTime)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidDateTime,[$mod.FloatToStr(Value)]]);
  4593. Result = Value;
  4594. return Result;
  4595. };
  4596. this.CurrencyFormat = 0;
  4597. this.NegCurrFormat = 0;
  4598. this.CurrencyDecimals = 2;
  4599. this.CurrencyString = "$";
  4600. this.FloattoCurr = function (Value) {
  4601. var Result = 0;
  4602. if (!$mod.TryFloatToCurr(Value,{get: function () {
  4603. return Result;
  4604. }, set: function (v) {
  4605. Result = v;
  4606. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidCurrency,[$mod.FloatToStr(Value)]]);
  4607. return Result;
  4608. };
  4609. this.TryFloatToCurr = function (Value, AResult) {
  4610. var Result = false;
  4611. Result = ((Value * 10000) >= $mod.MinCurrency) && ((Value * 10000) <= $mod.MaxCurrency);
  4612. if (Result) AResult.set(Math.floor(Value * 10000));
  4613. return Result;
  4614. };
  4615. this.CurrToStr = function (Value) {
  4616. var Result = "";
  4617. Result = $mod.FloatToStrF(Value / 10000,$mod.TFloatFormat.ffGeneral,-1,0);
  4618. return Result;
  4619. };
  4620. this.StrToCurr = function (S) {
  4621. var Result = 0;
  4622. if (!$mod.TryStrToCurr(S,{get: function () {
  4623. return Result;
  4624. }, set: function (v) {
  4625. Result = v;
  4626. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidCurrency,[S]]);
  4627. return Result;
  4628. };
  4629. this.TryStrToCurr = function (S, Value) {
  4630. var Result = false;
  4631. var D = 0.0;
  4632. Result = $mod.TryStrToFloat(S,{get: function () {
  4633. return D;
  4634. }, set: function (v) {
  4635. D = v;
  4636. }});
  4637. if (Result) Value.set(Math.floor(D * 10000));
  4638. return Result;
  4639. };
  4640. this.StrToCurrDef = function (S, Default) {
  4641. var Result = 0;
  4642. var R = 0;
  4643. if ($mod.TryStrToCurr(S,{get: function () {
  4644. return R;
  4645. }, set: function (v) {
  4646. R = v;
  4647. }})) {
  4648. Result = R}
  4649. else Result = Default;
  4650. return Result;
  4651. };
  4652. this.GUID_NULL = new pas.System.TGuid({D1: 0x00000000, D2: 0x0000, D3: 0x0000, D4: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]});
  4653. this.Supports = function (Instance, AClass, Obj) {
  4654. var Result = false;
  4655. Result = ((Instance !== null) && (Instance.QueryInterface(pas.System.IObjectInstance,Obj) === 0)) && Obj.get().$class.InheritsFrom(AClass);
  4656. return Result;
  4657. };
  4658. this.Supports$1 = function (Instance, IID, Intf) {
  4659. var Result = false;
  4660. Result = (Instance !== null) && (Instance.QueryInterface(IID,Intf) === 0);
  4661. return Result;
  4662. };
  4663. this.Supports$2 = function (Instance, IID, Intf) {
  4664. var Result = false;
  4665. Result = (Instance !== null) && Instance.GetInterface(IID,Intf);
  4666. return Result;
  4667. };
  4668. this.Supports$3 = function (Instance, IID, Intf) {
  4669. var Result = false;
  4670. Result = (Instance !== null) && Instance.GetInterfaceByStr(IID,Intf);
  4671. return Result;
  4672. };
  4673. this.Supports$4 = function (Instance, AClass) {
  4674. var Result = false;
  4675. var Temp = null;
  4676. Result = $mod.Supports(Instance,AClass,{get: function () {
  4677. return Temp;
  4678. }, set: function (v) {
  4679. Temp = v;
  4680. }});
  4681. return Result;
  4682. };
  4683. this.Supports$5 = function (Instance, IID) {
  4684. var Result = false;
  4685. var Temp = null;
  4686. try {
  4687. Result = $mod.Supports$1(Instance,IID,{get: function () {
  4688. return Temp;
  4689. }, set: function (v) {
  4690. Temp = v;
  4691. }});
  4692. } finally {
  4693. rtl._Release(Temp);
  4694. };
  4695. return Result;
  4696. };
  4697. this.Supports$6 = function (Instance, IID) {
  4698. var Result = false;
  4699. var Temp = null;
  4700. Result = $mod.Supports$2(Instance,IID,{get: function () {
  4701. return Temp;
  4702. }, set: function (v) {
  4703. Temp = v;
  4704. }});
  4705. if (Temp && Temp.$kind==='com') Temp._Release();
  4706. return Result;
  4707. };
  4708. this.Supports$7 = function (Instance, IID) {
  4709. var Result = false;
  4710. var Temp = null;
  4711. Result = $mod.Supports$3(Instance,IID,{get: function () {
  4712. return Temp;
  4713. }, set: function (v) {
  4714. Temp = v;
  4715. }});
  4716. if (Temp && Temp.$kind==='com') Temp._Release();
  4717. return Result;
  4718. };
  4719. this.Supports$8 = function (AClass, IID) {
  4720. var Result = false;
  4721. var maps = undefined;
  4722. if (AClass === null) return false;
  4723. maps = AClass["$intfmaps"];
  4724. if (!maps) return false;
  4725. if (rtl.getObject(maps)[$mod.GUIDToString(IID)]) return true;
  4726. Result = false;
  4727. return Result;
  4728. };
  4729. this.Supports$9 = function (AClass, IID) {
  4730. var Result = false;
  4731. var maps = undefined;
  4732. if (AClass === null) return false;
  4733. maps = AClass["$intfmaps"];
  4734. if (!maps) return false;
  4735. if (rtl.getObject(maps)[$mod.UpperCase(IID)]) return true;
  4736. Result = false;
  4737. return Result;
  4738. };
  4739. this.TryStringToGUID = function (s, Guid) {
  4740. var Result = false;
  4741. var re = null;
  4742. if (s.length !== 38) return false;
  4743. re = new RegExp("^\\{[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\\}$");
  4744. Result = re.test(s);
  4745. if (!Result) {
  4746. Guid.get().D1 = 0;
  4747. return Result;
  4748. };
  4749. rtl.strToGUIDR(s,Guid.get());
  4750. Result = true;
  4751. return Result;
  4752. };
  4753. this.StringToGUID = function (S) {
  4754. var Result = new pas.System.TGuid();
  4755. if (!$mod.TryStringToGUID(S,{get: function () {
  4756. return Result;
  4757. }, set: function (v) {
  4758. Result = v;
  4759. }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidGUID,[S]]);
  4760. return Result;
  4761. };
  4762. this.GUIDToString = function (guid) {
  4763. var Result = "";
  4764. Result = rtl.guidrToStr(guid);
  4765. return Result;
  4766. };
  4767. this.IsEqualGUID = function (guid1, guid2) {
  4768. var Result = false;
  4769. var i = 0;
  4770. if (((guid1.D1 !== guid2.D1) || (guid1.D2 !== guid2.D2)) || (guid1.D3 !== guid2.D3)) return false;
  4771. for (i = 0; i <= 7; i++) if (guid1.D4[i] !== guid2.D4[i]) return false;
  4772. Result = true;
  4773. return Result;
  4774. };
  4775. this.GuidCase = function (guid, List) {
  4776. var Result = 0;
  4777. for (var $l1 = rtl.length(List) - 1; $l1 >= 0; $l1--) {
  4778. Result = $l1;
  4779. if ($mod.IsEqualGUID(guid,List[Result])) return Result;
  4780. };
  4781. Result = -1;
  4782. return Result;
  4783. };
  4784. $mod.$init = function () {
  4785. $mod.FormatSettings = $mod.TFormatSettings.$create("Create");
  4786. };
  4787. },null,function () {
  4788. "use strict";
  4789. var $mod = this;
  4790. var $impl = $mod.$impl;
  4791. $impl.SAbortError = "Operation aborted";
  4792. $impl.CheckBoolStrs = function () {
  4793. if (rtl.length($mod.TrueBoolStrs) === 0) {
  4794. $mod.TrueBoolStrs = rtl.arraySetLength($mod.TrueBoolStrs,"",1);
  4795. $mod.TrueBoolStrs[0] = "True";
  4796. };
  4797. if (rtl.length($mod.FalseBoolStrs) === 0) {
  4798. $mod.FalseBoolStrs = rtl.arraySetLength($mod.FalseBoolStrs,"",1);
  4799. $mod.FalseBoolStrs[0] = "False";
  4800. };
  4801. };
  4802. $impl.feInvalidFormat = 1;
  4803. $impl.feMissingArgument = 2;
  4804. $impl.feInvalidArgIndex = 3;
  4805. $impl.DoFormatError = function (ErrCode, fmt) {
  4806. var $tmp1 = ErrCode;
  4807. if ($tmp1 === 1) {
  4808. throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidFormat,[fmt]])}
  4809. else if ($tmp1 === 2) {
  4810. throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SArgumentMissing,[fmt]])}
  4811. else if ($tmp1 === 3) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidArgIndex,[fmt]]);
  4812. };
  4813. $impl.maxdigits = 15;
  4814. $impl.ReplaceDecimalSep = function (S, DS) {
  4815. var Result = "";
  4816. var P = 0;
  4817. P = pas.System.Pos(".",S);
  4818. if (P > 0) {
  4819. Result = (pas.System.Copy(S,1,P - 1) + DS) + pas.System.Copy(S,P + 1,S.length - P)}
  4820. else Result = S;
  4821. return Result;
  4822. };
  4823. $impl.FormatGeneralFloat = function (Value, Precision, DS) {
  4824. var Result = "";
  4825. var P = 0;
  4826. var PE = 0;
  4827. var Q = 0;
  4828. var Exponent = 0;
  4829. if ((Precision === -1) || (Precision > 15)) Precision = 15;
  4830. Result = rtl.floatToStr(Value,Precision + 7);
  4831. Result = $mod.TrimLeft(Result);
  4832. P = pas.System.Pos(".",Result);
  4833. if (P === 0) return Result;
  4834. PE = pas.System.Pos("E",Result);
  4835. if (PE === 0) {
  4836. Result = $impl.ReplaceDecimalSep(Result,DS);
  4837. return Result;
  4838. };
  4839. Q = PE + 2;
  4840. Exponent = 0;
  4841. while (Q <= Result.length) {
  4842. Exponent = ((Exponent * 10) + Result.charCodeAt(Q - 1)) - "0".charCodeAt();
  4843. Q += 1;
  4844. };
  4845. if (Result.charAt((PE + 1) - 1) === "-") Exponent = -Exponent;
  4846. if (((P + Exponent) < PE) && (Exponent > -6)) {
  4847. Result = rtl.strSetLength(Result,PE - 1);
  4848. if (Exponent >= 0) {
  4849. for (var $l1 = 0, $end2 = Exponent - 1; $l1 <= $end2; $l1++) {
  4850. Q = $l1;
  4851. Result = rtl.setCharAt(Result,P - 1,Result.charAt((P + 1) - 1));
  4852. P += 1;
  4853. };
  4854. Result = rtl.setCharAt(Result,P - 1,".");
  4855. P = 1;
  4856. if (Result.charAt(P - 1) === "-") P += 1;
  4857. while (((Result.charAt(P - 1) === "0") && (P < Result.length)) && (pas.System.Copy(Result,P + 1,DS.length) !== DS)) pas.System.Delete({get: function () {
  4858. return Result;
  4859. }, set: function (v) {
  4860. Result = v;
  4861. }},P,1);
  4862. } else {
  4863. pas.System.Insert(pas.System.Copy("00000",1,-Exponent),{get: function () {
  4864. return Result;
  4865. }, set: function (v) {
  4866. Result = v;
  4867. }},P - 1);
  4868. Result = rtl.setCharAt(Result,(P - Exponent) - 1,Result.charAt(((P - Exponent) - 1) - 1));
  4869. Result = rtl.setCharAt(Result,P - 1,".");
  4870. if (Exponent !== -1) Result = rtl.setCharAt(Result,((P - Exponent) - 1) - 1,"0");
  4871. };
  4872. Q = Result.length;
  4873. while ((Q > 0) && (Result.charAt(Q - 1) === "0")) Q -= 1;
  4874. if (Result.charAt(Q - 1) === ".") Q -= 1;
  4875. if ((Q === 0) || ((Q === 1) && (Result.charAt(0) === "-"))) {
  4876. Result = "0"}
  4877. else Result = rtl.strSetLength(Result,Q);
  4878. } else {
  4879. while (Result.charAt((PE - 1) - 1) === "0") {
  4880. pas.System.Delete({get: function () {
  4881. return Result;
  4882. }, set: function (v) {
  4883. Result = v;
  4884. }},PE - 1,1);
  4885. PE -= 1;
  4886. };
  4887. if (Result.charAt((PE - 1) - 1) === DS) {
  4888. pas.System.Delete({get: function () {
  4889. return Result;
  4890. }, set: function (v) {
  4891. Result = v;
  4892. }},PE - 1,1);
  4893. PE -= 1;
  4894. };
  4895. if (Result.charAt((PE + 1) - 1) === "+") {
  4896. pas.System.Delete({get: function () {
  4897. return Result;
  4898. }, set: function (v) {
  4899. Result = v;
  4900. }},PE + 1,1)}
  4901. else PE += 1;
  4902. while (Result.charAt((PE + 1) - 1) === "0") pas.System.Delete({get: function () {
  4903. return Result;
  4904. }, set: function (v) {
  4905. Result = v;
  4906. }},PE + 1,1);
  4907. };
  4908. Result = $impl.ReplaceDecimalSep(Result,DS);
  4909. return Result;
  4910. };
  4911. $impl.FormatExponentFloat = function (Value, Precision, Digits, DS) {
  4912. var Result = "";
  4913. var P = 0;
  4914. DS = $mod.DecimalSeparator;
  4915. if ((Precision === -1) || (Precision > 15)) Precision = 15;
  4916. Result = rtl.floatToStr(Value,Precision + 7);
  4917. while (Result.charAt(0) === " ") pas.System.Delete({get: function () {
  4918. return Result;
  4919. }, set: function (v) {
  4920. Result = v;
  4921. }},1,1);
  4922. P = pas.System.Pos("E",Result);
  4923. if (P === 0) {
  4924. Result = $impl.ReplaceDecimalSep(Result,DS);
  4925. return Result;
  4926. };
  4927. P += 2;
  4928. if (Digits > 4) Digits = 4;
  4929. Digits = ((Result.length - P) - Digits) + 1;
  4930. if (Digits < 0) {
  4931. pas.System.Insert(pas.System.Copy("0000",1,-Digits),{get: function () {
  4932. return Result;
  4933. }, set: function (v) {
  4934. Result = v;
  4935. }},P)}
  4936. else while ((Digits > 0) && (Result.charAt(P - 1) === "0")) {
  4937. pas.System.Delete({get: function () {
  4938. return Result;
  4939. }, set: function (v) {
  4940. Result = v;
  4941. }},P,1);
  4942. if (P > Result.length) {
  4943. pas.System.Delete({get: function () {
  4944. return Result;
  4945. }, set: function (v) {
  4946. Result = v;
  4947. }},P - 2,2);
  4948. break;
  4949. };
  4950. Digits -= 1;
  4951. };
  4952. Result = $impl.ReplaceDecimalSep(Result,DS);
  4953. return Result;
  4954. };
  4955. $impl.FormatFixedFloat = function (Value, Digits, DS) {
  4956. var Result = "";
  4957. if (Digits === -1) {
  4958. Digits = 2}
  4959. else if (Digits > 18) Digits = 18;
  4960. Result = rtl.floatToStr(Value,0,Digits);
  4961. if ((Result !== "") && (Result.charAt(0) === " ")) pas.System.Delete({get: function () {
  4962. return Result;
  4963. }, set: function (v) {
  4964. Result = v;
  4965. }},1,1);
  4966. Result = $impl.ReplaceDecimalSep(Result,DS);
  4967. return Result;
  4968. };
  4969. $impl.FormatNumberFloat = function (Value, Digits, DS, TS) {
  4970. var Result = "";
  4971. var P = 0;
  4972. if (Digits === -1) {
  4973. Digits = 2}
  4974. else if (Digits > 15) Digits = 15;
  4975. Result = rtl.floatToStr(Value,0,Digits);
  4976. if ((Result !== "") && (Result.charAt(0) === " ")) pas.System.Delete({get: function () {
  4977. return Result;
  4978. }, set: function (v) {
  4979. Result = v;
  4980. }},1,1);
  4981. P = pas.System.Pos(".",Result);
  4982. Result = $impl.ReplaceDecimalSep(Result,DS);
  4983. P -= 3;
  4984. if ((TS !== "") && (TS !== "\x00")) while (P > 1) {
  4985. if (Result.charAt((P - 1) - 1) !== "-") pas.System.Insert(TS,{get: function () {
  4986. return Result;
  4987. }, set: function (v) {
  4988. Result = v;
  4989. }},P);
  4990. P -= 3;
  4991. };
  4992. return Result;
  4993. };
  4994. $impl.RemoveLeadingNegativeSign = function (AValue, DS) {
  4995. var Result = false;
  4996. var i = 0;
  4997. var TS = "";
  4998. var StartPos = 0;
  4999. Result = false;
  5000. StartPos = 2;
  5001. TS = $mod.ThousandSeparator;
  5002. for (var $l1 = StartPos, $end2 = AValue.get().length; $l1 <= $end2; $l1++) {
  5003. i = $l1;
  5004. Result = (AValue.get().charCodeAt(i - 1) in rtl.createSet(48,DS.charCodeAt(),69,43)) || (AValue.get() === TS);
  5005. if (!Result) break;
  5006. };
  5007. if (Result) pas.System.Delete(AValue,1,1);
  5008. return Result;
  5009. };
  5010. $impl.FormatNumberCurrency = function (Value, Digits, DS, TS) {
  5011. var Result = "";
  5012. var Negative = false;
  5013. var P = 0;
  5014. if (Digits === -1) {
  5015. Digits = $mod.CurrencyDecimals}
  5016. else if (Digits > 18) Digits = 18;
  5017. Result = rtl.spaceLeft("" + Value,0);
  5018. Negative = Result.charAt(0) === "-";
  5019. if (Negative) pas.System.Delete({get: function () {
  5020. return Result;
  5021. }, set: function (v) {
  5022. Result = v;
  5023. }},1,1);
  5024. P = pas.System.Pos(".",Result);
  5025. if (P !== 0) {
  5026. Result = $impl.ReplaceDecimalSep(Result,DS)}
  5027. else P = Result.length + 1;
  5028. P -= 3;
  5029. while (P > 1) {
  5030. if ($mod.ThousandSeparator !== "\x00") pas.System.Insert($mod.FormatSettings.GetThousandSeparator(),{get: function () {
  5031. return Result;
  5032. }, set: function (v) {
  5033. Result = v;
  5034. }},P);
  5035. P -= 3;
  5036. };
  5037. if ((Result.length > 1) && Negative) Negative = !$impl.RemoveLeadingNegativeSign({get: function () {
  5038. return Result;
  5039. }, set: function (v) {
  5040. Result = v;
  5041. }},DS);
  5042. if (!Negative) {
  5043. var $tmp1 = $mod.CurrencyFormat;
  5044. if ($tmp1 === 0) {
  5045. Result = $mod.CurrencyString + Result}
  5046. else if ($tmp1 === 1) {
  5047. Result = Result + $mod.CurrencyString}
  5048. else if ($tmp1 === 2) {
  5049. Result = ($mod.CurrencyString + " ") + Result}
  5050. else if ($tmp1 === 3) Result = (Result + " ") + $mod.CurrencyString;
  5051. } else {
  5052. var $tmp2 = $mod.NegCurrFormat;
  5053. if ($tmp2 === 0) {
  5054. Result = (("(" + $mod.CurrencyString) + Result) + ")"}
  5055. else if ($tmp2 === 1) {
  5056. Result = ("-" + $mod.CurrencyString) + Result}
  5057. else if ($tmp2 === 2) {
  5058. Result = ($mod.CurrencyString + "-") + Result}
  5059. else if ($tmp2 === 3) {
  5060. Result = ($mod.CurrencyString + Result) + "-"}
  5061. else if ($tmp2 === 4) {
  5062. Result = (("(" + Result) + $mod.CurrencyString) + ")"}
  5063. else if ($tmp2 === 5) {
  5064. Result = ("-" + Result) + $mod.CurrencyString}
  5065. else if ($tmp2 === 6) {
  5066. Result = (Result + "-") + $mod.CurrencyString}
  5067. else if ($tmp2 === 7) {
  5068. Result = (Result + $mod.CurrencyString) + "-"}
  5069. else if ($tmp2 === 8) {
  5070. Result = (("-" + Result) + " ") + $mod.CurrencyString}
  5071. else if ($tmp2 === 9) {
  5072. Result = (("-" + $mod.CurrencyString) + " ") + Result}
  5073. else if ($tmp2 === 10) {
  5074. Result = ((Result + " ") + $mod.CurrencyString) + "-"}
  5075. else if ($tmp2 === 11) {
  5076. Result = (($mod.CurrencyString + " ") + Result) + "-"}
  5077. else if ($tmp2 === 12) {
  5078. Result = (($mod.CurrencyString + " ") + "-") + Result}
  5079. else if ($tmp2 === 13) {
  5080. Result = ((Result + "-") + " ") + $mod.CurrencyString}
  5081. else if ($tmp2 === 14) {
  5082. Result = ((("(" + $mod.CurrencyString) + " ") + Result) + ")"}
  5083. else if ($tmp2 === 15) Result = ((("(" + Result) + " ") + $mod.CurrencyString) + ")";
  5084. };
  5085. if (TS === "") ;
  5086. return Result;
  5087. };
  5088. $impl.RESpecials = "([\\[\\]\\(\\)\\\\\\.\\*])";
  5089. $impl.DoEncodeDate = function (Year, Month, Day) {
  5090. var Result = 0;
  5091. var D = 0.0;
  5092. if ($mod.TryEncodeDate(Year,Month,Day,{get: function () {
  5093. return D;
  5094. }, set: function (v) {
  5095. D = v;
  5096. }})) {
  5097. Result = pas.System.Trunc(D)}
  5098. else Result = 0;
  5099. return Result;
  5100. };
  5101. $impl.DoEncodeTime = function (Hour, Minute, Second, MilliSecond) {
  5102. var Result = 0.0;
  5103. if (!$mod.TryEncodeTime(Hour,Minute,Second,MilliSecond,{get: function () {
  5104. return Result;
  5105. }, set: function (v) {
  5106. Result = v;
  5107. }})) Result = 0;
  5108. return Result;
  5109. };
  5110. $impl.DateTimeToStrFormat = ["c","f"];
  5111. var WhiteSpace = " \b\t\n\f\r";
  5112. var Digits = "0123456789";
  5113. $impl.IntStrToDate = function (ErrorMsg, S, useformat, separator) {
  5114. var Result = 0.0;
  5115. function FixErrorMsg(errmarg) {
  5116. ErrorMsg.set($mod.Format(pas.RTLConsts.SInvalidDateFormat,[errmarg]));
  5117. };
  5118. var df = "";
  5119. var d = 0;
  5120. var m = 0;
  5121. var y = 0;
  5122. var ly = 0;
  5123. var ld = 0;
  5124. var lm = 0;
  5125. var n = 0;
  5126. var i = 0;
  5127. var len = 0;
  5128. var c = 0;
  5129. var dp = 0;
  5130. var mp = 0;
  5131. var yp = 0;
  5132. var which = 0;
  5133. var s1 = "";
  5134. var values = [];
  5135. var YearMoreThenTwoDigits = false;
  5136. values = rtl.arraySetLength(values,0,4);
  5137. Result = 0;
  5138. len = S.length;
  5139. ErrorMsg.set("");
  5140. while ((len > 0) && (pas.System.Pos(S.charAt(len - 1),WhiteSpace) > 0)) len -= 1;
  5141. if (len === 0) {
  5142. FixErrorMsg(S);
  5143. return Result;
  5144. };
  5145. YearMoreThenTwoDigits = false;
  5146. if (separator === "\x00") if ($mod.DateSeparator !== "\x00") {
  5147. separator = $mod.DateSeparator}
  5148. else separator = "-";
  5149. df = $mod.UpperCase(useformat);
  5150. yp = 0;
  5151. mp = 0;
  5152. dp = 0;
  5153. which = 0;
  5154. i = 0;
  5155. while ((i < df.length) && (which < 3)) {
  5156. i += 1;
  5157. var $tmp1 = df.charAt(i - 1);
  5158. if ($tmp1 === "Y") {
  5159. if (yp === 0) {
  5160. which += 1;
  5161. yp = which;
  5162. }}
  5163. else if ($tmp1 === "M") {
  5164. if (mp === 0) {
  5165. which += 1;
  5166. mp = which;
  5167. }}
  5168. else if ($tmp1 === "D") if (dp === 0) {
  5169. which += 1;
  5170. dp = which;
  5171. };
  5172. };
  5173. for (i = 1; i <= 3; i++) values[i] = 0;
  5174. s1 = "";
  5175. n = 0;
  5176. for (var $l2 = 1, $end3 = len; $l2 <= $end3; $l2++) {
  5177. i = $l2;
  5178. if (pas.System.Pos(S.charAt(i - 1),Digits) > 0) s1 = s1 + S.charAt(i - 1);
  5179. if ((separator !== " ") && (S.charAt(i - 1) === " ")) continue;
  5180. if ((S.charAt(i - 1) === separator) || ((i === len) && (pas.System.Pos(S.charAt(i - 1),Digits) > 0))) {
  5181. n += 1;
  5182. if (n > 3) {
  5183. FixErrorMsg(S);
  5184. return Result;
  5185. };
  5186. if ((n === yp) && (s1.length > 2)) YearMoreThenTwoDigits = true;
  5187. pas.System.val$5(s1,{a: n, p: values, get: function () {
  5188. return this.p[this.a];
  5189. }, set: function (v) {
  5190. this.p[this.a] = v;
  5191. }},{get: function () {
  5192. return c;
  5193. }, set: function (v) {
  5194. c = v;
  5195. }});
  5196. if (c !== 0) {
  5197. FixErrorMsg(S);
  5198. return Result;
  5199. };
  5200. s1 = "";
  5201. } else if (pas.System.Pos(S.charAt(i - 1),Digits) === 0) {
  5202. FixErrorMsg(S);
  5203. return Result;
  5204. };
  5205. };
  5206. if ((which < 3) && (n > which)) {
  5207. FixErrorMsg(S);
  5208. return Result;
  5209. };
  5210. $mod.DecodeDate($mod.date(),{get: function () {
  5211. return ly;
  5212. }, set: function (v) {
  5213. ly = v;
  5214. }},{get: function () {
  5215. return lm;
  5216. }, set: function (v) {
  5217. lm = v;
  5218. }},{get: function () {
  5219. return ld;
  5220. }, set: function (v) {
  5221. ld = v;
  5222. }});
  5223. if (n === 3) {
  5224. y = values[yp];
  5225. m = values[mp];
  5226. d = values[dp];
  5227. } else {
  5228. y = ly;
  5229. if (n < 2) {
  5230. d = values[1];
  5231. m = lm;
  5232. } else if (dp < mp) {
  5233. d = values[1];
  5234. m = values[2];
  5235. } else {
  5236. d = values[2];
  5237. m = values[1];
  5238. };
  5239. };
  5240. if (((y >= 0) && (y < 100)) && !YearMoreThenTwoDigits) {
  5241. ly = ly - $mod.TwoDigitYearCenturyWindow;
  5242. y += Math.floor(ly / 100) * 100;
  5243. if (($mod.TwoDigitYearCenturyWindow > 0) && (y < ly)) y += 100;
  5244. };
  5245. if (!$mod.TryEncodeDate(y,m,d,{get: function () {
  5246. return Result;
  5247. }, set: function (v) {
  5248. Result = v;
  5249. }})) ErrorMsg.set(pas.RTLConsts.SErrInvalidDate);
  5250. return Result;
  5251. };
  5252. var AMPM_None = 0;
  5253. var AMPM_AM = 1;
  5254. var AMPM_PM = 2;
  5255. var tiHour = 0;
  5256. var tiMin = 1;
  5257. var tiSec = 2;
  5258. var tiMSec = 3;
  5259. var Digits$1 = "0123456789";
  5260. $impl.IntStrToTime = function (ErrorMsg, S, Len, separator) {
  5261. var Result = 0.0;
  5262. var AmPm = 0;
  5263. var TimeValues = [];
  5264. function SplitElements(TimeValues, AmPm) {
  5265. var Result = false;
  5266. var Cur = 0;
  5267. var Offset = 0;
  5268. var ElemLen = 0;
  5269. var Err = 0;
  5270. var TimeIndex = 0;
  5271. var FirstSignificantDigit = 0;
  5272. var Value = 0;
  5273. var DigitPending = false;
  5274. var MSecPending = false;
  5275. var AmPmStr = "";
  5276. var CurChar = "";
  5277. var I = 0;
  5278. var allowedchars = "";
  5279. Result = false;
  5280. AmPm.set(0);
  5281. MSecPending = false;
  5282. TimeIndex = 0;
  5283. for (I = 0; I <= 3; I++) TimeValues.get()[I] = 0;
  5284. Cur = 1;
  5285. while ((Cur < Len) && (S.charAt(Cur - 1) === " ")) Cur += 1;
  5286. Offset = Cur;
  5287. if (((Cur > (Len - 1)) || (S.charAt(Cur - 1) === separator)) || (S.charAt(Cur - 1) === $mod.DecimalSeparator)) {
  5288. return Result;
  5289. };
  5290. DigitPending = pas.System.Pos(S.charAt(Cur - 1),Digits$1) > 0;
  5291. while (Cur <= Len) {
  5292. CurChar = S.charAt(Cur - 1);
  5293. if (pas.System.Pos(CurChar,Digits$1) > 0) {
  5294. if (!DigitPending || (TimeIndex > 3)) {
  5295. return Result;
  5296. };
  5297. Offset = Cur;
  5298. if (CurChar !== "0") {
  5299. FirstSignificantDigit = Offset}
  5300. else FirstSignificantDigit = -1;
  5301. while ((Cur < Len) && (pas.System.Pos(S.charAt((Cur + 1) - 1),Digits$1) > 0)) {
  5302. if ((FirstSignificantDigit === -1) && (S.charAt(Cur - 1) !== "0")) FirstSignificantDigit = Cur;
  5303. Cur += 1;
  5304. };
  5305. if (FirstSignificantDigit === -1) FirstSignificantDigit = Cur;
  5306. ElemLen = (1 + Cur) - FirstSignificantDigit;
  5307. if ((ElemLen <= 2) || ((ElemLen <= 3) && (TimeIndex === 3))) {
  5308. pas.System.val$5(pas.System.Copy(S,FirstSignificantDigit,ElemLen),{get: function () {
  5309. return Value;
  5310. }, set: function (v) {
  5311. Value = v;
  5312. }},{get: function () {
  5313. return Err;
  5314. }, set: function (v) {
  5315. Err = v;
  5316. }});
  5317. TimeValues.get()[TimeIndex] = Value;
  5318. TimeIndex += 1;
  5319. DigitPending = false;
  5320. } else {
  5321. return Result;
  5322. };
  5323. } else if (CurChar === " ") {}
  5324. else if (CurChar === separator) {
  5325. if (DigitPending || (TimeIndex > 2)) {
  5326. return Result;
  5327. };
  5328. DigitPending = true;
  5329. MSecPending = false;
  5330. } else if (CurChar === $mod.DecimalSeparator) {
  5331. if ((DigitPending || MSecPending) || (TimeIndex !== 3)) {
  5332. return Result;
  5333. };
  5334. DigitPending = true;
  5335. MSecPending = true;
  5336. } else {
  5337. if ((AmPm.get() !== 0) || DigitPending) {
  5338. return Result;
  5339. };
  5340. Offset = Cur;
  5341. allowedchars = $mod.DecimalSeparator + " ";
  5342. if (separator !== "\x00") allowedchars = allowedchars + separator;
  5343. while (((Cur < (Len - 1)) && (pas.System.Pos(S.charAt((Cur + 1) - 1),allowedchars) === 0)) && (pas.System.Pos(S.charAt((Cur + 1) - 1),Digits$1) === 0)) Cur += 1;
  5344. ElemLen = (1 + Cur) - Offset;
  5345. AmPmStr = pas.System.Copy(S,1 + Offset,ElemLen);
  5346. if ($mod.CompareText(AmPmStr,$mod.TimeAMString) === 0) {
  5347. AmPm.set(1)}
  5348. else if ($mod.CompareText(AmPmStr,$mod.TimePMString) === 0) {
  5349. AmPm.set(2)}
  5350. else if ($mod.CompareText(AmPmStr,"AM") === 0) {
  5351. AmPm.set(1)}
  5352. else if ($mod.CompareText(AmPmStr,"PM") === 0) {
  5353. AmPm.set(2)}
  5354. else {
  5355. return Result;
  5356. };
  5357. if (TimeIndex === 0) {
  5358. DigitPending = true;
  5359. } else {
  5360. TimeIndex = 3 + 1;
  5361. DigitPending = false;
  5362. };
  5363. };
  5364. Cur += 1;
  5365. };
  5366. if (((TimeIndex === 0) || ((AmPm.get() !== 0) && ((TimeValues.get()[0] > 12) || (TimeValues.get()[0] === 0)))) || DigitPending) return Result;
  5367. Result = true;
  5368. return Result;
  5369. };
  5370. TimeValues = rtl.arraySetLength(TimeValues,0,4);
  5371. if (separator === "\x00") if ($mod.TimeSeparator !== "\x00") {
  5372. separator = $mod.TimeSeparator}
  5373. else separator = ":";
  5374. AmPm = 0;
  5375. if (!SplitElements({get: function () {
  5376. return TimeValues;
  5377. }, set: function (v) {
  5378. TimeValues = v;
  5379. }},{get: function () {
  5380. return AmPm;
  5381. }, set: function (v) {
  5382. AmPm = v;
  5383. }})) {
  5384. ErrorMsg.set($mod.Format(pas.RTLConsts.SErrInvalidTimeFormat,[S]));
  5385. return Result;
  5386. };
  5387. if ((AmPm === 2) && (TimeValues[0] !== 12)) {
  5388. TimeValues[0] += 12}
  5389. else if ((AmPm === 1) && (TimeValues[0] === 12)) TimeValues[0] = 0;
  5390. if (!$mod.TryEncodeTime(TimeValues[0],TimeValues[1],TimeValues[2],TimeValues[3],{get: function () {
  5391. return Result;
  5392. }, set: function (v) {
  5393. Result = v;
  5394. }})) ErrorMsg.set($mod.Format(pas.RTLConsts.SErrInvalidTimeFormat,[S]));
  5395. return Result;
  5396. };
  5397. var WhiteSpace$1 = "\t\n\r ";
  5398. $impl.SplitDateTimeStr = function (DateTimeStr, DateStr, TimeStr) {
  5399. var Result = 0;
  5400. var p = 0;
  5401. var DummyDT = 0.0;
  5402. Result = 0;
  5403. DateStr.set("");
  5404. TimeStr.set("");
  5405. DateTimeStr = $mod.Trim(DateTimeStr);
  5406. if (DateTimeStr.length === 0) return Result;
  5407. if ((($mod.DateSeparator === " ") && ($mod.TimeSeparator === " ")) && (pas.System.Pos(" ",DateTimeStr) > 0)) {
  5408. DateStr.set(DateTimeStr);
  5409. return 1;
  5410. };
  5411. p = 1;
  5412. if ($mod.DateSeparator !== " ") {
  5413. while ((p < DateTimeStr.length) && !(pas.System.Pos(DateTimeStr.charAt((p + 1) - 1),WhiteSpace$1) > 0)) p += 1;
  5414. } else {
  5415. p = pas.System.Pos($mod.TimeSeparator,DateTimeStr);
  5416. if (p !== 0) do {
  5417. p -= 1;
  5418. } while (!((p === 0) || (pas.System.Pos(DateTimeStr.charAt(p - 1),WhiteSpace$1) > 0)));
  5419. };
  5420. if (p === 0) p = DateTimeStr.length;
  5421. DateStr.set(pas.System.Copy(DateTimeStr,1,p));
  5422. TimeStr.set($mod.Trim(pas.System.Copy(DateTimeStr,p + 1,100)));
  5423. if (TimeStr.get().length !== 0) {
  5424. Result = 2}
  5425. else {
  5426. Result = 1;
  5427. if ((($mod.DateSeparator !== $mod.TimeSeparator) && (pas.System.Pos($mod.TimeSeparator,DateStr.get()) > 0)) || (($mod.DateSeparator === $mod.TimeSeparator) && !$mod.TryStrToDate(DateStr.get(),{get: function () {
  5428. return DummyDT;
  5429. }, set: function (v) {
  5430. DummyDT = v;
  5431. }}))) {
  5432. TimeStr.set(DateStr.get());
  5433. DateStr.set("");
  5434. };
  5435. };
  5436. return Result;
  5437. };
  5438. });
  5439. rtl.module("math",["System","SysUtils"],function () {
  5440. "use strict";
  5441. var $mod = this;
  5442. var $impl = $mod.$impl;
  5443. this.MinInteger = -0x10000000000000;
  5444. this.MaxInteger = 0xfffffffffffff;
  5445. this.MinDouble = 5.0e-324;
  5446. this.MaxDouble = 1.7e+308;
  5447. this.InRange = function (AValue, AMin, AMax) {
  5448. return (AValue >= AMin) && (AValue <= AMax);
  5449. };
  5450. this.InRange$1 = function (AValue, AMin, AMax) {
  5451. return (AValue >= AMin) && (AValue <= AMax);
  5452. };
  5453. this.EnsureRange = function (AValue, AMin, AMax) {
  5454. if (AValue<AMin){ return AMin;
  5455. } else if (AValue>AMax){ return AMax;
  5456. } else return AValue;
  5457. };
  5458. this.EnsureRange$1 = function (AValue, AMin, AMax) {
  5459. if (AValue<AMin){ return AMin;
  5460. } else if (AValue>AMax){ return AMax;
  5461. } else return AValue;
  5462. };
  5463. this.RoundTo = function (AValue, Digits) {
  5464. var Result = 0.0;
  5465. var RV = 0.0;
  5466. RV = $mod.IntPower(10,Digits);
  5467. Result = Math.round(AValue / RV) * RV;
  5468. return Result;
  5469. };
  5470. this.SimpleRoundTo = function (AValue, Digits) {
  5471. var Result = 0.0;
  5472. var RV = 0.0;
  5473. RV = $mod.IntPower(10,-Digits);
  5474. if (AValue < 0) {
  5475. Result = pas.System.Int((AValue * RV) - 0.5) / RV}
  5476. else Result = pas.System.Int((AValue * RV) + 0.5) / RV;
  5477. return Result;
  5478. };
  5479. this.randg = function (mean, stddev) {
  5480. var Result = 0.0;
  5481. var U1 = 0.0;
  5482. var S2 = 0.0;
  5483. do {
  5484. U1 = (2 * Math.random()) - 1;
  5485. S2 = pas.System.Sqr$1(U1) + pas.System.Sqr$1((2 * Math.random()) - 1);
  5486. } while (!(S2 < 1));
  5487. Result = ((Math.sqrt((-2 * Math.log(S2)) / S2) * U1) * stddev) + mean;
  5488. return Result;
  5489. };
  5490. this.RandomRange = function (aFrom, aTo) {
  5491. var Result = 0;
  5492. Result = pas.System.Random(Math.abs(aFrom - aTo)) + Math.min(aTo,aFrom);
  5493. return Result;
  5494. };
  5495. this.RandomRange$1 = function (aFrom, aTo) {
  5496. var Result = 0;
  5497. var m = 0;
  5498. if (aFrom < aTo) {
  5499. m = aFrom}
  5500. else m = aTo;
  5501. Result = pas.System.Random(Math.abs(aFrom - aTo)) + m;
  5502. return Result;
  5503. };
  5504. this.NegativeValue = -1;
  5505. this.ZeroValue = 0;
  5506. this.PositiveValue = 1;
  5507. this.IsZero = function (d, Epsilon) {
  5508. var Result = false;
  5509. if (Epsilon === 0) Epsilon = 1E-12;
  5510. Result = Math.abs(d) <= Epsilon;
  5511. return Result;
  5512. };
  5513. this.IsZero$1 = function (d) {
  5514. var Result = false;
  5515. Result = Math.abs(d) <= 1E-12;
  5516. return Result;
  5517. };
  5518. this.IsInfinite = function (d) {
  5519. return (d==Infinite) || (d==-Infinite);
  5520. };
  5521. this.SameValue = function (A, B, Epsilon) {
  5522. var Result = false;
  5523. if (Epsilon === 0.0) Epsilon = Math.max(Math.min(Math.abs(A),Math.abs(B)) * 1E-12,1E-12);
  5524. if (A > B) {
  5525. Result = (A - B) <= Epsilon}
  5526. else Result = (B - A) <= Epsilon;
  5527. return Result;
  5528. };
  5529. this.LogN = function (A, Base) {
  5530. var Result = 0.0;
  5531. Result = Math.log(A) / Math.log(Base);
  5532. return Result;
  5533. };
  5534. this.Ceil = function (A) {
  5535. var Result = 0;
  5536. Result = pas.System.Trunc(Math.ceil(A));
  5537. return Result;
  5538. };
  5539. this.Floor = function (A) {
  5540. var Result = 0;
  5541. Result = pas.System.Trunc(Math.floor(A));
  5542. return Result;
  5543. };
  5544. this.Ceil64 = function (A) {
  5545. var Result = 0;
  5546. Result = pas.System.Trunc(Math.ceil(A));
  5547. return Result;
  5548. };
  5549. this.Floor64 = function (A) {
  5550. var Result = 0;
  5551. Result = pas.System.Trunc(Math.ceil(A));
  5552. return Result;
  5553. };
  5554. this.ldexp = function (x, p) {
  5555. var Result = 0.0;
  5556. Result = x * $mod.IntPower(2.0,p);
  5557. return Result;
  5558. };
  5559. this.Frexp = function (X, Mantissa, Exponent) {
  5560. Exponent.set(0);
  5561. if (X !== 0) if (Math.abs(X) < 0.5) {
  5562. do {
  5563. X = X * 2;
  5564. Exponent.set(Exponent.get() - 1);
  5565. } while (!(Math.abs(X) >= 0.5))}
  5566. else while (Math.abs(X) >= 1) {
  5567. X = X / 2;
  5568. Exponent.set(Exponent.get() + 1);
  5569. };
  5570. Mantissa.set(X);
  5571. };
  5572. this.lnxp1 = function (x) {
  5573. var Result = 0.0;
  5574. var y = 0.0;
  5575. if (x >= 4.0) {
  5576. Result = Math.log(1.0 + x)}
  5577. else {
  5578. y = 1.0 + x;
  5579. if (y === 1.0) {
  5580. Result = x}
  5581. else {
  5582. Result = Math.log(y);
  5583. if (y > 0.0) Result = Result + ((x - (y - 1.0)) / y);
  5584. };
  5585. };
  5586. return Result;
  5587. };
  5588. this.IntPower = function (base, exponent) {
  5589. var Result = 0.0;
  5590. var i = 0;
  5591. if ((base === 0.0) && (exponent === 0)) {
  5592. Result = 1}
  5593. else {
  5594. i = Math.abs(exponent);
  5595. Result = 1.0;
  5596. while (i > 0) {
  5597. while ((i & 1) === 0) {
  5598. i = i >>> 1;
  5599. base = pas.System.Sqr$1(base);
  5600. };
  5601. i = i - 1;
  5602. Result = Result * base;
  5603. };
  5604. if (exponent < 0) Result = 1.0 / Result;
  5605. };
  5606. return Result;
  5607. };
  5608. this.DivMod = function (Dividend, Divisor, Result, Remainder) {
  5609. if (Dividend < 0) {
  5610. Dividend = -Dividend;
  5611. Result.set(-Math.floor(Dividend / Divisor));
  5612. Remainder.set(-(Dividend + (Result.get() * Divisor)));
  5613. } else {
  5614. Result.set(Math.floor(Dividend / Divisor));
  5615. Remainder.set(Dividend - (Result.get() * Divisor));
  5616. };
  5617. };
  5618. this.DivMod$1 = function (Dividend, Divisor, Result, Remainder) {
  5619. if (Dividend < 0) {
  5620. Dividend = -Dividend;
  5621. Result.set(-Math.floor(Dividend / Divisor));
  5622. Remainder.set(-(Dividend + (Result.get() * Divisor)));
  5623. } else {
  5624. Result.set(Math.floor(Dividend / Divisor));
  5625. Remainder.set(Dividend - (Result.get() * Divisor));
  5626. };
  5627. };
  5628. this.DivMod$2 = function (Dividend, Divisor, Result, Remainder) {
  5629. Result.set(Math.floor(Dividend / Divisor));
  5630. Remainder.set(Dividend - (Result.get() * Divisor));
  5631. };
  5632. this.DivMod$3 = function (Dividend, Divisor, Result, Remainder) {
  5633. if (Dividend < 0) {
  5634. Dividend = -Dividend;
  5635. Result.set(-Math.floor(Dividend / Divisor));
  5636. Remainder.set(-(Dividend + (Result.get() * Divisor)));
  5637. } else {
  5638. Result.set(Math.floor(Dividend / Divisor));
  5639. Remainder.set(Dividend - (Result.get() * Divisor));
  5640. };
  5641. };
  5642. this.DegToRad = function (deg) {
  5643. var Result = 0.0;
  5644. Result = deg * (Math.PI / 180.0);
  5645. return Result;
  5646. };
  5647. this.RadToDeg = function (rad) {
  5648. var Result = 0.0;
  5649. Result = rad * (180.0 / Math.PI);
  5650. return Result;
  5651. };
  5652. this.GradToRad = function (grad) {
  5653. var Result = 0.0;
  5654. Result = grad * (Math.PI / 200.0);
  5655. return Result;
  5656. };
  5657. this.RadToGrad = function (rad) {
  5658. var Result = 0.0;
  5659. Result = rad * (200.0 / Math.PI);
  5660. return Result;
  5661. };
  5662. this.DegToGrad = function (deg) {
  5663. var Result = 0.0;
  5664. Result = deg * (200.0 / 180.0);
  5665. return Result;
  5666. };
  5667. this.GradToDeg = function (grad) {
  5668. var Result = 0.0;
  5669. Result = grad * (180.0 / 200.0);
  5670. return Result;
  5671. };
  5672. this.CycleToRad = function (cycle) {
  5673. var Result = 0.0;
  5674. Result = (2 * Math.PI) * cycle;
  5675. return Result;
  5676. };
  5677. this.RadToCycle = function (rad) {
  5678. var Result = 0.0;
  5679. Result = rad * (1 / (2 * Math.PI));
  5680. return Result;
  5681. };
  5682. this.DegNormalize = function (deg) {
  5683. var Result = 0.0;
  5684. Result = deg - (pas.System.Int(deg / 360) * 360);
  5685. if (Result < 0) Result = Result + 360;
  5686. return Result;
  5687. };
  5688. this.Norm = function (data) {
  5689. var Result = 0.0;
  5690. Result = Math.sqrt($impl.sumofsquares(data));
  5691. return Result;
  5692. };
  5693. this.Mean = function (data) {
  5694. var Result = 0.0;
  5695. var N = 0;
  5696. N = rtl.length(data);
  5697. if (N === 0) {
  5698. Result = 0}
  5699. else Result = $mod.Sum(data) / N;
  5700. return Result;
  5701. };
  5702. this.Sum = function (data) {
  5703. var Result = 0.0;
  5704. var i = 0;
  5705. var N = 0;
  5706. N = rtl.length(data);
  5707. Result = 0.0;
  5708. for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
  5709. i = $l1;
  5710. Result = Result + data[i];
  5711. };
  5712. return Result;
  5713. };
  5714. this.SumsAndSquares = function (data, Sum, SumOfSquares) {
  5715. var i = 0;
  5716. var n = 0;
  5717. var t = 0.0;
  5718. var s = 0.0;
  5719. var ss = 0.0;
  5720. n = rtl.length(data);
  5721. ss = 0.0;
  5722. s = 0.0;
  5723. for (var $l1 = 0, $end2 = n - 1; $l1 <= $end2; $l1++) {
  5724. i = $l1;
  5725. t = data[i];
  5726. ss = ss + pas.System.Sqr$1(t);
  5727. s = s + t;
  5728. };
  5729. Sum.set(s);
  5730. SumOfSquares.set(ss);
  5731. };
  5732. this.StdDev = function (data) {
  5733. var Result = 0.0;
  5734. Result = Math.sqrt($mod.Variance(data));
  5735. return Result;
  5736. };
  5737. this.MeanAndStdDev = function (data, Mean, StdDev) {
  5738. var I = 0;
  5739. var N = 0;
  5740. var M = 0.0;
  5741. var S = 0.0;
  5742. N = rtl.length(data);
  5743. M = 0;
  5744. S = 0;
  5745. for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
  5746. I = $l1;
  5747. M = M + data[I];
  5748. S = S + pas.System.Sqr$1(data[I]);
  5749. };
  5750. M = M / N;
  5751. S = S - (N * pas.System.Sqr$1(M));
  5752. if (N > 1) {
  5753. S = Math.sqrt(S / (N - 1))}
  5754. else S = 0;
  5755. Mean.set(M);
  5756. StdDev.set(S);
  5757. };
  5758. this.Variance = function (data) {
  5759. var Result = 0.0;
  5760. var n = 0;
  5761. n = rtl.length(data);
  5762. if (n === 1) {
  5763. Result = 0}
  5764. else Result = $mod.TotalVariance(data) / (n - 1);
  5765. return Result;
  5766. };
  5767. this.TotalVariance = function (data) {
  5768. var Result = 0.0;
  5769. var S = 0.0;
  5770. var SS = 0.0;
  5771. var N = 0;
  5772. N = rtl.length(data);
  5773. if (rtl.length(data) === 1) {
  5774. Result = 0}
  5775. else {
  5776. $mod.SumsAndSquares(data,{get: function () {
  5777. return S;
  5778. }, set: function (v) {
  5779. S = v;
  5780. }},{get: function () {
  5781. return SS;
  5782. }, set: function (v) {
  5783. SS = v;
  5784. }});
  5785. Result = SS - (pas.System.Sqr$1(S) / N);
  5786. };
  5787. return Result;
  5788. };
  5789. this.PopNStdDev = function (data) {
  5790. var Result = 0.0;
  5791. Result = Math.sqrt($mod.PopNVariance(data));
  5792. return Result;
  5793. };
  5794. this.PopNVariance = function (data) {
  5795. var Result = 0.0;
  5796. var N = 0;
  5797. N = rtl.length(data);
  5798. if (N === 0) {
  5799. Result = 0}
  5800. else Result = $mod.TotalVariance(data) / N;
  5801. return Result;
  5802. };
  5803. this.MomentSkewKurtosis = function (data, m1, m2, m3, m4, skew, kurtosis) {
  5804. var i = 0;
  5805. var N = 0;
  5806. var deviation = 0.0;
  5807. var deviation2 = 0.0;
  5808. var reciprocalN = 0.0;
  5809. var lm1 = 0.0;
  5810. var lm2 = 0.0;
  5811. var lm3 = 0.0;
  5812. var lm4 = 0.0;
  5813. var lskew = 0.0;
  5814. var lkurtosis = 0.0;
  5815. N = rtl.length(data);
  5816. lm1 = 0;
  5817. reciprocalN = 1 / N;
  5818. for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
  5819. i = $l1;
  5820. lm1 = lm1 + data[i];
  5821. };
  5822. lm1 = reciprocalN * lm1;
  5823. lm2 = 0;
  5824. lm3 = 0;
  5825. lm4 = 0;
  5826. for (var $l3 = 0, $end4 = N - 1; $l3 <= $end4; $l3++) {
  5827. i = $l3;
  5828. deviation = data[i] - lm1;
  5829. deviation2 = deviation * deviation;
  5830. lm2 = lm2 + deviation2;
  5831. lm3 = lm3 + (deviation2 * deviation);
  5832. lm4 = lm4 + (deviation2 * deviation2);
  5833. };
  5834. lm2 = reciprocalN * lm2;
  5835. lm3 = reciprocalN * lm3;
  5836. lm4 = reciprocalN * lm4;
  5837. lskew = lm3 / (Math.sqrt(lm2) * lm2);
  5838. lkurtosis = lm4 / (lm2 * lm2);
  5839. m1.set(lm1);
  5840. m2.set(lm2);
  5841. m3.set(lm3);
  5842. m4.set(lm4);
  5843. skew.set(lskew);
  5844. kurtosis.set(lkurtosis);
  5845. };
  5846. this.TPaymentTime = {"0": "ptEndOfPeriod", ptEndOfPeriod: 0, "1": "ptStartOfPeriod", ptStartOfPeriod: 1};
  5847. this.FutureValue = function (ARate, NPeriods, APayment, APresentValue, APaymentTime) {
  5848. var Result = 0.0;
  5849. var q = 0.0;
  5850. var qn = 0.0;
  5851. var factor = 0.0;
  5852. if (ARate === 0) {
  5853. Result = -APresentValue - (APayment * NPeriods)}
  5854. else {
  5855. q = 1.0 + ARate;
  5856. qn = Math.pow(q,NPeriods);
  5857. factor = (qn - 1) / (q - 1);
  5858. if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
  5859. Result = -((APresentValue * qn) + (APayment * factor));
  5860. };
  5861. return Result;
  5862. };
  5863. var DELTA = 0.001;
  5864. var EPS = 1E-9;
  5865. var MAXIT = 20;
  5866. this.InterestRate = function (NPeriods, APayment, APresentValue, AFutureValue, APaymentTime) {
  5867. var Result = 0.0;
  5868. var r1 = 0.0;
  5869. var r2 = 0.0;
  5870. var dr = 0.0;
  5871. var fv1 = 0.0;
  5872. var fv2 = 0.0;
  5873. var iteration = 0;
  5874. iteration = 0;
  5875. r1 = 0.05;
  5876. do {
  5877. r2 = r1 + 0.001;
  5878. fv1 = $mod.FutureValue(r1,NPeriods,APayment,APresentValue,APaymentTime);
  5879. fv2 = $mod.FutureValue(r2,NPeriods,APayment,APresentValue,APaymentTime);
  5880. dr = ((AFutureValue - fv1) / (fv2 - fv1)) * 0.001;
  5881. r1 = r1 + dr;
  5882. iteration += 1;
  5883. } while (!((Math.abs(dr) < 1.0E-9) || (iteration >= 20)));
  5884. Result = r1;
  5885. return Result;
  5886. };
  5887. this.NumberOfPeriods = function (ARate, APayment, APresentValue, AFutureValue, APaymentTime) {
  5888. var Result = 0.0;
  5889. var q = 0.0;
  5890. var x1 = 0.0;
  5891. var x2 = 0.0;
  5892. if (ARate === 0) {
  5893. Result = -(APresentValue + AFutureValue) / APayment}
  5894. else {
  5895. q = 1.0 + ARate;
  5896. if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) APayment = APayment * q;
  5897. x1 = APayment - (AFutureValue * ARate);
  5898. x2 = APayment + (APresentValue * ARate);
  5899. if ((x2 === 0) || ((Math.sign(x1) * Math.sign(x2)) < 0)) {
  5900. Result = Infinity}
  5901. else {
  5902. Result = Math.log(x1 / x2) / Math.log(q);
  5903. };
  5904. };
  5905. return Result;
  5906. };
  5907. this.Payment = function (ARate, NPeriods, APresentValue, AFutureValue, APaymentTime) {
  5908. var Result = 0.0;
  5909. var q = 0.0;
  5910. var qn = 0.0;
  5911. var factor = 0.0;
  5912. if (ARate === 0) {
  5913. Result = -(AFutureValue + APresentValue) / NPeriods}
  5914. else {
  5915. q = 1.0 + ARate;
  5916. qn = Math.pow(q,NPeriods);
  5917. factor = (qn - 1) / (q - 1);
  5918. if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
  5919. Result = -(AFutureValue + (APresentValue * qn)) / factor;
  5920. };
  5921. return Result;
  5922. };
  5923. this.PresentValue = function (ARate, NPeriods, APayment, AFutureValue, APaymentTime) {
  5924. var Result = 0.0;
  5925. var q = 0.0;
  5926. var qn = 0.0;
  5927. var factor = 0.0;
  5928. if (ARate === 0.0) {
  5929. Result = -AFutureValue - (APayment * NPeriods)}
  5930. else {
  5931. q = 1.0 + ARate;
  5932. qn = Math.pow(q,NPeriods);
  5933. factor = (qn - 1) / (q - 1);
  5934. if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
  5935. Result = -(AFutureValue + (APayment * factor)) / qn;
  5936. };
  5937. return Result;
  5938. };
  5939. this.IfThen = function (val, ifTrue, ifFalse) {
  5940. var Result = 0;
  5941. if (val) {
  5942. Result = ifTrue}
  5943. else Result = ifFalse;
  5944. return Result;
  5945. };
  5946. this.IfThen$1 = function (val, ifTrue, ifFalse) {
  5947. var Result = 0.0;
  5948. if (val) {
  5949. Result = ifTrue}
  5950. else Result = ifFalse;
  5951. return Result;
  5952. };
  5953. this.EqualsValue = 0;
  5954. this.LessThanValue = -1;
  5955. this.GreaterThanValue = 1;
  5956. this.CompareValue = function (A, B) {
  5957. var Result = -1;
  5958. Result = 1;
  5959. if (A === B) {
  5960. Result = 0}
  5961. else if (A < B) Result = -1;
  5962. return Result;
  5963. };
  5964. this.CompareValue$1 = function (A, B) {
  5965. var Result = -1;
  5966. Result = 1;
  5967. if (A === B) {
  5968. Result = 0}
  5969. else if (A < B) Result = -1;
  5970. return Result;
  5971. };
  5972. this.CompareValue$2 = function (A, B) {
  5973. var Result = -1;
  5974. Result = 1;
  5975. if (A === B) {
  5976. Result = 0}
  5977. else if (A < B) Result = -1;
  5978. return Result;
  5979. };
  5980. this.CompareValue$3 = function (A, B, delta) {
  5981. var Result = -1;
  5982. Result = 1;
  5983. if (Math.abs(A - B) <= delta) {
  5984. Result = 0}
  5985. else if (A < B) Result = -1;
  5986. return Result;
  5987. };
  5988. },null,function () {
  5989. "use strict";
  5990. var $mod = this;
  5991. var $impl = $mod.$impl;
  5992. $impl.DZeroResolution = 1E-12;
  5993. $impl.sumofsquares = function (data) {
  5994. var Result = 0.0;
  5995. var i = 0;
  5996. var N = 0;
  5997. N = rtl.length(data);
  5998. Result = 0.0;
  5999. for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
  6000. i = $l1;
  6001. Result = Result + pas.System.Sqr$1(data[i]);
  6002. };
  6003. return Result;
  6004. };
  6005. });
  6006. rtl.module("Mat4",["System","vectors","browserconsole","JS","webgl"],function () {
  6007. "use strict";
  6008. var $mod = this;
  6009. var $impl = $mod.$impl;
  6010. rtl.createClass($mod,"TMat4",pas.System.TObject,function () {
  6011. this.$init = function () {
  6012. pas.System.TObject.$init.call(this);
  6013. this.RawComponents = rtl.arraySetLength(null,0.0,4,4);
  6014. };
  6015. this.$final = function () {
  6016. this.RawComponents = undefined;
  6017. pas.System.TObject.$final.call(this);
  6018. };
  6019. this.Identity = function () {
  6020. this.RawComponents[0][0] = 1.0;
  6021. this.RawComponents[0][1] = 0.0;
  6022. this.RawComponents[0][2] = 0.0;
  6023. this.RawComponents[0][3] = 0.0;
  6024. this.RawComponents[1][0] = 0.0;
  6025. this.RawComponents[1][1] = 1.0;
  6026. this.RawComponents[1][2] = 0.0;
  6027. this.RawComponents[1][3] = 0.0;
  6028. this.RawComponents[2][0] = 0.0;
  6029. this.RawComponents[2][1] = 0.0;
  6030. this.RawComponents[2][2] = 1.0;
  6031. this.RawComponents[2][3] = 0.0;
  6032. this.RawComponents[3][0] = 0.0;
  6033. this.RawComponents[3][1] = 0.0;
  6034. this.RawComponents[3][2] = 0.0;
  6035. this.RawComponents[3][3] = 1.0;
  6036. };
  6037. this.Translate = function (tx, ty, tz) {
  6038. this.RawComponents[0][0] = 1.0;
  6039. this.RawComponents[0][1] = 0.0;
  6040. this.RawComponents[0][2] = 0.0;
  6041. this.RawComponents[0][3] = 0.0;
  6042. this.RawComponents[1][0] = 0.0;
  6043. this.RawComponents[1][1] = 1.0;
  6044. this.RawComponents[1][2] = 0.0;
  6045. this.RawComponents[1][3] = 0.0;
  6046. this.RawComponents[2][0] = 0.0;
  6047. this.RawComponents[2][1] = 0.0;
  6048. this.RawComponents[2][2] = 1.0;
  6049. this.RawComponents[2][3] = 0.0;
  6050. this.RawComponents[3][0] = tx;
  6051. this.RawComponents[3][1] = ty;
  6052. this.RawComponents[3][2] = tz;
  6053. this.RawComponents[3][3] = 1.0;
  6054. };
  6055. this.RotateZ = function (Angle) {
  6056. $mod.SinCos(Angle,{a: 1, p: this.RawComponents[0], get: function () {
  6057. return this.p[this.a];
  6058. }, set: function (v) {
  6059. this.p[this.a] = v;
  6060. }},{a: 0, p: this.RawComponents[0], get: function () {
  6061. return this.p[this.a];
  6062. }, set: function (v) {
  6063. this.p[this.a] = v;
  6064. }});
  6065. this.RawComponents[0][2] = 0.0;
  6066. this.RawComponents[0][3] = 0.0;
  6067. this.RawComponents[1][0] = -this.RawComponents[0][1];
  6068. this.RawComponents[1][1] = this.RawComponents[0][0];
  6069. this.RawComponents[1][2] = 0.0;
  6070. this.RawComponents[1][3] = 0.0;
  6071. this.RawComponents[2][0] = 0.0;
  6072. this.RawComponents[2][1] = 0.0;
  6073. this.RawComponents[2][2] = 1.0;
  6074. this.RawComponents[2][3] = 0.0;
  6075. this.RawComponents[3][0] = 0.0;
  6076. this.RawComponents[3][1] = 0.0;
  6077. this.RawComponents[3][2] = 0.0;
  6078. this.RawComponents[3][3] = 1.0;
  6079. };
  6080. this.RotateY = function (Angle) {
  6081. $mod.SinCos(Angle,{a: 0, p: this.RawComponents[2], get: function () {
  6082. return this.p[this.a];
  6083. }, set: function (v) {
  6084. this.p[this.a] = v;
  6085. }},{a: 0, p: this.RawComponents[0], get: function () {
  6086. return this.p[this.a];
  6087. }, set: function (v) {
  6088. this.p[this.a] = v;
  6089. }});
  6090. this.RawComponents[0][1] = 0.0;
  6091. this.RawComponents[0][2] = -this.RawComponents[2][0];
  6092. this.RawComponents[0][3] = 0.0;
  6093. this.RawComponents[1][0] = 0.0;
  6094. this.RawComponents[1][1] = 1.0;
  6095. this.RawComponents[1][2] = 0.0;
  6096. this.RawComponents[1][3] = 0.0;
  6097. this.RawComponents[2][1] = 0.0;
  6098. this.RawComponents[2][2] = this.RawComponents[0][0];
  6099. this.RawComponents[2][3] = 0.0;
  6100. this.RawComponents[3][0] = 0.0;
  6101. this.RawComponents[3][1] = 0.0;
  6102. this.RawComponents[3][2] = 0.0;
  6103. this.RawComponents[3][3] = 1.0;
  6104. };
  6105. this.RotateX = function (Angle) {
  6106. this.RawComponents[0][0] = 1.0;
  6107. this.RawComponents[0][1] = 0.0;
  6108. this.RawComponents[0][2] = 0.0;
  6109. this.RawComponents[0][3] = 0.0;
  6110. this.RawComponents[1][0] = 0.0;
  6111. $mod.SinCos(Angle,{a: 2, p: this.RawComponents[1], get: function () {
  6112. return this.p[this.a];
  6113. }, set: function (v) {
  6114. this.p[this.a] = v;
  6115. }},{a: 1, p: this.RawComponents[1], get: function () {
  6116. return this.p[this.a];
  6117. }, set: function (v) {
  6118. this.p[this.a] = v;
  6119. }});
  6120. this.RawComponents[1][3] = 0.0;
  6121. this.RawComponents[2][0] = 0.0;
  6122. this.RawComponents[2][1] = -this.RawComponents[1][2];
  6123. this.RawComponents[2][2] = this.RawComponents[1][1];
  6124. this.RawComponents[2][3] = 0.0;
  6125. this.RawComponents[3][0] = 0.0;
  6126. this.RawComponents[3][1] = 0.0;
  6127. this.RawComponents[3][2] = 0.0;
  6128. this.RawComponents[3][3] = 1.0;
  6129. };
  6130. this.Scale = function (x, y, z) {
  6131. this.RawComponents[0][0] = x;
  6132. this.RawComponents[0][1] = 0;
  6133. this.RawComponents[0][2] = 0;
  6134. this.RawComponents[0][3] = 0;
  6135. this.RawComponents[1][0] = 0;
  6136. this.RawComponents[1][1] = y;
  6137. this.RawComponents[1][2] = 0;
  6138. this.RawComponents[1][3] = 0;
  6139. this.RawComponents[2][0] = 0;
  6140. this.RawComponents[2][1] = 0;
  6141. this.RawComponents[2][2] = z;
  6142. this.RawComponents[2][3] = 0;
  6143. this.RawComponents[3][0] = 0;
  6144. this.RawComponents[3][1] = 0;
  6145. this.RawComponents[3][2] = 0;
  6146. this.RawComponents[3][3] = 1;
  6147. };
  6148. this.Ortho = function (Left, Right, Bottom, Top, zNear, zFar) {
  6149. var rml = 0.0;
  6150. var tmb = 0.0;
  6151. var fmn = 0.0;
  6152. rml = Right - Left;
  6153. tmb = Top - Bottom;
  6154. fmn = zFar - zNear;
  6155. this.RawComponents[0][0] = 2.0 / rml;
  6156. this.RawComponents[0][1] = 0.0;
  6157. this.RawComponents[0][2] = 0.0;
  6158. this.RawComponents[0][3] = 0.0;
  6159. this.RawComponents[1][0] = 0.0;
  6160. this.RawComponents[1][1] = 2.0 / tmb;
  6161. this.RawComponents[1][2] = 0.0;
  6162. this.RawComponents[1][3] = 0.0;
  6163. this.RawComponents[2][0] = 0.0;
  6164. this.RawComponents[2][1] = 0.0;
  6165. this.RawComponents[2][2] = -2.0 / fmn;
  6166. this.RawComponents[2][3] = 0.0;
  6167. this.RawComponents[3][0] = -(Right + Left) / rml;
  6168. this.RawComponents[3][1] = -(Top + Bottom) / tmb;
  6169. this.RawComponents[3][2] = -(zFar + zNear) / fmn;
  6170. this.RawComponents[3][3] = 1.0;
  6171. };
  6172. this.Perspective = function (fovy, Aspect, zNear, zFar) {
  6173. var Sine = 0.0;
  6174. var Cotangent = 0.0;
  6175. var ZDelta = 0.0;
  6176. var Radians = 0.0;
  6177. Radians = (fovy * 0.5) * 0.017453292519944444;
  6178. ZDelta = zFar - zNear;
  6179. Sine = Math.sin(Radians);
  6180. if (!(((ZDelta === 0) || (Sine === 0)) || (Aspect === 0))) {
  6181. Cotangent = Math.cos(Radians) / Sine;
  6182. this.RawComponents = $impl.Matrix4x4Identity.RawComponents.slice(0);
  6183. this.RawComponents[0][0] = Cotangent / Aspect;
  6184. this.RawComponents[1][1] = Cotangent;
  6185. this.RawComponents[2][2] = -(zFar + zNear) / ZDelta;
  6186. this.RawComponents[2][3] = -1 - 0;
  6187. this.RawComponents[3][2] = -((2.0 * zNear) * zFar) / ZDelta;
  6188. this.RawComponents[3][3] = 0.0;
  6189. };
  6190. };
  6191. this.Multiply = function (m) {
  6192. var Result = null;
  6193. Result = $mod.TMat4.$create("Identity");
  6194. Result.RawComponents[0][0] = (((m.RawComponents[0][0] * this.RawComponents[0][0]) + (m.RawComponents[0][1] * this.RawComponents[1][0])) + (m.RawComponents[0][2] * this.RawComponents[2][0])) + (m.RawComponents[0][3] * this.RawComponents[3][0]);
  6195. Result.RawComponents[0][1] = (((m.RawComponents[0][0] * this.RawComponents[0][1]) + (m.RawComponents[0][1] * this.RawComponents[1][1])) + (m.RawComponents[0][2] * this.RawComponents[2][1])) + (m.RawComponents[0][3] * this.RawComponents[3][1]);
  6196. Result.RawComponents[0][2] = (((m.RawComponents[0][0] * this.RawComponents[0][2]) + (m.RawComponents[0][1] * this.RawComponents[1][2])) + (m.RawComponents[0][2] * this.RawComponents[2][2])) + (m.RawComponents[0][3] * this.RawComponents[3][2]);
  6197. Result.RawComponents[0][3] = (((m.RawComponents[0][0] * this.RawComponents[0][3]) + (m.RawComponents[0][1] * this.RawComponents[1][3])) + (m.RawComponents[0][2] * this.RawComponents[2][3])) + (m.RawComponents[0][3] * this.RawComponents[3][3]);
  6198. Result.RawComponents[1][0] = (((m.RawComponents[1][0] * this.RawComponents[0][0]) + (m.RawComponents[1][1] * this.RawComponents[1][0])) + (m.RawComponents[1][2] * this.RawComponents[2][0])) + (m.RawComponents[1][3] * this.RawComponents[3][0]);
  6199. Result.RawComponents[1][1] = (((m.RawComponents[1][0] * this.RawComponents[0][1]) + (m.RawComponents[1][1] * this.RawComponents[1][1])) + (m.RawComponents[1][2] * this.RawComponents[2][1])) + (m.RawComponents[1][3] * this.RawComponents[3][1]);
  6200. Result.RawComponents[1][2] = (((m.RawComponents[1][0] * this.RawComponents[0][2]) + (m.RawComponents[1][1] * this.RawComponents[1][2])) + (m.RawComponents[1][2] * this.RawComponents[2][2])) + (m.RawComponents[1][3] * this.RawComponents[3][2]);
  6201. Result.RawComponents[1][3] = (((m.RawComponents[1][0] * this.RawComponents[0][3]) + (m.RawComponents[1][1] * this.RawComponents[1][3])) + (m.RawComponents[1][2] * this.RawComponents[2][3])) + (m.RawComponents[1][3] * this.RawComponents[3][3]);
  6202. Result.RawComponents[2][0] = (((m.RawComponents[2][0] * this.RawComponents[0][0]) + (m.RawComponents[2][1] * this.RawComponents[1][0])) + (m.RawComponents[2][2] * this.RawComponents[2][0])) + (m.RawComponents[2][3] * this.RawComponents[3][0]);
  6203. Result.RawComponents[2][1] = (((m.RawComponents[2][0] * this.RawComponents[0][1]) + (m.RawComponents[2][1] * this.RawComponents[1][1])) + (m.RawComponents[2][2] * this.RawComponents[2][1])) + (m.RawComponents[2][3] * this.RawComponents[3][1]);
  6204. Result.RawComponents[2][2] = (((m.RawComponents[2][0] * this.RawComponents[0][2]) + (m.RawComponents[2][1] * this.RawComponents[1][2])) + (m.RawComponents[2][2] * this.RawComponents[2][2])) + (m.RawComponents[2][3] * this.RawComponents[3][2]);
  6205. Result.RawComponents[2][3] = (((m.RawComponents[2][0] * this.RawComponents[0][3]) + (m.RawComponents[2][1] * this.RawComponents[1][3])) + (m.RawComponents[2][2] * this.RawComponents[2][3])) + (m.RawComponents[2][3] * this.RawComponents[3][3]);
  6206. Result.RawComponents[3][0] = (((m.RawComponents[3][0] * this.RawComponents[0][0]) + (m.RawComponents[3][1] * this.RawComponents[1][0])) + (m.RawComponents[3][2] * this.RawComponents[2][0])) + (m.RawComponents[3][3] * this.RawComponents[3][0]);
  6207. Result.RawComponents[3][1] = (((m.RawComponents[3][0] * this.RawComponents[0][1]) + (m.RawComponents[3][1] * this.RawComponents[1][1])) + (m.RawComponents[3][2] * this.RawComponents[2][1])) + (m.RawComponents[3][3] * this.RawComponents[3][1]);
  6208. Result.RawComponents[3][2] = (((m.RawComponents[3][0] * this.RawComponents[0][2]) + (m.RawComponents[3][1] * this.RawComponents[1][2])) + (m.RawComponents[3][2] * this.RawComponents[2][2])) + (m.RawComponents[3][3] * this.RawComponents[3][2]);
  6209. Result.RawComponents[3][3] = (((m.RawComponents[3][0] * this.RawComponents[0][3]) + (m.RawComponents[3][1] * this.RawComponents[1][3])) + (m.RawComponents[3][2] * this.RawComponents[2][3])) + (m.RawComponents[3][3] * this.RawComponents[3][3]);
  6210. return Result;
  6211. };
  6212. this.CopyList = function () {
  6213. var Result = [];
  6214. var x = 0;
  6215. var y = 0;
  6216. var list = null;
  6217. list = new Array();
  6218. for (x = 0; x <= 3; x++) for (y = 0; y <= 3; y++) list.push(this.RawComponents[x][y]);
  6219. Result = list;
  6220. return Result;
  6221. };
  6222. this.Show = function () {
  6223. var x = 0;
  6224. var y = 0;
  6225. for (y = 0; y <= 3; y++) {
  6226. pas.System.Write("[");
  6227. for (x = 0; x <= 3; x++) {
  6228. if (x < 3) {
  6229. pas.System.Write(this.RawComponents[x][y],",")}
  6230. else pas.System.Write(this.RawComponents[x][y]);
  6231. };
  6232. pas.System.Write("]");
  6233. };
  6234. };
  6235. });
  6236. this.SinCos = function (angle, sinus, cosinus) {
  6237. sinus.set(Math.sin(angle));
  6238. cosinus.set(Math.cos(angle));
  6239. };
  6240. $mod.$init = function () {
  6241. $impl.Matrix4x4Identity = $mod.TMat4.$create("Identity");
  6242. };
  6243. },null,function () {
  6244. "use strict";
  6245. var $mod = this;
  6246. var $impl = $mod.$impl;
  6247. $impl.PI = 3.14159265359;
  6248. $impl.DEG2RAD = 3.14159265359 / 180.0;
  6249. $impl.Matrix4x4Identity = null;
  6250. });