12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356 |
- var pas = {};
- var rtl = {
- quiet: false,
- debug_load_units: false,
- debug_rtti: false,
- debug: function(){
- if (rtl.quiet || !console || !console.log) return;
- console.log(arguments);
- },
- error: function(s){
- rtl.debug('Error: ',s);
- throw s;
- },
- warn: function(s){
- rtl.debug('Warn: ',s);
- },
- hasString: function(s){
- return rtl.isString(s) && (s.length>0);
- },
- isArray: function(a) {
- return Array.isArray(a);
- },
- isFunction: function(f){
- return typeof(f)==="function";
- },
- isModule: function(m){
- return rtl.isObject(m) && rtl.hasString(m.$name) && (pas[m.$name]===m);
- },
- isImplementation: function(m){
- return rtl.isObject(m) && rtl.isModule(m.$module) && (m.$module.$impl===m);
- },
- isNumber: function(n){
- return typeof(n)==="number";
- },
- isObject: function(o){
- var s=typeof(o);
- return (typeof(o)==="object") && (o!=null);
- },
- isString: function(s){
- return typeof(s)==="string";
- },
- getNumber: function(n){
- return typeof(n)==="number"?n:NaN;
- },
- getChar: function(c){
- return ((typeof(c)==="string") && (c.length===1)) ? c : "";
- },
- getObject: function(o){
- return ((typeof(o)==="object") || (typeof(o)==='function')) ? o : null;
- },
- isPasClass: function(type){
- return (rtl.isObject(type) && type.hasOwnProperty('$classname') && rtl.isObject(type.$module));
- },
- isPasClassInstance: function(type){
- return (rtl.isObject(type) && rtl.isPasClass(type.$class));
- },
- hexStr: function(n,digits){
- return ("000000000000000"+n.toString(16).toUpperCase()).slice(-digits);
- },
- m_loading: 0,
- m_loading_intf: 1,
- m_intf_loaded: 2,
- m_loading_impl: 3, // loading all used unit
- m_initializing: 4, // running initialization
- m_initialized: 5,
- module: function(module_name, intfuseslist, intfcode, impluseslist, implcode){
- if (rtl.debug_load_units) rtl.debug('rtl.module name="'+module_name+'" intfuses='+intfuseslist+' impluses='+impluseslist+' hasimplcode='+rtl.isFunction(implcode));
- if (!rtl.hasString(module_name)) rtl.error('invalid module name "'+module_name+'"');
- if (!rtl.isArray(intfuseslist)) rtl.error('invalid interface useslist of "'+module_name+'"');
- if (!rtl.isFunction(intfcode)) rtl.error('invalid interface code of "'+module_name+'"');
- if (!(impluseslist==undefined) && !rtl.isArray(impluseslist)) rtl.error('invalid implementation useslist of "'+module_name+'"');
- if (!(implcode==undefined) && !rtl.isFunction(implcode)) rtl.error('invalid implementation code of "'+module_name+'"');
- if (pas[module_name])
- rtl.error('module "'+module_name+'" is already registered');
- var module = pas[module_name] = {
- $name: module_name,
- $intfuseslist: intfuseslist,
- $impluseslist: impluseslist,
- $state: rtl.m_loading,
- $intfcode: intfcode,
- $implcode: implcode,
- $impl: null,
- $rtti: Object.create(rtl.tSectionRTTI)
- };
- module.$rtti.$module = module;
- if (implcode) module.$impl = {
- $module: module,
- $rtti: module.$rtti
- };
- },
- exitcode: 0,
- run: function(module_name){
-
- function doRun(){
- if (!rtl.hasString(module_name)) module_name='program';
- if (rtl.debug_load_units) rtl.debug('rtl.run module="'+module_name+'"');
- rtl.initRTTI();
- var module = pas[module_name];
- if (!module) rtl.error('rtl.run module "'+module_name+'" missing');
- rtl.loadintf(module);
- rtl.loadimpl(module);
- if (module_name=='program'){
- if (rtl.debug_load_units) rtl.debug('running $main');
- var r = pas.program.$main();
- if (rtl.isNumber(r)) rtl.exitcode = r;
- }
- }
-
- if (rtl.showUncaughtExceptions) {
- try{
- doRun();
- } catch(re) {
- var errMsg = re.hasOwnProperty('$class') ? re.$class.$classname : '';
- errMsg += ((errMsg) ? ': ' : '') + (re.hasOwnProperty('fMessage') ? re.fMessage : re);
- alert('Uncaught Exception : '+errMsg);
- rtl.exitCode = 216;
- }
- } else {
- doRun();
- }
- return rtl.exitcode;
- },
- loadintf: function(module){
- if (module.$state>rtl.m_loading_intf) return; // already finished
- if (rtl.debug_load_units) rtl.debug('loadintf: "'+module.$name+'"');
- if (module.$state===rtl.m_loading_intf)
- rtl.error('unit cycle detected "'+module.$name+'"');
- module.$state=rtl.m_loading_intf;
- // load interfaces of interface useslist
- rtl.loaduseslist(module,module.$intfuseslist,rtl.loadintf);
- // run interface
- if (rtl.debug_load_units) rtl.debug('loadintf: run intf of "'+module.$name+'"');
- module.$intfcode(module.$intfuseslist);
- // success
- module.$state=rtl.m_intf_loaded;
- // Note: units only used in implementations are not yet loaded (not even their interfaces)
- },
- loaduseslist: function(module,useslist,f){
- if (useslist==undefined) return;
- for (var i in useslist){
- var unitname=useslist[i];
- if (rtl.debug_load_units) rtl.debug('loaduseslist of "'+module.$name+'" uses="'+unitname+'"');
- if (pas[unitname]==undefined)
- rtl.error('module "'+module.$name+'" misses "'+unitname+'"');
- f(pas[unitname]);
- }
- },
- loadimpl: function(module){
- if (module.$state>=rtl.m_loading_impl) return; // already processing
- if (module.$state<rtl.m_intf_loaded) rtl.error('loadimpl: interface not loaded of "'+module.$name+'"');
- if (rtl.debug_load_units) rtl.debug('loadimpl: load uses of "'+module.$name+'"');
- module.$state=rtl.m_loading_impl;
- // load interfaces of implementation useslist
- rtl.loaduseslist(module,module.$impluseslist,rtl.loadintf);
- // load implementation of interfaces useslist
- rtl.loaduseslist(module,module.$intfuseslist,rtl.loadimpl);
- // load implementation of implementation useslist
- rtl.loaduseslist(module,module.$impluseslist,rtl.loadimpl);
- // Note: At this point all interfaces used by this unit are loaded. If
- // there are implementation uses cycles some used units might not yet be
- // initialized. This is by design.
- // run implementation
- if (rtl.debug_load_units) rtl.debug('loadimpl: run impl of "'+module.$name+'"');
- if (rtl.isFunction(module.$implcode)) module.$implcode(module.$impluseslist);
- // run initialization
- if (rtl.debug_load_units) rtl.debug('loadimpl: run init of "'+module.$name+'"');
- module.$state=rtl.m_initializing;
- if (rtl.isFunction(module.$init)) module.$init();
- // unit initialized
- module.$state=rtl.m_initialized;
- },
- createCallback: function(scope, fn){
- var cb;
- if (typeof(fn)==='string'){
- cb = function(){
- return scope[fn].apply(scope,arguments);
- };
- } else {
- cb = function(){
- return fn.apply(scope,arguments);
- };
- };
- cb.scope = scope;
- cb.fn = fn;
- return cb;
- },
- cloneCallback: function(cb){
- return rtl.createCallback(cb.scope,cb.fn);
- },
- eqCallback: function(a,b){
- // can be a function or a function wrapper
- if (a==b){
- return true;
- } else {
- return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
- }
- },
- initClass: function(c,parent,name,initfn){
- parent[name] = c;
- c.$classname = name;
- if ((parent.$module) && (parent.$module.$impl===parent)) parent=parent.$module;
- c.$parent = parent;
- c.$fullname = parent.$name+'.'+name;
- if (rtl.isModule(parent)){
- c.$module = parent;
- c.$name = name;
- } else {
- c.$module = parent.$module;
- c.$name = parent.name+'.'+name;
- };
- // rtti
- if (rtl.debug_rtti) rtl.debug('initClass '+c.$fullname);
- var t = c.$module.$rtti.$Class(c.$name,{ "class": c, module: parent });
- c.$rtti = t;
- if (rtl.isObject(c.$ancestor)) t.ancestor = c.$ancestor.$rtti;
- if (!t.ancestor) t.ancestor = null;
- // init members
- initfn.call(c);
- },
- createClass: function(parent,name,ancestor,initfn){
- // create a normal class,
- // ancestor must be null or a normal class,
- // the root ancestor can be an external class
- var c = null;
- if (ancestor != null){
- c = Object.create(ancestor);
- c.$ancestor = ancestor;
- // Note:
- // if root is an "object" then c.$ancestor === Object.getPrototypeOf(c)
- // if root is a "function" then c.$ancestor === c.__proto__, Object.getPrototypeOf(c) returns the root
- } else {
- c = {};
- c.$create = function(fnname,args){
- if (args == undefined) args = [];
- var o = Object.create(this);
- o.$class = this; // Note: o.$class === Object.getPrototypeOf(o)
- o.$init();
- try{
- o[fnname].apply(o,args);
- o.AfterConstruction();
- } catch($e){
- o.$destroy;
- throw $e;
- }
- return o;
- };
- c.$destroy = function(fnname){
- this.BeforeDestruction();
- this[fnname]();
- this.$final;
- };
- };
- rtl.initClass(c,parent,name,initfn);
- },
- createClassExt: function(parent,name,ancestor,newinstancefnname,initfn){
- // Create a class using an external ancestor.
- // If newinstancefnname is given, use that function to create the new object.
- // If exist call BeforeDestruction and AfterConstruction.
- var c = null;
- c = Object.create(ancestor);
- c.$create = function(fnname,args){
- if (args == undefined) args = [];
- var o = null;
- if (newinstancefnname.length>0){
- o = this[newinstancefnname](fnname,args);
- } else {
- o = Object.create(this);
- }
- o.$class = this; // Note: o.$class === Object.getPrototypeOf(o)
- o.$init();
- try{
- o[fnname].apply(o,args);
- if (o.AfterConstruction) o.AfterConstruction();
- } catch($e){
- o.$destroy;
- throw $e;
- }
- return o;
- };
- c.$destroy = function(fnname){
- if (this.BeforeDestruction) this.BeforeDestruction();
- this[fnname]();
- this.$final;
- };
- rtl.initClass(c,parent,name,initfn);
- },
- tObjectDestroy: "Destroy",
- free: function(obj,name){
- if (obj[name]==null) return;
- obj[name].$destroy(rtl.tObjectDestroy);
- obj[name]=null;
- },
- freeLoc: function(obj){
- if (obj==null) return;
- obj.$destroy(rtl.tObjectDestroy);
- return null;
- },
- is: function(instance,type){
- return type.isPrototypeOf(instance) || (instance===type);
- },
- isExt: function(instance,type,mode){
- // mode===1 means instance must be a Pascal class instance
- // mode===2 means instance must be a Pascal class
- // Notes:
- // isPrototypeOf and instanceof return false on equal
- // isPrototypeOf does not work for Date.isPrototypeOf(new Date())
- // so if isPrototypeOf is false test with instanceof
- // instanceof needs a function on right side
- if (instance == null) return false; // Note: ==null checks for undefined too
- if ((typeof(type) !== 'object') && (typeof(type) !== 'function')) return false;
- if (instance === type){
- if (mode===1) return false;
- if (mode===2) return rtl.isPasClass(instance);
- return true;
- }
- if (type.isPrototypeOf && type.isPrototypeOf(instance)){
- if (mode===1) return rtl.isPasClassInstance(instance);
- if (mode===2) return rtl.isPasClass(instance);
- return true;
- }
- if ((typeof type == 'function') && (instance instanceof type)) return true;
- return false;
- },
- Exception: null,
- EInvalidCast: null,
- EAbstractError: null,
- ERangeError: null,
- raiseE: function(typename){
- var t = rtl[typename];
- if (t==null){
- var mod = pas.SysUtils;
- if (!mod) mod = pas.sysutils;
- if (mod){
- t = mod[typename];
- if (!t) t = mod[typename.toLowerCase()];
- if (!t) t = mod['Exception'];
- if (!t) t = mod['exception'];
- }
- }
- if (t){
- if (t.Create){
- throw t.$create("Create");
- } else if (t.create){
- throw t.$create("create");
- }
- }
- if (typename === "EInvalidCast") throw "invalid type cast";
- if (typename === "EAbstractError") throw "Abstract method called";
- if (typename === "ERangeError") throw "range error";
- throw typename;
- },
- as: function(instance,type){
- if((instance === null) || rtl.is(instance,type)) return instance;
- rtl.raiseE("EInvalidCast");
- },
- asExt: function(instance,type,mode){
- if((instance === null) || rtl.isExt(instance,type,mode)) return instance;
- rtl.raiseE("EInvalidCast");
- },
- createInterface: function(module, name, guid, fnnames, ancestor, initfn){
- //console.log('createInterface name="'+name+'" guid="'+guid+'" names='+fnnames);
- var i = ancestor?Object.create(ancestor):{};
- module[name] = i;
- i.$module = module;
- i.$name = name;
- i.$fullname = module.$name+'.'+name;
- i.$guid = guid;
- i.$guidr = null;
- i.$names = fnnames?fnnames:[];
- if (rtl.isFunction(initfn)){
- // rtti
- if (rtl.debug_rtti) rtl.debug('createInterface '+i.$fullname);
- var t = i.$module.$rtti.$Interface(name,{ "interface": i, module: module });
- i.$rtti = t;
- if (ancestor) t.ancestor = ancestor.$rtti;
- if (!t.ancestor) t.ancestor = null;
- initfn.call(i);
- }
- return i;
- },
- strToGUIDR: function(s,g){
- var p = 0;
- function n(l){
- var h = s.substr(p,l);
- p+=l;
- return parseInt(h,16);
- }
- p+=1; // skip {
- g.D1 = n(8);
- p+=1; // skip -
- g.D2 = n(4);
- p+=1; // skip -
- g.D3 = n(4);
- p+=1; // skip -
- if (!g.D4) g.D4=[];
- g.D4[0] = n(2);
- g.D4[1] = n(2);
- p+=1; // skip -
- for(var i=2; i<8; i++) g.D4[i] = n(2);
- return g;
- },
- guidrToStr: function(g){
- if (g.$intf) return g.$intf.$guid;
- var h = rtl.hexStr;
- var s='{'+h(g.D1,8)+'-'+h(g.D2,4)+'-'+h(g.D3,4)+'-'+h(g.D4[0],2)+h(g.D4[1],2)+'-';
- for (var i=2; i<8; i++) s+=h(g.D4[i],2);
- s+='}';
- return s;
- },
- createTGUID: function(guid){
- var TGuid = (pas.System)?pas.System.TGuid:pas.system.tguid;
- var g = rtl.strToGUIDR(guid,new TGuid());
- return g;
- },
- getIntfGUIDR: function(intfTypeOrVar){
- if (!intfTypeOrVar) return null;
- if (!intfTypeOrVar.$guidr){
- var g = rtl.createTGUID(intfTypeOrVar.$guid);
- if (!intfTypeOrVar.hasOwnProperty('$guid')) intfTypeOrVar = Object.getPrototypeOf(intfTypeOrVar);
- g.$intf = intfTypeOrVar;
- intfTypeOrVar.$guidr = g;
- }
- return intfTypeOrVar.$guidr;
- },
- addIntf: function (aclass, intf, map){
- function jmp(fn){
- if (typeof(fn)==="function"){
- return function(){ return fn.apply(this.$o,arguments); };
- } else {
- return function(){ rtl.raiseE('EAbstractError'); };
- }
- }
- if(!map) map = {};
- var t = intf;
- var item = Object.create(t);
- aclass.$intfmaps[intf.$guid] = item;
- do{
- var names = t.$names;
- if (!names) break;
- for (var i=0; i<names.length; i++){
- var intfname = names[i];
- var fnname = map[intfname];
- if (!fnname) fnname = intfname;
- //console.log('addIntf: intftype='+t.$name+' index='+i+' intfname="'+intfname+'" fnname="'+fnname+'" proc='+typeof(fn));
- item[intfname] = jmp(aclass[fnname]);
- }
- t = Object.getPrototypeOf(t);
- }while(t!=null);
- },
- getIntfG: function (obj, guid, query){
- if (!obj) return null;
- //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query);
- // search
- var maps = obj.$intfmaps;
- if (!maps) return null;
- var item = maps[guid];
- if (!item) return null;
- // check delegation
- //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' query='+query+' item='+typeof(item));
- if (typeof item === 'function') return item.call(obj); // COM: contains _AddRef
- // check cache
- var intf = null;
- if (obj.$interfaces){
- intf = obj.$interfaces[guid];
- //console.log('getIntfG: obj='+obj.$classname+' guid='+guid+' cache='+typeof(intf));
- }
- if (!intf){ // intf can be undefined!
- intf = Object.create(item);
- intf.$o = obj;
- if (!obj.$interfaces) obj.$interfaces = {};
- obj.$interfaces[guid] = intf;
- }
- if (typeof(query)==='object'){
- // called by queryIntfT
- var o = null;
- if (intf.QueryInterface(rtl.getIntfGUIDR(query),
- {get:function(){ return o; }, set:function(v){ o=v; }}) === 0){
- return o;
- } else {
- return null;
- }
- } else if(query===2){
- // called by TObject.GetInterfaceByStr
- if (intf.$kind === 'com') intf._AddRef();
- }
- return intf;
- },
- getIntfT: function(obj,intftype){
- return rtl.getIntfG(obj,intftype.$guid);
- },
- queryIntfT: function(obj,intftype){
- return rtl.getIntfG(obj,intftype.$guid,intftype);
- },
- queryIntfIsT: function(obj,intftype){
- var i = rtl.queryIntfG(obj,intftype.$guid);
- if (!i) return false;
- if (i.$kind === 'com') i._Release();
- return true;
- },
- asIntfT: function (obj,intftype){
- var i = rtl.getIntfG(obj,intftype.$guid);
- if (i!==null) return i;
- rtl.raiseEInvalidCast();
- },
- intfIsClass: function(intf,classtype){
- return (intf!=null) && (rtl.is(intf.$o,classtype));
- },
- intfAsClass: function(intf,classtype){
- if (intf==null) return null;
- return rtl.as(intf.$o,classtype);
- },
- intfToClass: function(intf,classtype){
- if ((intf!==null) && rtl.is(intf.$o,classtype)) return intf.$o;
- return null;
- },
- // interface reference counting
- intfRefs: { // base object for temporary interface variables
- ref: function(id,intf){
- // called for temporary interface references needing delayed release
- var old = this[id];
- //console.log('rtl.intfRefs.ref: id='+id+' old="'+(old?old.$name:'null')+'" intf="'+(intf?intf.$name:'null'));
- if (old){
- // called again, e.g. in a loop
- delete this[id];
- old._Release(); // may fail
- }
- this[id]=intf;
- return intf;
- },
- free: function(){
- //console.log('rtl.intfRefs.free...');
- for (var id in this){
- if (this.hasOwnProperty(id)) this[id]._Release;
- }
- }
- },
- createIntfRefs: function(){
- //console.log('rtl.createIntfRefs');
- return Object.create(rtl.intfRefs);
- },
- setIntfP: function(path,name,value,skipAddRef){
- var old = path[name];
- //console.log('rtl.setIntfP path='+path+' name='+name+' old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
- if (old === value) return;
- if (old !== null){
- path[name]=null;
- old._Release();
- }
- if (value !== null){
- if (!skipAddRef) value._AddRef();
- path[name]=value;
- }
- },
- setIntfL: function(old,value,skipAddRef){
- //console.log('rtl.setIntfL old="'+(old?old.$name:'null')+'" value="'+(value?value.$name:'null')+'"');
- if (old !== value){
- if (value!==null){
- if (!skipAddRef) value._AddRef();
- }
- if (old!==null){
- old._Release(); // Release after AddRef, to avoid double Release if Release creates an exception
- }
- } else if (skipAddRef){
- if (old!==null){
- old._Release(); // value has an AddRef
- }
- }
- return value;
- },
- _AddRef: function(intf){
- //if (intf) console.log('rtl._AddRef intf="'+(intf?intf.$name:'null')+'"');
- if (intf) intf._AddRef();
- return intf;
- },
- _Release: function(intf){
- //if (intf) console.log('rtl._Release intf="'+(intf?intf.$name:'null')+'"');
- if (intf) intf._Release();
- return intf;
- },
- checkMethodCall: function(obj,type){
- if (rtl.isObject(obj) && rtl.is(obj,type)) return;
- rtl.raiseE("EInvalidCast");
- },
- rc: function(i,minval,maxval){
- // range check integer
- if ((Math.floor(i)===i) && (i>=minval) && (i<=maxval)) return i;
- rtl.raiseE('ERangeError');
- },
- rcc: function(c,minval,maxval){
- // range check char
- if ((typeof(c)==='string') && (c.length===1)){
- var i = c.charCodeAt(0);
- if ((i>=minval) && (i<=maxval)) return c;
- }
- rtl.raiseE('ERangeError');
- },
- rcSetCharAt: function(s,index,c){
- // range check setCharAt
- if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
- return rtl.setCharAt(s,index,c);
- },
- rcCharAt: function(s,index){
- // range check charAt
- if ((typeof(s)!=='string') || (index<0) || (index>=s.length)) rtl.raiseE('ERangeError');
- return s.charAt(index);
- },
- rcArrR: function(arr,index){
- // range check read array
- if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
- if (arguments.length>2){
- // arr,index1,index2,...
- arr=arr[index];
- for (var i=2; i<arguments.length; i++) arr=rtl.rcArrR(arr,arguments[i]);
- return arr;
- }
- return arr[index];
- }
- rtl.raiseE('ERangeError');
- },
- rcArrW: function(arr,index,value){
- // range check write array
- // arr,index1,index2,...,value
- for (var i=3; i<arguments.length; i++){
- arr=rtl.rcArrR(arr,index);
- index=arguments[i-1];
- value=arguments[i];
- }
- if (Array.isArray(arr) && (typeof(index)==='number') && (index>=0) && (index<arr.length)){
- return arr[index]=value;
- }
- rtl.raiseE('ERangeError');
- },
- length: function(arr){
- return (arr == null) ? 0 : arr.length;
- },
- arraySetLength: function(arr,defaultvalue,newlength){
- // multi dim: (arr,defaultvalue,dim1,dim2,...)
- if (arr == null) arr = [];
- var p = arguments;
- function setLength(a,argNo){
- var oldlen = a.length;
- var newlen = p[argNo];
- if (oldlen!==newlength){
- a.length = newlength;
- if (argNo === p.length-1){
- if (rtl.isArray(defaultvalue)){
- for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
- } else if (rtl.isFunction(defaultvalue)){
- for (var i=oldlen; i<newlen; i++) a[i]=new defaultvalue(); // e.g. record
- } else if (rtl.isObject(defaultvalue)) {
- for (var i=oldlen; i<newlen; i++) a[i]={}; // e.g. set
- } else {
- for (var i=oldlen; i<newlen; i++) a[i]=defaultvalue;
- }
- } else {
- for (var i=oldlen; i<newlen; i++) a[i]=[]; // nested array
- }
- }
- if (argNo < p.length-1){
- // multi argNo
- for (var i=0; i<newlen; i++) a[i]=setLength(a[i],argNo+1);
- }
- return a;
- }
- return setLength(arr,2);
- },
- arrayEq: function(a,b){
- if (a===null) return b===null;
- if (b===null) return false;
- if (a.length!==b.length) return false;
- for (var i=0; i<a.length; i++) if (a[i]!==b[i]) return false;
- return true;
- },
- arrayClone: function(type,src,srcpos,end,dst,dstpos){
- // type: 0 for references, "refset" for calling refSet(), a function for new type()
- // src must not be null
- // This function does not range check.
- if (rtl.isFunction(type)){
- for (; srcpos<end; srcpos++) dst[dstpos++] = new type(src[srcpos]); // clone record
- } else if((typeof(type)==="string") && (type === 'refSet')) {
- for (; srcpos<end; srcpos++) dst[dstpos++] = rtl.refSet(src[srcpos]); // ref set
- } else {
- for (; srcpos<end; srcpos++) dst[dstpos++] = src[srcpos]; // reference
- };
- },
- arrayConcat: function(type){
- // type: see rtl.arrayClone
- var a = [];
- var l = 0;
- for (var i=1; i<arguments.length; i++) l+=arguments[i].length;
- a.length = l;
- l=0;
- for (var i=1; i<arguments.length; i++){
- var src = arguments[i];
- if (src == null) continue;
- rtl.arrayClone(type,src,0,src.length,a,l);
- l+=src.length;
- };
- return a;
- },
- arrayCopy: function(type, srcarray, index, count){
- // type: see rtl.arrayClone
- // if count is missing, use srcarray.length
- if (srcarray == null) return [];
- if (index < 0) index = 0;
- if (count === undefined) count=srcarray.length;
- var end = index+count;
- if (end>srcarray.length) end = srcarray.length;
- if (index>=end) return [];
- if (type===0){
- return srcarray.slice(index,end);
- } else {
- var a = [];
- a.length = end-index;
- rtl.arrayClone(type,srcarray,index,end,a,0);
- return a;
- }
- },
- setCharAt: function(s,index,c){
- return s.substr(0,index)+c+s.substr(index+1);
- },
- getResStr: function(mod,name){
- var rs = mod.$resourcestrings[name];
- return rs.current?rs.current:rs.org;
- },
- createSet: function(){
- var s = {};
- for (var i=0; i<arguments.length; i++){
- if (arguments[i]!=null){
- s[arguments[i]]=true;
- } else {
- var first=arguments[i+=1];
- var last=arguments[i+=1];
- for(var j=first; j<=last; j++) s[j]=true;
- }
- }
- return s;
- },
- cloneSet: function(s){
- var r = {};
- for (var key in s) r[key]=true;
- return r;
- },
- refSet: function(s){
- s.$shared = true;
- return s;
- },
- includeSet: function(s,enumvalue){
- if (s.$shared) s = rtl.cloneSet(s);
- s[enumvalue] = true;
- return s;
- },
- excludeSet: function(s,enumvalue){
- if (s.$shared) s = rtl.cloneSet(s);
- delete s[enumvalue];
- return s;
- },
- diffSet: function(s,t){
- var r = {};
- for (var key in s) if (!t[key]) r[key]=true;
- delete r.$shared;
- return r;
- },
- unionSet: function(s,t){
- var r = {};
- for (var key in s) r[key]=true;
- for (var key in t) r[key]=true;
- delete r.$shared;
- return r;
- },
- intersectSet: function(s,t){
- var r = {};
- for (var key in s) if (t[key]) r[key]=true;
- delete r.$shared;
- return r;
- },
- symDiffSet: function(s,t){
- var r = {};
- for (var key in s) if (!t[key]) r[key]=true;
- for (var key in t) if (!s[key]) r[key]=true;
- delete r.$shared;
- return r;
- },
- eqSet: function(s,t){
- for (var key in s) if (!t[key] && (key!='$shared')) return false;
- for (var key in t) if (!s[key] && (key!='$shared')) return false;
- return true;
- },
- neSet: function(s,t){
- return !rtl.eqSet(s,t);
- },
- leSet: function(s,t){
- for (var key in s) if (!t[key] && (key!='$shared')) return false;
- return true;
- },
- geSet: function(s,t){
- for (var key in t) if (!s[key] && (key!='$shared')) return false;
- return true;
- },
- strSetLength: function(s,newlen){
- var oldlen = s.length;
- if (oldlen > newlen){
- return s.substring(0,newlen);
- } else if (s.repeat){
- // Note: repeat needs ECMAScript6!
- return s+' '.repeat(newlen-oldlen);
- } else {
- while (oldlen<newlen){
- s+=' ';
- oldlen++;
- };
- return s;
- }
- },
- spaceLeft: function(s,width){
- var l=s.length;
- if (l>=width) return s;
- if (s.repeat){
- // Note: repeat needs ECMAScript6!
- return ' '.repeat(width-l) + s;
- } else {
- while (l<width){
- s=' '+s;
- l++;
- };
- };
- },
- floatToStr : function(d,w,p){
- // input 1-3 arguments: double, width, precision
- if (arguments.length>2){
- return rtl.spaceLeft(d.toFixed(p),w);
- } else {
- // exponent width
- var pad = "";
- var ad = Math.abs(d);
- if (ad<1.0e+10) {
- pad='00';
- } else if (ad<1.0e+100) {
- pad='0';
- }
- if (arguments.length<2) {
- w=9;
- } else if (w<9) {
- w=9;
- }
- var p = w-8;
- var s=(d>0 ? " " : "" ) + d.toExponential(p);
- s=s.replace(/e(.)/,'E$1'+pad);
- return rtl.spaceLeft(s,w);
- }
- },
- initRTTI: function(){
- if (rtl.debug_rtti) rtl.debug('initRTTI');
- // base types
- rtl.tTypeInfo = { name: "tTypeInfo" };
- function newBaseTI(name,kind,ancestor){
- if (!ancestor) ancestor = rtl.tTypeInfo;
- if (rtl.debug_rtti) rtl.debug('initRTTI.newBaseTI "'+name+'" '+kind+' ("'+ancestor.name+'")');
- var t = Object.create(ancestor);
- t.name = name;
- t.kind = kind;
- rtl[name] = t;
- return t;
- };
- function newBaseInt(name,minvalue,maxvalue,ordtype){
- var t = newBaseTI(name,1 /* tkInteger */,rtl.tTypeInfoInteger);
- t.minvalue = minvalue;
- t.maxvalue = maxvalue;
- t.ordtype = ordtype;
- return t;
- };
- newBaseTI("tTypeInfoInteger",1 /* tkInteger */);
- newBaseInt("shortint",-0x80,0x7f,0);
- newBaseInt("byte",0,0xff,1);
- newBaseInt("smallint",-0x8000,0x7fff,2);
- newBaseInt("word",0,0xffff,3);
- newBaseInt("longint",-0x80000000,0x7fffffff,4);
- newBaseInt("longword",0,0xffffffff,5);
- newBaseInt("nativeint",-0x10000000000000,0xfffffffffffff,6);
- newBaseInt("nativeuint",0,0xfffffffffffff,7);
- newBaseTI("char",2 /* tkChar */);
- newBaseTI("string",3 /* tkString */);
- newBaseTI("tTypeInfoEnum",4 /* tkEnumeration */,rtl.tTypeInfoInteger);
- newBaseTI("tTypeInfoSet",5 /* tkSet */);
- newBaseTI("double",6 /* tkDouble */);
- newBaseTI("boolean",7 /* tkBool */);
- newBaseTI("tTypeInfoProcVar",8 /* tkProcVar */);
- newBaseTI("tTypeInfoMethodVar",9 /* tkMethod */,rtl.tTypeInfoProcVar);
- newBaseTI("tTypeInfoArray",10 /* tkArray */);
- newBaseTI("tTypeInfoDynArray",11 /* tkDynArray */);
- newBaseTI("tTypeInfoPointer",15 /* tkPointer */);
- var t = newBaseTI("pointer",15 /* tkPointer */,rtl.tTypeInfoPointer);
- t.reftype = null;
- newBaseTI("jsvalue",16 /* tkJSValue */);
- newBaseTI("tTypeInfoRefToProcVar",17 /* tkRefToProcVar */,rtl.tTypeInfoProcVar);
- // member kinds
- rtl.tTypeMember = {};
- function newMember(name,kind){
- var m = Object.create(rtl.tTypeMember);
- m.name = name;
- m.kind = kind;
- rtl[name] = m;
- };
- newMember("tTypeMemberField",1); // tmkField
- newMember("tTypeMemberMethod",2); // tmkMethod
- newMember("tTypeMemberProperty",3); // tmkProperty
- // base object for storing members: a simple object
- rtl.tTypeMembers = {};
- // tTypeInfoStruct - base object for tTypeInfoClass, tTypeInfoRecord, tTypeInfoInterface
- var tis = newBaseTI("tTypeInfoStruct",0);
- tis.$addMember = function(name,ancestor,options){
- if (rtl.debug_rtti){
- if (!rtl.hasString(name) || (name.charAt()==='$')) throw 'invalid member "'+name+'", this="'+this.name+'"';
- if (!rtl.is(ancestor,rtl.tTypeMember)) throw 'invalid ancestor "'+ancestor+':'+ancestor.name+'", "'+this.name+'.'+name+'"';
- if ((options!=undefined) && (typeof(options)!='object')) throw 'invalid options "'+options+'", "'+this.name+'.'+name+'"';
- };
- var t = Object.create(ancestor);
- t.name = name;
- this.members[name] = t;
- this.names.push(name);
- if (rtl.isObject(options)){
- for (var key in options) if (options.hasOwnProperty(key)) t[key] = options[key];
- };
- return t;
- };
- tis.addField = function(name,type,options){
- var t = this.$addMember(name,rtl.tTypeMemberField,options);
- if (rtl.debug_rtti){
- if (!rtl.is(type,rtl.tTypeInfo)) throw 'invalid type "'+type+'", "'+this.name+'.'+name+'"';
- };
- t.typeinfo = type;
- this.fields.push(name);
- return t;
- };
- tis.addFields = function(){
- var i=0;
- while(i<arguments.length){
- var name = arguments[i++];
- var type = arguments[i++];
- if ((i<arguments.length) && (typeof(arguments[i])==='object')){
- this.addField(name,type,arguments[i++]);
- } else {
- this.addField(name,type);
- };
- };
- };
- tis.addMethod = function(name,methodkind,params,result,options){
- var t = this.$addMember(name,rtl.tTypeMemberMethod,options);
- t.methodkind = methodkind;
- t.procsig = rtl.newTIProcSig(params);
- t.procsig.resulttype = result?result:null;
- this.methods.push(name);
- return t;
- };
- tis.addProperty = function(name,flags,result,getter,setter,options){
- var t = this.$addMember(name,rtl.tTypeMemberProperty,options);
- t.flags = flags;
- t.typeinfo = result;
- t.getter = getter;
- t.setter = setter;
- // Note: in options: params, stored, defaultvalue
- if (rtl.isArray(t.params)) t.params = rtl.newTIParams(t.params);
- this.properties.push(name);
- if (!rtl.isString(t.stored)) t.stored = "";
- return t;
- };
- tis.getField = function(index){
- return this.members[this.fields[index]];
- };
- tis.getMethod = function(index){
- return this.members[this.methods[index]];
- };
- tis.getProperty = function(index){
- return this.members[this.properties[index]];
- };
- newBaseTI("tTypeInfoRecord",12 /* tkRecord */,rtl.tTypeInfoStruct);
- newBaseTI("tTypeInfoClass",13 /* tkClass */,rtl.tTypeInfoStruct);
- newBaseTI("tTypeInfoClassRef",14 /* tkClassRef */);
- newBaseTI("tTypeInfoInterface",15 /* tkInterface */,rtl.tTypeInfoStruct);
- },
- tSectionRTTI: {
- $module: null,
- $inherited: function(name,ancestor,o){
- if (rtl.debug_rtti){
- rtl.debug('tSectionRTTI.newTI "'+(this.$module?this.$module.$name:"(no module)")
- +'"."'+name+'" ('+ancestor.name+') '+(o?'init':'forward'));
- };
- var t = this[name];
- if (t){
- if (!t.$forward) throw 'duplicate type "'+name+'"';
- if (!ancestor.isPrototypeOf(t)) throw 'typeinfo ancestor mismatch "'+name+'" ancestor="'+ancestor.name+'" t.name="'+t.name+'"';
- } else {
- t = Object.create(ancestor);
- t.name = name;
- t.module = this.module;
- this[name] = t;
- }
- if (o){
- delete t.$forward;
- for (var key in o) if (o.hasOwnProperty(key)) t[key]=o[key];
- } else {
- t.$forward = true;
- }
- return t;
- },
- $Scope: function(name,ancestor,o){
- var t=this.$inherited(name,ancestor,o);
- t.members = {};
- t.names = [];
- t.fields = [];
- t.methods = [];
- t.properties = [];
- return t;
- },
- $TI: function(name,kind,o){ var t=this.$inherited(name,rtl.tTypeInfo,o); t.kind = kind; return t; },
- $Int: function(name,o){ return this.$inherited(name,rtl.tTypeInfoInteger,o); },
- $Enum: function(name,o){ return this.$inherited(name,rtl.tTypeInfoEnum,o); },
- $Set: function(name,o){ return this.$inherited(name,rtl.tTypeInfoSet,o); },
- $StaticArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoArray,o); },
- $DynArray: function(name,o){ return this.$inherited(name,rtl.tTypeInfoDynArray,o); },
- $ProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoProcVar,o); },
- $RefToProcVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoRefToProcVar,o); },
- $MethodVar: function(name,o){ return this.$inherited(name,rtl.tTypeInfoMethodVar,o); },
- $Record: function(name,o){ return this.$Scope(name,rtl.tTypeInfoRecord,o); },
- $Class: function(name,o){ return this.$Scope(name,rtl.tTypeInfoClass,o); },
- $ClassRef: function(name,o){ return this.$inherited(name,rtl.tTypeInfoClassRef,o); },
- $Pointer: function(name,o){ return this.$inherited(name,rtl.tTypeInfoPointer,o); },
- $Interface: function(name,o){ return this.$Scope(name,rtl.tTypeInfoInterface,o); }
- },
- newTIParam: function(param){
- // param is an array, 0=name, 1=type, 2=optional flags
- var t = {
- name: param[0],
- typeinfo: param[1],
- flags: (rtl.isNumber(param[2]) ? param[2] : 0)
- };
- return t;
- },
- newTIParams: function(list){
- // list: optional array of [paramname,typeinfo,optional flags]
- var params = [];
- if (rtl.isArray(list)){
- for (var i=0; i<list.length; i++) params.push(rtl.newTIParam(list[i]));
- };
- return params;
- },
- newTIProcSig: function(params,result,flags){
- var s = {
- params: rtl.newTIParams(params),
- resulttype: result,
- flags: flags
- };
- return s;
- }
- }
- rtl.module("System",[],function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.LineEnding = "\n";
- this.sLineBreak = $mod.LineEnding;
- this.MaxSmallint = 32767;
- this.MinSmallint = -32768;
- this.MaxShortInt = 127;
- this.MinShortInt = -128;
- this.MaxByte = 0xFF;
- this.MaxWord = 0xFFFF;
- this.MaxLongint = 0x7fffffff;
- this.MaxCardinal = 0xffffffff;
- this.Maxint = 2147483647;
- this.IsMultiThread = false;
- this.TTextLineBreakStyle = {"0": "tlbsLF", tlbsLF: 0, "1": "tlbsCRLF", tlbsCRLF: 1, "2": "tlbsCR", tlbsCR: 2};
- this.TGuid = function (s) {
- if (s) {
- this.D1 = s.D1;
- this.D2 = s.D2;
- this.D3 = s.D3;
- this.D4 = s.D4.slice(0);
- } else {
- this.D1 = 0;
- this.D2 = 0;
- this.D3 = 0;
- this.D4 = rtl.arraySetLength(null,0,8);
- };
- this.$equal = function (b) {
- return (this.D1 === b.D1) && ((this.D2 === b.D2) && ((this.D3 === b.D3) && rtl.arrayEq(this.D4,b.D4)));
- };
- };
- rtl.createClass($mod,"TObject",null,function () {
- this.$init = function () {
- };
- this.$final = function () {
- };
- this.Create = function () {
- };
- this.Destroy = function () {
- };
- this.Free = function () {
- this.$destroy("Destroy");
- };
- this.ClassType = function () {
- return this;
- };
- this.ClassNameIs = function (Name) {
- var Result = false;
- Result = $impl.SameText(Name,this.$classname);
- return Result;
- };
- this.InheritsFrom = function (aClass) {
- return (aClass!=null) && ((this==aClass) || aClass.isPrototypeOf(this));
- };
- this.AfterConstruction = function () {
- };
- this.BeforeDestruction = function () {
- };
- this.GetInterface = function (iid, obj) {
- var Result = false;
- var i = iid.$intf;
- if (i){
- i = rtl.getIntfG(this,i.$guid,2);
- if (i){
- obj.set(i);
- return true;
- }
- };
- Result = this.GetInterfaceByStr(rtl.guidrToStr(iid),obj);
- return Result;
- };
- this.GetInterface$1 = function (iidstr, obj) {
- var Result = false;
- Result = this.GetInterfaceByStr(iidstr,obj);
- return Result;
- };
- this.GetInterfaceByStr = function (iidstr, obj) {
- var Result = false;
- if ($mod.IObjectInstance.$equal(rtl.createTGUID(iidstr))) {
- obj.set(this);
- return true;
- };
- var i = rtl.getIntfG(this,iidstr,2);
- obj.set(i);
- return i!==null;
- Result = false;
- return Result;
- };
- this.GetInterfaceWeak = function (iid, obj) {
- var Result = false;
- Result = this.GetInterface(iid,obj);
- if (Result){
- var o = obj.get();
- if (o.$kind==='com'){
- o._Release();
- }
- };
- return Result;
- };
- this.Equals = function (Obj) {
- var Result = false;
- Result = Obj === this;
- return Result;
- };
- this.ToString = function () {
- var Result = "";
- Result = this.$classname;
- return Result;
- };
- });
- this.S_OK = 0;
- this.S_FALSE = 1;
- this.E_NOINTERFACE = -2147467262;
- this.E_UNEXPECTED = -2147418113;
- this.E_NOTIMPL = -2147467263;
- rtl.createInterface($mod,"IUnknown","{00000000-0000-0000-C000-000000000046}",["QueryInterface","_AddRef","_Release"],null,function () {
- this.$kind = "com";
- var $r = this.$rtti;
- $r.addMethod("QueryInterface",1,[["iid",$mod.$rtti["TGuid"],2],["obj",null,4]],rtl.longint);
- $r.addMethod("_AddRef",1,null,rtl.longint);
- $r.addMethod("_Release",1,null,rtl.longint);
- });
- rtl.createInterface($mod,"IInvokable","{88387EF6-BCEE-3E17-9E85-5D491ED4FC10}",[],$mod.IUnknown,function () {
- });
- rtl.createInterface($mod,"IEnumerator","{ECEC7568-4E50-30C9-A2F0-439342DE2ADB}",["GetCurrent","MoveNext","Reset"],$mod.IUnknown);
- rtl.createInterface($mod,"IEnumerable","{9791C368-4E51-3424-A3CE-D4911D54F385}",["GetEnumerator"],$mod.IUnknown);
- rtl.createClass($mod,"TInterfacedObject",$mod.TObject,function () {
- this.$init = function () {
- $mod.TObject.$init.call(this);
- this.fRefCount = 0;
- };
- this.QueryInterface = function (iid, obj) {
- var Result = 0;
- if (this.GetInterface(iid,obj)) {
- Result = 0}
- else Result = -2147467262;
- return Result;
- };
- this._AddRef = function () {
- var Result = 0;
- this.fRefCount += 1;
- Result = this.fRefCount;
- return Result;
- };
- this._Release = function () {
- var Result = 0;
- this.fRefCount -= 1;
- Result = this.fRefCount;
- if (this.fRefCount === 0) this.$destroy("Destroy");
- return Result;
- };
- this.BeforeDestruction = function () {
- if (this.fRefCount !== 0) rtl.raiseE('EHeapMemoryError');
- };
- this.$intfmaps = {};
- rtl.addIntf(this,$mod.IUnknown);
- });
- rtl.createClass($mod,"TAggregatedObject",$mod.TObject,function () {
- this.$init = function () {
- $mod.TObject.$init.call(this);
- this.fController = null;
- };
- this.GetController = function () {
- var Result = null;
- var $ok = false;
- try {
- Result = rtl.setIntfL(Result,this.fController);
- $ok = true;
- } finally {
- if (!$ok) rtl._Release(Result);
- };
- return Result;
- };
- this.QueryInterface = function (iid, obj) {
- var Result = 0;
- Result = this.fController.QueryInterface(iid,obj);
- return Result;
- };
- this._AddRef = function () {
- var Result = 0;
- Result = this.fController._AddRef();
- return Result;
- };
- this._Release = function () {
- var Result = 0;
- Result = this.fController._Release();
- return Result;
- };
- this.Create$1 = function (aController) {
- $mod.TObject.Create.call(this);
- this.fController = aController;
- };
- });
- rtl.createClass($mod,"TContainedObject",$mod.TAggregatedObject,function () {
- this.QueryInterface = function (iid, obj) {
- var Result = 0;
- if (this.GetInterface(iid,obj)) {
- Result = 0}
- else Result = -2147467262;
- return Result;
- };
- this.$intfmaps = {};
- rtl.addIntf(this,$mod.IUnknown);
- });
- this.IObjectInstance = new $mod.TGuid({D1: 0xD91C9AF4, D2: 0x3C93, D3: 0x420F, D4: [0xA3,0x03,0xBF,0x5B,0xA8,0x2B,0xFD,0x23]});
- this.IsConsole = false;
- this.OnParamCount = null;
- this.OnParamStr = null;
- this.ParamCount = function () {
- var Result = 0;
- if ($mod.OnParamCount != null) {
- Result = $mod.OnParamCount()}
- else Result = 0;
- return Result;
- };
- this.ParamStr = function (Index) {
- var Result = "";
- if ($mod.OnParamStr != null) {
- Result = $mod.OnParamStr(Index)}
- else if (Index === 0) {
- Result = "js"}
- else Result = "";
- return Result;
- };
- this.Frac = function (A) {
- return A % 1;
- };
- this.Odd = function (A) {
- return A&1 != 0;
- };
- this.Random = function (Range) {
- return Math.floor(Math.random()*Range);
- };
- this.Sqr = function (A) {
- return A*A;
- };
- this.Sqr$1 = function (A) {
- return A*A;
- };
- this.Trunc = function (A) {
- if (!Math.trunc) {
- Math.trunc = function(v) {
- v = +v;
- if (!isFinite(v)) return v;
- return (v - v % 1) || (v < 0 ? -0 : v === 0 ? v : 0);
- };
- }
- $mod.Trunc = Math.trunc;
- return Math.trunc(A);
- };
- this.DefaultTextLineBreakStyle = $mod.TTextLineBreakStyle.tlbsLF;
- this.Int = function (A) {
- var Result = 0.0;
- Result = Math.trunc(A);
- return Result;
- };
- this.Copy = function (S, Index, Size) {
- if (Index<1) Index = 1;
- return (Size>0) ? S.substring(Index-1,Index+Size-1) : "";
- };
- this.Copy$1 = function (S, Index) {
- if (Index<1) Index = 1;
- return S.substr(Index-1);
- };
- this.Delete = function (S, Index, Size) {
- var h = "";
- if (((Index < 1) || (Index > S.get().length)) || (Size <= 0)) return;
- h = S.get();
- S.set($mod.Copy(h,1,Index - 1) + $mod.Copy$1(h,Index + Size));
- };
- this.Pos = function (Search, InString) {
- return InString.indexOf(Search)+1;
- };
- this.Pos$1 = function (Search, InString, StartAt) {
- return InString.indexOf(Search,StartAt-1)+1;
- };
- this.Insert = function (Insertion, Target, Index) {
- var t = "";
- if (Insertion === "") return;
- t = Target.get();
- if (Index < 1) {
- Target.set(Insertion + t)}
- else if (Index > t.length) {
- Target.set(t + Insertion)}
- else Target.set(($mod.Copy(t,1,Index - 1) + Insertion) + $mod.Copy(t,Index,t.length));
- };
- this.upcase = function (c) {
- return c.toUpperCase();
- };
- this.val = function (S, NI, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x) || (x !== $mod.Int(x))) {
- Code.set(1)}
- else NI.set($mod.Trunc(x));
- };
- this.val$1 = function (S, SI, Code) {
- var X = 0.0;
- Code.set(0);
- X = Number(S);
- if (isNaN(X) || (X !== $mod.Int(X))) {
- Code.set(1)}
- else if ((X < -128) || (X > 127)) {
- Code.set(2)}
- else SI.set($mod.Trunc(X));
- };
- this.val$2 = function (S, B, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x) || (x !== $mod.Int(x))) {
- Code.set(1)}
- else if ((x < 0) || (x > 255)) {
- Code.set(2)}
- else B.set($mod.Trunc(x));
- };
- this.val$3 = function (S, SI, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x) || (x !== $mod.Int(x))) {
- Code.set(1)}
- else if ((x < -32768) || (x > 32767)) {
- Code.set(2)}
- else SI.set($mod.Trunc(x));
- };
- this.val$4 = function (S, W, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x)) {
- Code.set(1)}
- else if ((x < 0) || (x > 65535)) {
- Code.set(2)}
- else W.set($mod.Trunc(x));
- };
- this.val$5 = function (S, I, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x)) {
- Code.set(1)}
- else if (x > 2147483647) {
- Code.set(2)}
- else I.set($mod.Trunc(x));
- };
- this.val$6 = function (S, C, Code) {
- var x = 0.0;
- Code.set(0);
- x = Number(S);
- if (isNaN(x) || (x !== $mod.Int(x))) {
- Code.set(1)}
- else if ((x < 0) || (x > 4294967295)) {
- Code.set(2)}
- else C.set($mod.Trunc(x));
- };
- this.val$7 = function (S, d, Code) {
- var x = 0.0;
- x = Number(S);
- if (isNaN(x)) {
- Code.set(1)}
- else {
- Code.set(0);
- d.set(x);
- };
- };
- this.StringOfChar = function (c, l) {
- var Result = "";
- var i = 0;
- Result = "";
- for (var $l1 = 1, $end2 = l; $l1 <= $end2; $l1++) {
- i = $l1;
- Result = Result + c;
- };
- return Result;
- };
- this.Write = function () {
- var i = 0;
- for (var $l1 = 0, $end2 = rtl.length(arguments) - 1; $l1 <= $end2; $l1++) {
- i = $l1;
- if ($impl.WriteCallBack != null) {
- $impl.WriteCallBack(arguments[i],false)}
- else $impl.WriteBuf = $impl.WriteBuf + ("" + arguments[i]);
- };
- };
- this.Writeln = function () {
- var i = 0;
- var l = 0;
- var s = "";
- l = rtl.length(arguments) - 1;
- if ($impl.WriteCallBack != null) {
- for (var $l1 = 0, $end2 = l; $l1 <= $end2; $l1++) {
- i = $l1;
- $impl.WriteCallBack(arguments[i],i === l);
- };
- } else {
- s = $impl.WriteBuf;
- for (var $l3 = 0, $end4 = l; $l3 <= $end4; $l3++) {
- i = $l3;
- s = s + ("" + arguments[i]);
- };
- console.log(s);
- $impl.WriteBuf = "";
- };
- };
- this.SetWriteCallBack = function (H) {
- var Result = null;
- Result = $impl.WriteCallBack;
- $impl.WriteCallBack = H;
- return Result;
- };
- this.Assigned = function (V) {
- return (V!=undefined) && (V!=null) && (!rtl.isArray(V) || (V.length > 0));
- };
- this.StrictEqual = function (A, B) {
- return A === B;
- };
- this.StrictInequal = function (A, B) {
- return A !== B;
- };
- $mod.$init = function () {
- rtl.exitcode = 0;
- };
- },null,function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.SameText = function (s1, s2) {
- return s1.toLowerCase() == s2.toLowerCase();
- };
- $impl.WriteBuf = "";
- $impl.WriteCallBack = null;
- });
- rtl.module("Types",["System"],function () {
- "use strict";
- var $mod = this;
- this.TDirection = {"0": "FromBeginning", FromBeginning: 0, "1": "FromEnd", FromEnd: 1};
- this.TDuplicates = {"0": "dupIgnore", dupIgnore: 0, "1": "dupAccept", dupAccept: 1, "2": "dupError", dupError: 2};
- this.TSize = function (s) {
- if (s) {
- this.cx = s.cx;
- this.cy = s.cy;
- } else {
- this.cx = 0;
- this.cy = 0;
- };
- this.$equal = function (b) {
- return (this.cx === b.cx) && (this.cy === b.cy);
- };
- };
- this.TPoint = function (s) {
- if (s) {
- this.x = s.x;
- this.y = s.y;
- } else {
- this.x = 0;
- this.y = 0;
- };
- this.$equal = function (b) {
- return (this.x === b.x) && (this.y === b.y);
- };
- };
- this.TRect = function (s) {
- if (s) {
- this.Left = s.Left;
- this.Top = s.Top;
- this.Right = s.Right;
- this.Bottom = s.Bottom;
- } else {
- this.Left = 0;
- this.Top = 0;
- this.Right = 0;
- this.Bottom = 0;
- };
- this.$equal = function (b) {
- return (this.Left === b.Left) && ((this.Top === b.Top) && ((this.Right === b.Right) && (this.Bottom === b.Bottom)));
- };
- };
- this.EqualRect = function (r1, r2) {
- var Result = false;
- Result = (((r1.Left === r2.Left) && (r1.Right === r2.Right)) && (r1.Top === r2.Top)) && (r1.Bottom === r2.Bottom);
- return Result;
- };
- this.Rect = function (Left, Top, Right, Bottom) {
- var Result = new $mod.TRect();
- Result.Left = Left;
- Result.Top = Top;
- Result.Right = Right;
- Result.Bottom = Bottom;
- return Result;
- };
- this.Bounds = function (ALeft, ATop, AWidth, AHeight) {
- var Result = new $mod.TRect();
- Result.Left = ALeft;
- Result.Top = ATop;
- Result.Right = ALeft + AWidth;
- Result.Bottom = ATop + AHeight;
- return Result;
- };
- this.Point = function (x, y) {
- var Result = new $mod.TPoint();
- Result.x = x;
- Result.y = y;
- return Result;
- };
- this.PtInRect = function (aRect, p) {
- var Result = false;
- Result = (((p.y >= aRect.Top) && (p.y < aRect.Bottom)) && (p.x >= aRect.Left)) && (p.x < aRect.Right);
- return Result;
- };
- this.IntersectRect = function (aRect, R1, R2) {
- var Result = false;
- var lRect = new $mod.TRect();
- lRect = new $mod.TRect(R1);
- if (R2.Left > R1.Left) lRect.Left = R2.Left;
- if (R2.Top > R1.Top) lRect.Top = R2.Top;
- if (R2.Right < R1.Right) lRect.Right = R2.Right;
- if (R2.Bottom < R1.Bottom) lRect.Bottom = R2.Bottom;
- if ($mod.IsRectEmpty(lRect)) {
- aRect.set(new $mod.TRect($mod.Rect(0,0,0,0)));
- Result = false;
- } else {
- Result = true;
- aRect.set(new $mod.TRect(lRect));
- };
- return Result;
- };
- this.UnionRect = function (aRect, R1, R2) {
- var Result = false;
- var lRect = new $mod.TRect();
- lRect = new $mod.TRect(R1);
- if (R2.Left < R1.Left) lRect.Left = R2.Left;
- if (R2.Top < R1.Top) lRect.Top = R2.Top;
- if (R2.Right > R1.Right) lRect.Right = R2.Right;
- if (R2.Bottom > R1.Bottom) lRect.Bottom = R2.Bottom;
- if ($mod.IsRectEmpty(lRect)) {
- aRect.set(new $mod.TRect($mod.Rect(0,0,0,0)));
- Result = false;
- } else {
- aRect.set(new $mod.TRect(lRect));
- Result = true;
- };
- return Result;
- };
- this.IsRectEmpty = function (aRect) {
- var Result = false;
- Result = (aRect.Right <= aRect.Left) || (aRect.Bottom <= aRect.Top);
- return Result;
- };
- this.OffsetRect = function (aRect, DX, DY) {
- var Result = false;
- var $with1 = aRect.get();
- $with1.Left += DX;
- $with1.Top += DY;
- $with1.Right += DX;
- $with1.Bottom += DY;
- Result = true;
- return Result;
- };
- this.CenterPoint = function (aRect) {
- var Result = new $mod.TPoint();
- function Avg(a, b) {
- var Result = 0;
- if (a < b) {
- Result = a + ((b - a) >>> 1)}
- else Result = b + ((a - b) >>> 1);
- return Result;
- };
- Result.x = Avg(aRect.Left,aRect.Right);
- Result.y = Avg(aRect.Top,aRect.Bottom);
- return Result;
- };
- this.InflateRect = function (aRect, dx, dy) {
- var Result = false;
- var $with1 = aRect.get();
- $with1.Left -= dx;
- $with1.Top -= dy;
- $with1.Right += dx;
- $with1.Bottom += dy;
- Result = true;
- return Result;
- };
- this.Size = function (AWidth, AHeight) {
- var Result = new $mod.TSize();
- Result.cx = AWidth;
- Result.cy = AHeight;
- return Result;
- };
- this.Size$1 = function (aRect) {
- var Result = new $mod.TSize();
- Result.cx = aRect.Right - aRect.Left;
- Result.cy = aRect.Bottom - aRect.Top;
- return Result;
- };
- });
- rtl.module("JS",["System","Types"],function () {
- "use strict";
- var $mod = this;
- rtl.createClass($mod,"EJS",pas.System.TObject,function () {
- this.$init = function () {
- pas.System.TObject.$init.call(this);
- this.FMessage = "";
- };
- this.Create$1 = function (Msg) {
- this.FMessage = Msg;
- };
- });
- this.TLocaleCompareOptions = function (s) {
- if (s) {
- this.localematched = s.localematched;
- this.usage = s.usage;
- this.sensitivity = s.sensitivity;
- this.ignorePunctuation = s.ignorePunctuation;
- this.numeric = s.numeric;
- this.caseFirst = s.caseFirst;
- } else {
- this.localematched = "";
- this.usage = "";
- this.sensitivity = "";
- this.ignorePunctuation = false;
- this.numeric = false;
- this.caseFirst = "";
- };
- this.$equal = function (b) {
- 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)))));
- };
- };
- this.New = function (aElements) {
- var Result = null;
- var L = 0;
- var I = 0;
- var S = "";
- L = rtl.length(aElements);
- if ((L % 2) === 1) throw $mod.EJS.$create("Create$1",["Number of arguments must be even"]);
- I = 0;
- while (I < L) {
- if (!rtl.isString(aElements[I])) {
- S = String(I);
- throw $mod.EJS.$create("Create$1",[("Argument " + S) + " must be a string."]);
- };
- I += 2;
- };
- I = 0;
- Result = new Object();
- while (I < L) {
- S = "" + aElements[I];
- Result[S] = aElements[I + 1];
- I += 2;
- };
- return Result;
- };
- this.hasValue = function (v) {
- if(v){ return true; } else { return false; };
- };
- this.isBoolean = function (v) {
- return typeof(v) == 'boolean';
- };
- this.isCallback = function (v) {
- return rtl.isObject(v) && rtl.isObject(v.scope) && (rtl.isString(v.fn) || rtl.isFunction(v.fn));
- };
- this.isChar = function (v) {
- return (typeof(v)!="string") && (v.length==1);
- };
- this.isClass = function (v) {
- return (typeof(v)=="object") && (v!=null) && (v.$class == v);
- };
- this.isClassInstance = function (v) {
- return (typeof(v)=="object") && (v!=null) && (v.$class == Object.getPrototypeOf(v));
- };
- this.isInteger = function (v) {
- return Math.floor(v)===v;
- };
- this.isNull = function (v) {
- return v === null;
- };
- this.isRecord = function (v) {
- return (typeof(v)=="function") && (typeof(v.$create) == "function");
- };
- this.isUndefined = function (v) {
- return v == undefined;
- };
- this.isDefined = function (v) {
- return !(v == undefined);
- };
- this.isUTF16Char = function (v) {
- if (typeof(v)!="string") return false;
- if ((v.length==0) || (v.length>2)) return false;
- var code = v.charCodeAt(0);
- if (code < 0xD800){
- if (v.length == 1) return true;
- } else if (code <= 0xDBFF){
- if (v.length==2){
- code = v.charCodeAt(1);
- if (code >= 0xDC00 && code <= 0xDFFF) return true;
- };
- };
- return false;
- };
- this.jsInstanceOf = function (aFunction, aFunctionWithPrototype) {
- return aFunction instanceof aFunctionWithPrototype;
- };
- this.toNumber = function (v) {
- return v-0;
- };
- this.toInteger = function (v) {
- var Result = 0;
- if ($mod.isInteger(v)) {
- Result = Math.floor(v)}
- else Result = 0;
- return Result;
- };
- this.toObject = function (Value) {
- var Result = null;
- if (rtl.isObject(Value)) {
- Result = rtl.getObject(Value)}
- else Result = null;
- return Result;
- };
- this.toArray = function (Value) {
- var Result = null;
- if (rtl.isArray(Value)) {
- Result = rtl.getObject(Value)}
- else Result = null;
- return Result;
- };
- this.toBoolean = function (Value) {
- var Result = false;
- if ($mod.isBoolean(Value)) {
- Result = !(Value == false)}
- else Result = false;
- return Result;
- };
- this.ToString = function (Value) {
- var Result = "";
- if (rtl.isString(Value)) {
- Result = "" + Value}
- else Result = "";
- return Result;
- };
- 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};
- this.GetValueType = function (JS) {
- var Result = 0;
- var t = "";
- if ($mod.isNull(JS)) {
- Result = $mod.TJSValueType.jvtNull}
- else {
- t = typeof(JS);
- if (t === "string") {
- Result = $mod.TJSValueType.jvtString}
- else if (t === "boolean") {
- Result = $mod.TJSValueType.jvtBoolean}
- else if (t === "object") {
- if (rtl.isArray(JS)) {
- Result = $mod.TJSValueType.jvtArray}
- else Result = $mod.TJSValueType.jvtObject;
- } else if (t === "number") if ($mod.isInteger(JS)) {
- Result = $mod.TJSValueType.jvtInteger}
- else Result = $mod.TJSValueType.jvtFloat;
- };
- return Result;
- };
- });
- rtl.module("Web",["System","Types","JS"],function () {
- "use strict";
- var $mod = this;
- this.TJSClientRect = function (s) {
- if (s) {
- this.left = s.left;
- this.top = s.top;
- this.right = s.right;
- this.bottom = s.bottom;
- } else {
- this.left = 0.0;
- this.top = 0.0;
- this.right = 0.0;
- this.bottom = 0.0;
- };
- this.$equal = function (b) {
- return (this.left === b.left) && ((this.top === b.top) && ((this.right === b.right) && (this.bottom === b.bottom)));
- };
- };
- this.TJSElementCreationOptions = function (s) {
- if (s) {
- this.named = s.named;
- } else {
- this.named = "";
- };
- this.$equal = function (b) {
- return this.named === b.named;
- };
- };
- this.TJSEventInit = function (s) {
- if (s) {
- this.bubbles = s.bubbles;
- this.cancelable = s.cancelable;
- this.scoped = s.scoped;
- this.composed = s.composed;
- } else {
- this.bubbles = false;
- this.cancelable = false;
- this.scoped = false;
- this.composed = false;
- };
- this.$equal = function (b) {
- return (this.bubbles === b.bubbles) && ((this.cancelable === b.cancelable) && ((this.scoped === b.scoped) && (this.composed === b.composed)));
- };
- };
- rtl.createClassExt($mod,"TJSAnimationEvent",Event,"",function () {
- this.$init = function () {
- };
- this.$final = function () {
- };
- });
- rtl.createClassExt($mod,"TJSLoadEvent",Event,"",function () {
- this.$init = function () {
- };
- this.$final = function () {
- };
- });
- rtl.createClassExt($mod,"TJsPageTransitionEvent",Event,"",function () {
- this.$init = function () {
- };
- this.$final = function () {
- };
- });
- rtl.createClass($mod,"TJSIDBTransactionMode",pas.System.TObject,function () {
- this.readonly = "readonly";
- this.readwrite = "readwrite";
- this.versionchange = "versionchange";
- });
- this.TJSIDBIndexParameters = function (s) {
- if (s) {
- this.unique = s.unique;
- this.multiEntry = s.multiEntry;
- this.locale = s.locale;
- } else {
- this.unique = false;
- this.multiEntry = false;
- this.locale = "";
- };
- this.$equal = function (b) {
- return (this.unique === b.unique) && ((this.multiEntry === b.multiEntry) && (this.locale === b.locale));
- };
- };
- this.TJSCreateObjectStoreOptions = function (s) {
- if (s) {
- this.keyPath = s.keyPath;
- this.autoIncrement = s.autoIncrement;
- } else {
- this.keyPath = undefined;
- this.autoIncrement = false;
- };
- this.$equal = function (b) {
- return (this.keyPath === b.keyPath) && (this.autoIncrement === b.autoIncrement);
- };
- };
- this.TJSPositionError = function (s) {
- if (s) {
- this.code = s.code;
- this.message = s.message;
- } else {
- this.code = 0;
- this.message = "";
- };
- this.$equal = function (b) {
- return (this.code === b.code) && (this.message === b.message);
- };
- };
- this.TJSPositionOptions = function (s) {
- if (s) {
- this.enableHighAccuracy = s.enableHighAccuracy;
- this.timeout = s.timeout;
- this.maximumAge = s.maximumAge;
- } else {
- this.enableHighAccuracy = false;
- this.timeout = 0;
- this.maximumAge = 0;
- };
- this.$equal = function (b) {
- return (this.enableHighAccuracy === b.enableHighAccuracy) && ((this.timeout === b.timeout) && (this.maximumAge === b.maximumAge));
- };
- };
- this.TJSCoordinates = function (s) {
- if (s) {
- this.latitude = s.latitude;
- this.longitude = s.longitude;
- this.altitude = s.altitude;
- this.accuracy = s.accuracy;
- this.altitudeAccuracy = s.altitudeAccuracy;
- this.heading = s.heading;
- this.speed = s.speed;
- } else {
- this.latitude = 0.0;
- this.longitude = 0.0;
- this.altitude = 0.0;
- this.accuracy = 0.0;
- this.altitudeAccuracy = 0.0;
- this.heading = 0.0;
- this.speed = 0.0;
- };
- this.$equal = function (b) {
- 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))))));
- };
- };
- this.TJSPosition = function (s) {
- if (s) {
- this.coords = new $mod.TJSCoordinates(s.coords);
- this.timestamp = s.timestamp;
- } else {
- this.coords = new $mod.TJSCoordinates();
- this.timestamp = "";
- };
- this.$equal = function (b) {
- return this.coords.$equal(b.coords) && (this.timestamp === b.timestamp);
- };
- };
- this.TJSServiceWorkerContainerOptions = function (s) {
- if (s) {
- this.scope = s.scope;
- } else {
- this.scope = "";
- };
- this.$equal = function (b) {
- return this.scope === b.scope;
- };
- };
- this.TJSTextMetrics = function (s) {
- if (s) {
- this.width = s.width;
- this.actualBoundingBoxLeft = s.actualBoundingBoxLeft;
- this.actualBoundingBoxRight = s.actualBoundingBoxRight;
- this.fontBoundingBoxAscent = s.fontBoundingBoxAscent;
- this.fontBoundingBoxDescent = s.fontBoundingBoxDescent;
- this.actualBoundingBoxAscent = s.actualBoundingBoxAscent;
- this.actualBoundingBoxDescent = s.actualBoundingBoxDescent;
- this.emHeightAscent = s.emHeightAscent;
- this.emHeightDescent = s.emHeightDescent;
- this.hangingBaseline = s.hangingBaseline;
- this.alphabeticBaseline = s.alphabeticBaseline;
- this.ideographicBaseline = s.ideographicBaseline;
- } else {
- this.width = 0.0;
- this.actualBoundingBoxLeft = 0.0;
- this.actualBoundingBoxRight = 0.0;
- this.fontBoundingBoxAscent = 0.0;
- this.fontBoundingBoxDescent = 0.0;
- this.actualBoundingBoxAscent = 0.0;
- this.actualBoundingBoxDescent = 0.0;
- this.emHeightAscent = 0.0;
- this.emHeightDescent = 0.0;
- this.hangingBaseline = 0.0;
- this.alphabeticBaseline = 0.0;
- this.ideographicBaseline = 0.0;
- };
- this.$equal = function (b) {
- 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)))))))))));
- };
- };
- this.TJSWheelEventInit = function (s) {
- if (s) {
- this.deltaX = s.deltaX;
- this.deltaY = s.deltaY;
- this.deltaZ = s.deltaZ;
- this.deltaMode = s.deltaMode;
- } else {
- this.deltaX = 0.0;
- this.deltaY = 0.0;
- this.deltaZ = 0.0;
- this.deltaMode = 0;
- };
- this.$equal = function (b) {
- return (this.deltaX === b.deltaX) && ((this.deltaY === b.deltaY) && ((this.deltaZ === b.deltaZ) && (this.deltaMode === b.deltaMode)));
- };
- };
- rtl.createClass($mod,"TJSKeyNames",pas.System.TObject,function () {
- this.Alt = "Alt";
- this.AltGraph = "AltGraph";
- this.CapsLock = "CapsLock";
- this.Control = "Control";
- this.Fn = "Fn";
- this.FnLock = "FnLock";
- this.Hyper = "Hyper";
- this.Meta = "Meta";
- this.NumLock = "NumLock";
- this.ScrollLock = "ScrollLock";
- this.Shift = "Shift";
- this.Super = "Super";
- this.symbol = "Symbol";
- this.SymbolLock = "SymbolLock";
- this.Enter = "Enter";
- this.Tab = "Tab";
- this.Space = " ";
- this.ArrowDown = "ArrowDown";
- this.ArrowLeft = "ArrowLeft";
- this.ArrowRight = "ArrowRight";
- this.ArrowUp = "ArrowUp";
- this._End = "End";
- this.Home = "Home";
- this.PageDown = "PageDown";
- this.PageUp = "PageUp";
- this.BackSpace = "Backspace";
- this.Clear = "Clear";
- this.Copy = "Copy";
- this.CrSel = "CrSel";
- this.Cut = "Cut";
- this.Delete = "Delete";
- this.EraseEof = "EraseEof";
- this.ExSel = "ExSel";
- this.Insert = "Insert";
- this.Paste = "Paste";
- this.Redo = "Redo";
- this.Undo = "Undo";
- this.Accept = "Accept";
- this.Again = "Again";
- this.Attn = "Attn";
- this.Cancel = "Cancel";
- this.ContextMenu = "Contextmenu";
- this.Escape = "Escape";
- this.Execute = "Execute";
- this.Find = "Find";
- this.Finish = "Finish";
- this.Help = "Help";
- this.Pause = "Pause";
- this.Play = "Play";
- this.Props = "Props";
- this.Select = "Select";
- this.ZoomIn = "ZoomIn";
- this.ZoomOut = "ZoomOut";
- this.BrightnessDown = "BrightnessDown";
- this.BrightnessUp = "BrightnessUp";
- this.Eject = "Eject";
- this.LogOff = "LogOff";
- this.Power = "Power";
- this.PowerOff = "PowerOff";
- this.PrintScreen = "PrintScreen";
- this.Hibernate = "Hibernate";
- this.Standby = "Standby";
- this.WakeUp = "WakeUp";
- this.AllCandidates = "AllCandidates";
- this.Alphanumeric = "Alphanumeric";
- this.CodeInput = "CodeInput";
- this.Compose = "Compose";
- this.Convert = "Convert";
- this.Dead = "Dead";
- this.FinalMode = "FinalMode";
- this.GroupFirst = "GroupFirst";
- this.GroupLast = "GroupLast";
- this.GroupNext = "GroupNext";
- this.GroupPrevious = "GroupPrevious";
- this.ModelChange = "ModelChange";
- this.NextCandidate = "NextCandidate";
- this.NonConvert = "NonConvert";
- this.PreviousCandidate = "PreviousCandidate";
- this.Process = "Process";
- this.SingleCandidate = "SingleCandidate";
- this.HangulMode = "HangulMode";
- this.HanjaMode = "HanjaMode";
- this.JunjaMode = "JunjaMode";
- this.Eisu = "Eisu";
- this.Hankaku = "Hankaku";
- this.Hiranga = "Hiranga";
- this.HirangaKatakana = "HirangaKatakana";
- this.KanaMode = "KanaMode";
- this.Katakana = "Katakana";
- this.Romaji = "Romaji";
- this.Zenkaku = "Zenkaku";
- this.ZenkakuHanaku = "ZenkakuHanaku";
- this.F1 = "F1";
- this.F2 = "F2";
- this.F3 = "F3";
- this.F4 = "F4";
- this.F5 = "F5";
- this.F6 = "F6";
- this.F7 = "F7";
- this.F8 = "F8";
- this.F9 = "F9";
- this.F10 = "F10";
- this.F11 = "F11";
- this.F12 = "F12";
- this.F13 = "F13";
- this.F14 = "F14";
- this.F15 = "F15";
- this.F16 = "F16";
- this.F17 = "F17";
- this.F18 = "F18";
- this.F19 = "F19";
- this.F20 = "F20";
- this.Soft1 = "Soft1";
- this.Soft2 = "Soft2";
- this.Soft3 = "Soft3";
- this.Soft4 = "Soft4";
- this.Decimal = "Decimal";
- this.Key11 = "Key11";
- this.Key12 = "Key12";
- this.Multiply = "Multiply";
- this.Add = "Add";
- this.NumClear = "Clear";
- this.Divide = "Divide";
- this.Subtract = "Subtract";
- this.Separator = "Separator";
- this.AppSwitch = "AppSwitch";
- this.Call = "Call";
- this.Camera = "Camera";
- this.CameraFocus = "CameraFocus";
- this.EndCall = "EndCall";
- this.GoBack = "GoBack";
- this.GoHome = "GoHome";
- this.HeadsetHook = "HeadsetHook";
- this.LastNumberRedial = "LastNumberRedial";
- this.Notification = "Notification";
- this.MannerMode = "MannerMode";
- this.VoiceDial = "VoiceDial";
- });
- });
- rtl.module("browserconsole",["System","JS","Web"],function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.DefaultMaxConsoleLines = 25;
- 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) + "}";
- 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) + "}";
- this.ConsoleElementID = "";
- this.ConsoleStyle = "";
- this.MaxConsoleLines = 0;
- this.ConsoleLinesToBrowserLog = false;
- this.ResetConsole = function () {
- if ($impl.LinesParent === null) return;
- while ($impl.LinesParent.firstElementChild !== null) $impl.LinesParent.removeChild($impl.LinesParent.firstElementChild);
- $impl.AppendLine();
- };
- this.InitConsole = function () {
- if ($impl.ConsoleElement === null) return;
- if ($impl.ConsoleElement.nodeName.toLowerCase() !== "body") {
- while ($impl.ConsoleElement.firstElementChild !== null) $impl.ConsoleElement.removeChild($impl.ConsoleElement.firstElementChild);
- };
- $impl.StyleElement = document.createElement("style");
- $impl.StyleElement.innerText = $mod.ConsoleStyle;
- $impl.ConsoleElement.appendChild($impl.StyleElement);
- $impl.LinesParent = document.createElement("div");
- $impl.ConsoleElement.appendChild($impl.LinesParent);
- };
- this.HookConsole = function () {
- $impl.ConsoleElement = null;
- if ($mod.ConsoleElementID !== "") $impl.ConsoleElement = document.getElementById($mod.ConsoleElementID);
- if ($impl.ConsoleElement === null) $impl.ConsoleElement = document.body;
- if ($impl.ConsoleElement === null) return;
- $mod.InitConsole();
- $mod.ResetConsole();
- pas.System.SetWriteCallBack($impl.WriteConsole);
- };
- $mod.$init = function () {
- $mod.ConsoleLinesToBrowserLog = true;
- $mod.ConsoleElementID = "pasjsconsole";
- $mod.ConsoleStyle = $mod.DefaultConsoleStyle;
- $mod.MaxConsoleLines = 25;
- $mod.HookConsole();
- };
- },null,function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.LastLine = null;
- $impl.StyleElement = null;
- $impl.LinesParent = null;
- $impl.ConsoleElement = null;
- $impl.AppendLine = function () {
- var CurrentCount = 0;
- var S = null;
- CurrentCount = 0;
- S = $impl.LinesParent.firstChild;
- while (S != null) {
- CurrentCount += 1;
- S = S.nextSibling;
- };
- while (CurrentCount > $mod.MaxConsoleLines) {
- CurrentCount -= 1;
- $impl.LinesParent.removeChild($impl.LinesParent.firstChild);
- };
- $impl.LastLine = document.createElement("div");
- $impl.LastLine.className = "pasconsole";
- $impl.LinesParent.appendChild($impl.LastLine);
- };
- $impl.WriteConsole = function (S, NewLine) {
- var CL = "";
- CL = $impl.LastLine.innerText;
- CL = CL + ("" + S);
- $impl.LastLine.innerText = CL;
- if (NewLine) {
- if ($mod.ConsoleLinesToBrowserLog) window.console.log(CL);
- $impl.AppendLine();
- };
- };
- });
- rtl.module("vectors",["System","browserconsole","JS"],function () {
- "use strict";
- var $mod = this;
- rtl.createClassExt($mod,"TVec2",Array,"",function () {
- this.$init = function () {
- };
- this.$final = function () {
- };
- this.SetX = function (newValue) {
- this[0] = newValue;
- };
- this.SetY = function (newValue) {
- this[1] = newValue;
- };
- this.GetX = function () {
- var Result = 0.0;
- Result = rtl.getNumber(this[0]);
- return Result;
- };
- this.GetY = function () {
- var Result = 0.0;
- Result = rtl.getNumber(this[1]);
- return Result;
- };
- this.Create = function () {
- };
- });
- });
- rtl.module("webgl",["System","JS","Web"],function () {
- "use strict";
- var $mod = this;
- });
- rtl.module("RTLConsts",["System"],function () {
- "use strict";
- var $mod = this;
- this.SArgumentMissing = 'Missing argument in format "%s"';
- this.SInvalidFormat = 'Invalid format specifier : "%s"';
- this.SInvalidArgIndex = 'Invalid argument index in format: "%s"';
- this.SListCapacityError = "List capacity (%s) exceeded.";
- this.SListCountError = "List count (%s) out of bounds.";
- this.SListIndexError = "List index (%s) out of bounds";
- this.SSortedListError = "Operation not allowed on sorted list";
- this.SDuplicateString = "String list does not allow duplicates";
- this.SErrFindNeedsSortedList = "Cannot use find on unsorted list";
- this.SInvalidName = 'Invalid component name: "%s"';
- this.SInvalidBoolean = '"%s" is not a valid boolean.';
- this.SDuplicateName = 'Duplicate component name: "%s"';
- this.SErrInvalidDate = 'Invalid date: "%s"';
- this.SErrInvalidTimeFormat = 'Invalid time format: "%s"';
- this.SInvalidDateFormat = 'Invalid date format: "%s"';
- this.SCantReadPropertyS = 'Cannot read property "%s"';
- this.SCantWritePropertyS = 'Cannot write property "%s"';
- this.SErrPropertyNotFound = 'Unknown property: "%s"';
- this.SIndexedPropertyNeedsParams = 'Indexed property "%s" needs parameters';
- this.SErrInvalidInteger = 'Invalid integer value: "%s"';
- this.SErrInvalidFloat = 'Invalid floating-point value: "%s"';
- this.SInvalidDateTime = "Invalid date-time value: %s";
- this.SInvalidCurrency = "Invalid currency value: %s";
- this.SErrInvalidDayOfWeek = "%d is not a valid day of the week";
- this.SErrInvalidTimeStamp = 'Invalid date\/timestamp : "%s"';
- this.SErrInvalidDateWeek = "%d %d %d is not a valid dateweek";
- this.SErrInvalidDayOfYear = "Year %d does not have a day number %d";
- this.SErrInvalidDateMonthWeek = "Year %d, month %d, Week %d and day %d is not a valid date.";
- this.SErrInvalidDayOfWeekInMonth = "Year %d Month %d NDow %d DOW %d is not a valid date";
- this.SInvalidJulianDate = "%f Julian cannot be represented as a DateTime";
- this.SErrInvalidHourMinuteSecMsec = "%d:%d:%d.%d is not a valid time specification";
- this.SInvalidGUID = '"%s" is not a valid GUID value';
- });
- rtl.module("SysUtils",["System","RTLConsts","JS"],function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.FreeAndNil = function (Obj) {
- var o = null;
- o = Obj.get();
- if (o === null) return;
- Obj.set(null);
- o.$destroy("Destroy");
- };
- this.TFloatRec = function (s) {
- if (s) {
- this.Exponent = s.Exponent;
- this.Negative = s.Negative;
- this.Digits = s.Digits;
- } else {
- this.Exponent = 0;
- this.Negative = false;
- this.Digits = [];
- };
- this.$equal = function (b) {
- return (this.Exponent === b.Exponent) && ((this.Negative === b.Negative) && (this.Digits === b.Digits));
- };
- };
- this.TEndian = {"0": "Little", Little: 0, "1": "Big", Big: 1};
- rtl.createClass($mod,"Exception",pas.System.TObject,function () {
- this.$init = function () {
- pas.System.TObject.$init.call(this);
- this.fMessage = "";
- this.fHelpContext = 0;
- };
- this.Create$1 = function (Msg) {
- this.fMessage = Msg;
- };
- this.CreateFmt = function (Msg, Args) {
- this.fMessage = $mod.Format(Msg,Args);
- };
- this.CreateHelp = function (Msg, AHelpContext) {
- this.fMessage = Msg;
- this.fHelpContext = AHelpContext;
- };
- this.CreateFmtHelp = function (Msg, Args, AHelpContext) {
- this.fMessage = $mod.Format(Msg,Args);
- this.fHelpContext = AHelpContext;
- };
- this.ToString = function () {
- var Result = "";
- Result = (this.$classname + ": ") + this.fMessage;
- return Result;
- };
- });
- rtl.createClass($mod,"EExternal",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EMathError",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EInvalidOp",$mod.EMathError,function () {
- });
- rtl.createClass($mod,"EZeroDivide",$mod.EMathError,function () {
- });
- rtl.createClass($mod,"EOverflow",$mod.EMathError,function () {
- });
- rtl.createClass($mod,"EUnderflow",$mod.EMathError,function () {
- });
- rtl.createClass($mod,"EAbort",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EInvalidCast",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EAssertionFailed",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EObjectCheck",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EConvertError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EFormatError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EIntError",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EDivByZero",$mod.EIntError,function () {
- });
- rtl.createClass($mod,"ERangeError",$mod.EIntError,function () {
- });
- rtl.createClass($mod,"EIntOverflow",$mod.EIntError,function () {
- });
- rtl.createClass($mod,"EInOutError",$mod.Exception,function () {
- this.$init = function () {
- $mod.Exception.$init.call(this);
- this.ErrorCode = 0;
- };
- });
- rtl.createClass($mod,"EHeapMemoryError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EExternalException",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EInvalidPointer",$mod.EHeapMemoryError,function () {
- });
- rtl.createClass($mod,"EOutOfMemory",$mod.EHeapMemoryError,function () {
- });
- rtl.createClass($mod,"EVariantError",$mod.Exception,function () {
- this.$init = function () {
- $mod.Exception.$init.call(this);
- this.ErrCode = 0;
- };
- this.CreateCode = function (Code) {
- this.ErrCode = Code;
- };
- });
- rtl.createClass($mod,"EAccessViolation",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EBusError",$mod.EAccessViolation,function () {
- });
- rtl.createClass($mod,"EPrivilege",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EStackOverflow",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EControlC",$mod.EExternal,function () {
- });
- rtl.createClass($mod,"EAbstractError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EPropReadOnly",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EPropWriteOnly",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EIntfCastError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EInvalidContainer",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EInvalidInsert",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EPackageError",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EOSError",$mod.Exception,function () {
- this.$init = function () {
- $mod.Exception.$init.call(this);
- this.ErrorCode = 0;
- };
- });
- rtl.createClass($mod,"ESafecallException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"ENoThreadSupport",$mod.Exception,function () {
- });
- rtl.createClass($mod,"ENoWideStringSupport",$mod.Exception,function () {
- });
- rtl.createClass($mod,"ENotImplemented",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EArgumentException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EArgumentOutOfRangeException",$mod.EArgumentException,function () {
- });
- rtl.createClass($mod,"EArgumentNilException",$mod.EArgumentException,function () {
- });
- rtl.createClass($mod,"EPathTooLongException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"ENotSupportedException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EDirectoryNotFoundException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EFileNotFoundException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"EPathNotFoundException",$mod.Exception,function () {
- });
- rtl.createClass($mod,"ENoConstructException",$mod.Exception,function () {
- });
- this.EmptyStr = "";
- this.EmptyWideStr = "";
- this.HexDisplayPrefix = "$";
- this.LeadBytes = {};
- this.CharInSet = function (Ch, CSet) {
- var Result = false;
- var I = 0;
- Result = false;
- I = rtl.length(CSet) - 1;
- while (!Result && (I >= 0)) {
- Result = Ch === CSet[I];
- I -= 1;
- };
- return Result;
- };
- this.LeftStr = function (S, Count) {
- return (Count>0) ? S.substr(0,Count) : "";
- };
- this.RightStr = function (S, Count) {
- var l = S.length;
- return (Count<1) ? "" : ( Count>=l ? S : S.substr(l-Count));
- };
- this.Trim = function (S) {
- return S.trim();
- };
- this.TrimLeft = function (S) {
- return S.replace(/^[\s\uFEFF\xA0\x00-\x1f]+/,'');
- };
- this.TrimRight = function (S) {
- return S.replace(/[\s\uFEFF\xA0\x00-\x1f]+$/,'');
- };
- this.UpperCase = function (s) {
- return s.toUpperCase();
- };
- this.LowerCase = function (s) {
- return s.toLowerCase();
- };
- this.CompareStr = function (s1, s2) {
- var l1 = s1.length;
- var l2 = s2.length;
- if (l1<=l2){
- var s = s2.substr(0,l1);
- if (s1<s){ return -1;
- } else if (s1>s){ return 1;
- } else { return l1<l2 ? -1 : 0; };
- } else {
- var s = s1.substr(0,l2);
- if (s<s2){ return -1;
- } else { return 1; };
- };
- };
- this.SameStr = function (s1, s2) {
- return s1 == s2;
- };
- this.CompareText = function (s1, s2) {
- var l1 = s1.toLowerCase();
- var l2 = s2.toLowerCase();
- if (l1>l2){ return 1;
- } else if (l1<l2){ return -1;
- } else { return 0; };
- };
- this.SameText = function (s1, s2) {
- return s1.toLowerCase() == s2.toLowerCase();
- };
- this.AnsiCompareText = function (s1, s2) {
- return s1.localeCompare(s2);
- };
- this.AnsiSameText = function (s1, s2) {
- return s1.localeCompare(s2) == 0;
- };
- this.AnsiCompareStr = function (s1, s2) {
- var Result = 0;
- Result = $mod.CompareText(s1,s2);
- return Result;
- };
- this.AppendStr = function (Dest, S) {
- Dest.set(Dest.get() + S);
- };
- this.Format = function (Fmt, Args) {
- var Result = "";
- var ChPos = 0;
- var OldPos = 0;
- var ArgPos = 0;
- var DoArg = 0;
- var Len = 0;
- var Hs = "";
- var ToAdd = "";
- var Index = 0;
- var Width = 0;
- var Prec = 0;
- var Left = false;
- var Fchar = "";
- var vq = 0;
- function ReadFormat() {
- var Result = "";
- var Value = 0;
- function ReadInteger() {
- var Code = 0;
- var ArgN = 0;
- if (Value !== -1) return;
- OldPos = ChPos;
- while (((ChPos <= Len) && (Fmt.charAt(ChPos - 1) <= "9")) && (Fmt.charAt(ChPos - 1) >= "0")) ChPos += 1;
- if (ChPos > Len) $impl.DoFormatError(1,Fmt);
- if (Fmt.charAt(ChPos - 1) === "*") {
- if (Index === -1) {
- ArgN = ArgPos}
- else {
- ArgN = Index;
- Index += 1;
- };
- if ((ChPos > OldPos) || (ArgN > (rtl.length(Args) - 1))) $impl.DoFormatError(1,Fmt);
- ArgPos = ArgN + 1;
- if (rtl.isNumber(Args[ArgN]) && pas.JS.isInteger(Args[ArgN])) {
- Value = Math.floor(Args[ArgN])}
- else $impl.DoFormatError(1,Fmt);
- ChPos += 1;
- } else {
- if (OldPos < ChPos) {
- pas.System.val(pas.System.Copy(Fmt,OldPos,ChPos - OldPos),{get: function () {
- return Value;
- }, set: function (v) {
- Value = v;
- }},{get: function () {
- return Code;
- }, set: function (v) {
- Code = v;
- }});
- if (Code > 0) $impl.DoFormatError(1,Fmt);
- } else Value = -1;
- };
- };
- function ReadIndex() {
- if (Fmt.charAt(ChPos - 1) !== ":") {
- ReadInteger()}
- else Value = 0;
- if (Fmt.charAt(ChPos - 1) === ":") {
- if (Value === -1) $impl.DoFormatError(2,Fmt);
- Index = Value;
- Value = -1;
- ChPos += 1;
- };
- };
- function ReadLeft() {
- if (Fmt.charAt(ChPos - 1) === "-") {
- Left = true;
- ChPos += 1;
- } else Left = false;
- };
- function ReadWidth() {
- ReadInteger();
- if (Value !== -1) {
- Width = Value;
- Value = -1;
- };
- };
- function ReadPrec() {
- if (Fmt.charAt(ChPos - 1) === ".") {
- ChPos += 1;
- ReadInteger();
- if (Value === -1) Value = 0;
- Prec = Value;
- };
- };
- Index = -1;
- Width = -1;
- Prec = -1;
- Value = -1;
- ChPos += 1;
- if (Fmt.charAt(ChPos - 1) === "%") {
- Result = "%";
- return Result;
- };
- ReadIndex();
- ReadLeft();
- ReadWidth();
- ReadPrec();
- Result = pas.System.upcase(Fmt.charAt(ChPos - 1));
- return Result;
- };
- function Checkarg(AT, err) {
- var Result = false;
- Result = false;
- if (Index === -1) {
- DoArg = ArgPos}
- else DoArg = Index;
- ArgPos = DoArg + 1;
- if ((DoArg > (rtl.length(Args) - 1)) || (pas.JS.GetValueType(Args[DoArg]) !== AT)) {
- if (err) $impl.DoFormatError(3,Fmt);
- ArgPos -= 1;
- return Result;
- };
- Result = true;
- return Result;
- };
- Result = "";
- Len = Fmt.length;
- ChPos = 1;
- OldPos = 1;
- ArgPos = 0;
- while (ChPos <= Len) {
- while ((ChPos <= Len) && (Fmt.charAt(ChPos - 1) !== "%")) ChPos += 1;
- if (ChPos > OldPos) Result = Result + pas.System.Copy(Fmt,OldPos,ChPos - OldPos);
- if (ChPos < Len) {
- Fchar = ReadFormat();
- var $tmp1 = Fchar;
- if ($tmp1 === "D") {
- Checkarg(pas.JS.TJSValueType.jvtInteger,true);
- ToAdd = $mod.IntToStr(Math.floor(Args[DoArg]));
- Width = Math.abs(Width);
- Index = Prec - ToAdd.length;
- if (ToAdd.charAt(0) !== "-") {
- ToAdd = pas.System.StringOfChar("0",Index) + ToAdd}
- else pas.System.Insert(pas.System.StringOfChar("0",Index + 1),{get: function () {
- return ToAdd;
- }, set: function (v) {
- ToAdd = v;
- }},2);
- } else if ($tmp1 === "U") {
- Checkarg(pas.JS.TJSValueType.jvtInteger,true);
- if (Math.floor(Args[DoArg]) < 0) $impl.DoFormatError(3,Fmt);
- ToAdd = $mod.IntToStr(Math.floor(Args[DoArg]));
- Width = Math.abs(Width);
- Index = Prec - ToAdd.length;
- ToAdd = pas.System.StringOfChar("0",Index) + ToAdd;
- } else if ($tmp1 === "E") {
- 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);
- } else if ($tmp1 === "F") {
- 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);
- } else if ($tmp1 === "G") {
- 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);
- } else if ($tmp1 === "N") {
- 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);
- } else if ($tmp1 === "M") {
- 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);
- } else if ($tmp1 === "S") {
- Checkarg(pas.JS.TJSValueType.jvtString,true);
- Hs = "" + Args[DoArg];
- Index = Hs.length;
- if ((Prec !== -1) && (Index > Prec)) Index = Prec;
- ToAdd = pas.System.Copy(Hs,1,Index);
- } else if ($tmp1 === "P") {
- Checkarg(pas.JS.TJSValueType.jvtInteger,true);
- ToAdd = $mod.IntToHex(Math.floor(Args[DoArg]),31);
- } else if ($tmp1 === "X") {
- Checkarg(pas.JS.TJSValueType.jvtInteger,true);
- vq = Math.floor(Args[DoArg]);
- Index = 31;
- if (Prec > Index) {
- ToAdd = $mod.IntToHex(vq,Index)}
- else {
- Index = 1;
- while (((1 << (Index * 4)) <= vq) && (Index < 16)) Index += 1;
- if (Index > Prec) Prec = Index;
- ToAdd = $mod.IntToHex(vq,Prec);
- };
- } else if ($tmp1 === "%") ToAdd = "%";
- if (Width !== -1) if (ToAdd.length < Width) if (!Left) {
- ToAdd = pas.System.StringOfChar(" ",Width - ToAdd.length) + ToAdd}
- else ToAdd = ToAdd + pas.System.StringOfChar(" ",Width - ToAdd.length);
- Result = Result + ToAdd;
- };
- ChPos += 1;
- OldPos = ChPos;
- };
- return Result;
- };
- this.LocaleCompare = function (s1, s2, locales) {
- return s1.localeCompare(s2,locales) == 0;
- };
- this.NormalizeStr = function (S, Norm) {
- return S.normalize(Norm);
- };
- var Alpha = rtl.createSet(null,65,90,null,97,122,95);
- var AlphaNum = rtl.unionSet(Alpha,rtl.createSet(null,48,57));
- var Dot = ".";
- this.IsValidIdent = function (Ident, AllowDots, StrictDots) {
- var Result = false;
- var First = false;
- var I = 0;
- var Len = 0;
- Len = Ident.length;
- if (Len < 1) return false;
- First = true;
- Result = false;
- I = 1;
- while (I <= Len) {
- if (First) {
- if (!(Ident.charCodeAt(I - 1) in Alpha)) return Result;
- First = false;
- } else if (AllowDots && (Ident.charAt(I - 1) === Dot)) {
- if (StrictDots) {
- if (I >= Len) return Result;
- First = true;
- };
- } else if (!(Ident.charCodeAt(I - 1) in AlphaNum)) return Result;
- I = I + 1;
- };
- Result = true;
- return Result;
- };
- this.TStringReplaceFlag = {"0": "rfReplaceAll", rfReplaceAll: 0, "1": "rfIgnoreCase", rfIgnoreCase: 1};
- this.StringReplace = function (aOriginal, aSearch, aReplace, Flags) {
- var Result = "";
- var REFlags = "";
- var REString = "";
- REFlags = "";
- if ($mod.TStringReplaceFlag.rfReplaceAll in Flags) REFlags = "g";
- if ($mod.TStringReplaceFlag.rfIgnoreCase in Flags) REFlags = REFlags + "i";
- REString = aSearch.replace(new RegExp($impl.RESpecials,"g"),"\\$1");
- Result = aOriginal.replace(new RegExp(REString,REFlags),aReplace);
- return Result;
- };
- this.QuoteString = function (aOriginal, AQuote) {
- var Result = "";
- var REString = "";
- REString = AQuote.replace(new RegExp(aOriginal,"g"),"\\\\$1");
- Result = (AQuote + aOriginal.replace(new RegExp(REString,"g"),"$1\\$1")) + AQuote;
- return Result;
- };
- this.IsDelimiter = function (Delimiters, S, Index) {
- var Result = false;
- Result = false;
- if ((Index > 0) && (Index <= S.length)) Result = pas.System.Pos(S.charAt(Index - 1),Delimiters) !== 0;
- return Result;
- };
- this.AdjustLineBreaks = function (S) {
- var Result = "";
- Result = $mod.AdjustLineBreaks$1(S,pas.System.DefaultTextLineBreakStyle);
- return Result;
- };
- this.AdjustLineBreaks$1 = function (S, Style) {
- var Result = "";
- var I = 0;
- var L = 0;
- var Res = "";
- function Add(C) {
- Res = Res + C;
- };
- I = 0;
- L = S.length;
- Result = "";
- while (I <= L) {
- var $tmp1 = S.charAt(I - 1);
- if ($tmp1 === "\n") {
- if (Style in rtl.createSet(pas.System.TTextLineBreakStyle.tlbsCRLF,pas.System.TTextLineBreakStyle.tlbsCR)) Add("\r");
- if (Style === pas.System.TTextLineBreakStyle.tlbsCRLF) Add("\n");
- I += 1;
- } else if ($tmp1 === "\r") {
- if (Style === pas.System.TTextLineBreakStyle.tlbsCRLF) Add("\r");
- Add("\n");
- I += 1;
- if (S.charAt(I - 1) === "\n") I += 1;
- } else {
- Add(S.charAt(I - 1));
- I += 1;
- };
- };
- Result = Res;
- return Result;
- };
- var Quotes = rtl.createSet(39,34);
- this.WrapText = function (Line, BreakStr, BreakChars, MaxCol) {
- var Result = "";
- var L = "";
- var C = "";
- var LQ = "";
- var BC = "";
- var P = 0;
- var BLen = 0;
- var Len = 0;
- var HB = false;
- var IBC = false;
- Result = "";
- L = Line;
- BLen = BreakStr.length;
- if (BLen > 0) {
- BC = BreakStr.charAt(0)}
- else BC = "\x00";
- Len = L.length;
- while (Len > 0) {
- P = 1;
- LQ = "\x00";
- HB = false;
- IBC = false;
- while (((P <= Len) && ((P <= MaxCol) || !IBC)) && ((LQ !== "\x00") || !HB)) {
- C = L.charAt(P - 1);
- if (C === LQ) {
- LQ = "\x00"}
- else if (C.charCodeAt() in Quotes) LQ = C;
- if (LQ !== "\x00") {
- P += 1}
- else {
- HB = (C === BC) && (BreakStr === pas.System.Copy(L,P,BLen));
- if (HB) {
- P += BLen}
- else {
- if (P >= MaxCol) IBC = $mod.CharInSet(C,BreakChars);
- P += 1;
- };
- };
- };
- Result = Result + pas.System.Copy(L,1,P - 1);
- pas.System.Delete({get: function () {
- return L;
- }, set: function (v) {
- L = v;
- }},1,P - 1);
- Len = L.length;
- if ((Len > 0) && !HB) Result = Result + BreakStr;
- };
- return Result;
- };
- this.WrapText$1 = function (Line, MaxCol) {
- var Result = "";
- Result = $mod.WrapText(Line,pas.System.sLineBreak,[" ","-","\t"],MaxCol);
- return Result;
- };
- this.IntToStr = function (Value) {
- var Result = "";
- Result = "" + Value;
- return Result;
- };
- this.TryStrToInt = function (S, res) {
- var Result = false;
- var NI = 0;
- Result = $mod.TryStrToInt$1(S,{get: function () {
- return NI;
- }, set: function (v) {
- NI = v;
- }});
- if (Result) res.set(NI);
- return Result;
- };
- this.TryStrToInt$1 = function (S, res) {
- var Result = false;
- var Radix = 10;
- var F = "";
- var N = "";
- var J = undefined;
- N = S;
- F = pas.System.Copy(N,1,1);
- if (F === "$") {
- Radix = 16}
- else if (F === "&") {
- Radix = 8}
- else if (F === "%") Radix = 2;
- if (Radix !== 10) pas.System.Delete({get: function () {
- return N;
- }, set: function (v) {
- N = v;
- }},1,1);
- J = parseInt(N,Radix);
- Result = !isNaN(J);
- if (Result) res.set(Math.floor(J));
- return Result;
- };
- this.StrToIntDef = function (S, aDef) {
- var Result = 0;
- var R = 0;
- if ($mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }})) {
- Result = R}
- else Result = aDef;
- return Result;
- };
- this.StrToIntDef$1 = function (S, aDef) {
- var Result = 0;
- var R = 0;
- if ($mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }})) {
- Result = R}
- else Result = aDef;
- return Result;
- };
- this.StrToInt = function (S) {
- var Result = 0;
- var R = 0;
- if (!$mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- Result = R;
- return Result;
- };
- this.StrToNativeInt = function (S) {
- var Result = 0;
- if (!$mod.TryStrToInt$1(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- return Result;
- };
- this.StrToInt64 = function (S) {
- var Result = 0;
- var N = 0;
- if (!$mod.TryStrToInt$1(S,{get: function () {
- return N;
- }, set: function (v) {
- N = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- Result = N;
- return Result;
- };
- this.StrToInt64Def = function (S, ADefault) {
- var Result = 0;
- if ($mod.TryStrToInt64(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = ADefault;
- return Result;
- };
- this.TryStrToInt64 = function (S, res) {
- var Result = false;
- var R = 0;
- Result = $mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }});
- if (Result) res.set(R);
- return Result;
- };
- this.StrToQWord = function (S) {
- var Result = 0;
- var N = 0;
- if (!$mod.TryStrToInt$1(S,{get: function () {
- return N;
- }, set: function (v) {
- N = v;
- }}) || (N < 0)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- Result = N;
- return Result;
- };
- this.StrToQWordDef = function (S, ADefault) {
- var Result = 0;
- if (!$mod.TryStrToQWord(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = ADefault;
- return Result;
- };
- this.TryStrToQWord = function (S, res) {
- var Result = false;
- var R = 0;
- Result = $mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }}) && (R >= 0);
- if (Result) res.set(R);
- return Result;
- };
- this.StrToUInt64 = function (S) {
- var Result = 0;
- var N = 0;
- if (!$mod.TryStrToInt$1(S,{get: function () {
- return N;
- }, set: function (v) {
- N = v;
- }}) || (N < 0)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- Result = N;
- return Result;
- };
- this.StrToUInt64Def = function (S, ADefault) {
- var Result = 0;
- if (!$mod.TryStrToUInt64(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = ADefault;
- return Result;
- };
- this.TryStrToUInt64 = function (S, res) {
- var Result = false;
- var R = 0;
- Result = $mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }}) && (R >= 0);
- if (Result) res.set(R);
- return Result;
- };
- this.StrToDWord = function (S) {
- var Result = 0;
- if (!$mod.TryStrToDWord(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidInteger,[S]]);
- return Result;
- };
- this.StrToDWordDef = function (S, ADefault) {
- var Result = 0;
- if (!$mod.TryStrToDWord(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = ADefault;
- return Result;
- };
- this.TryStrToDWord = function (S, res) {
- var Result = false;
- var R = 0;
- Result = ($mod.TryStrToInt$1(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }}) && (R >= 0)) && (R <= 0xFFFFFFFF);
- if (Result) res.set(R);
- return Result;
- };
- var HexDigits = "0123456789ABCDEF";
- this.IntToHex = function (Value, Digits) {
- var Result = "";
- if (Digits === 0) Digits = 1;
- Result = "";
- while (Value > 0) {
- Result = HexDigits.charAt(((Value & 15) + 1) - 1) + Result;
- Value = Value >>> 4;
- };
- while (Result.length < Digits) Result = "0" + Result;
- return Result;
- };
- this.MaxCurrency = 450359962737.0495;
- this.MinCurrency = -450359962737.0496;
- this.TFloatFormat = {"0": "ffFixed", ffFixed: 0, "1": "ffGeneral", ffGeneral: 1, "2": "ffExponent", ffExponent: 2, "3": "ffNumber", ffNumber: 3, "4": "ffCurrency", ffCurrency: 4};
- var Rounds = "234567890";
- this.FloatToDecimal = function (Value, Precision, Decimals) {
- var Result = new $mod.TFloatRec();
- var Buffer = "";
- var InfNan = "";
- var error = 0;
- var N = 0;
- var L = 0;
- var Start = 0;
- var C = 0;
- var GotNonZeroBeforeDot = false;
- var BeforeDot = false;
- if (Value === 0) ;
- Result.Digits = rtl.arraySetLength(Result.Digits,"",19);
- Buffer=Value.toPrecision(21); // Double precision;
- N = 1;
- L = Buffer.length;
- while (Buffer.charAt(N - 1) === " ") N += 1;
- Result.Negative = Buffer.charAt(N - 1) === "-";
- if (Result.Negative) {
- N += 1}
- else if (Buffer.charAt(N - 1) === "+") N += 1;
- if (L >= (N + 2)) {
- InfNan = pas.System.Copy(Buffer,N,3);
- if (InfNan === "Inf") {
- Result.Digits[0] = "\x00";
- Result.Exponent = 32767;
- return Result;
- };
- if (InfNan === "Nan") {
- Result.Digits[0] = "\x00";
- Result.Exponent = -32768;
- return Result;
- };
- };
- Start = N;
- Result.Exponent = 0;
- BeforeDot = true;
- GotNonZeroBeforeDot = false;
- while ((L >= N) && (Buffer.charAt(N - 1) !== "E")) {
- if (Buffer.charAt(N - 1) === ".") {
- BeforeDot = false}
- else {
- if (BeforeDot) {
- Result.Exponent += 1;
- Result.Digits[N - Start] = Buffer.charAt(N - 1);
- if (Buffer.charAt(N - 1) !== "0") GotNonZeroBeforeDot = true;
- } else Result.Digits[(N - Start) - 1] = Buffer.charAt(N - 1);
- };
- N += 1;
- };
- N += 1;
- if (N <= L) {
- pas.System.val$5(pas.System.Copy(Buffer,N,(L - N) + 1),{get: function () {
- return C;
- }, set: function (v) {
- C = v;
- }},{get: function () {
- return error;
- }, set: function (v) {
- error = v;
- }});
- Result.Exponent += C;
- };
- if (BeforeDot) {
- N = (N - Start) - 1}
- else N = (N - Start) - 2;
- L = rtl.length(Result.Digits);
- if (N < L) Result.Digits[N] = "0";
- if ((Decimals + Result.Exponent) < Precision) {
- N = Decimals + Result.Exponent}
- else N = Precision;
- if (N >= L) N = L - 1;
- if (N === 0) {
- if (Result.Digits[0] >= "5") {
- Result.Digits[0] = "1";
- Result.Digits[1] = "\x00";
- Result.Exponent += 1;
- } else Result.Digits[0] = "\x00";
- } else if (N > 0) {
- if (Result.Digits[N] >= "5") {
- do {
- Result.Digits[N] = "\x00";
- N -= 1;
- Result.Digits[N] = Rounds.charAt($mod.StrToInt(Result.Digits[N]) - 1);
- } while (!((N === 0) || (Result.Digits[N] < ":")));
- if (Result.Digits[0] === ":") {
- Result.Digits[0] = "1";
- Result.Exponent += 1;
- };
- } else {
- Result.Digits[N] = "0";
- while ((N > -1) && (Result.Digits[N] === "0")) {
- Result.Digits[N] = "\x00";
- N -= 1;
- };
- };
- } else Result.Digits[0] = "\x00";
- if ((Result.Digits[0] === "\x00") && !GotNonZeroBeforeDot) {
- Result.Exponent = 0;
- Result.Negative = false;
- };
- return Result;
- };
- this.FloatToStr = function (Value) {
- var Result = "";
- Result = $mod.FloatToStrF(Value,$mod.TFloatFormat.ffGeneral,15,0);
- return Result;
- };
- this.FloatToStrF = function (Value, format, Precision, Digits) {
- var Result = "";
- var DS = "";
- DS = $mod.DecimalSeparator;
- var $tmp1 = format;
- if ($tmp1 === $mod.TFloatFormat.ffGeneral) {
- Result = $impl.FormatGeneralFloat(Value,Precision,DS)}
- else if ($tmp1 === $mod.TFloatFormat.ffExponent) {
- Result = $impl.FormatExponentFloat(Value,Precision,Digits,DS)}
- else if ($tmp1 === $mod.TFloatFormat.ffFixed) {
- Result = $impl.FormatFixedFloat(Value,Digits,DS)}
- else if ($tmp1 === $mod.TFloatFormat.ffNumber) {
- Result = $impl.FormatNumberFloat(Value,Digits,DS,$mod.ThousandSeparator)}
- else if ($tmp1 === $mod.TFloatFormat.ffCurrency) Result = $impl.FormatNumberCurrency(Value * 10000,Digits,DS,$mod.ThousandSeparator);
- if (((format !== $mod.TFloatFormat.ffCurrency) && (Result.length > 1)) && (Result.charAt(0) === "-")) $impl.RemoveLeadingNegativeSign({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},DS);
- return Result;
- };
- this.TryStrToFloat = function (S, res) {
- var Result = false;
- var J = undefined;
- var N = "";
- N = S;
- if ($mod.ThousandSeparator !== "") N = $mod.StringReplace(N,$mod.ThousandSeparator,"",rtl.createSet($mod.TStringReplaceFlag.rfReplaceAll));
- if ($mod.DecimalSeparator !== ".") N = $mod.StringReplace(N,$mod.DecimalSeparator,".",{});
- J = parseFloat(N);
- Result = !isNaN(J);
- if (Result) res.set(rtl.getNumber(J));
- return Result;
- };
- this.StrToFloatDef = function (S, aDef) {
- var Result = 0.0;
- if (!$mod.TryStrToFloat(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = aDef;
- return Result;
- };
- this.StrToFloat = function (S) {
- var Result = 0.0;
- if (!$mod.TryStrToFloat(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SErrInvalidFloat,[S]]);
- return Result;
- };
- var MaxPrecision = 18;
- this.FormatFloat = function (Fmt, aValue) {
- var Result = "";
- var E = 0.0;
- var FV = new $mod.TFloatRec();
- var Section = "";
- var SectionLength = 0;
- var ThousandSep = false;
- var IsScientific = false;
- var DecimalPos = 0;
- var FirstDigit = 0;
- var LastDigit = 0;
- var RequestedDigits = 0;
- var ExpSize = 0;
- var Available = 0;
- var Current = 0;
- var PadZeroes = 0;
- var DistToDecimal = 0;
- function InitVars() {
- E = aValue;
- Section = "";
- SectionLength = 0;
- ThousandSep = false;
- IsScientific = false;
- DecimalPos = 0;
- FirstDigit = 2147483647;
- LastDigit = 0;
- RequestedDigits = 0;
- ExpSize = 0;
- Available = -1;
- };
- function ToResult(AChar) {
- Result = Result + AChar;
- };
- function AddToResult(AStr) {
- Result = Result + AStr;
- };
- function WriteDigit(ADigit) {
- if (ADigit === "\x00") return;
- DistToDecimal -= 1;
- if (DistToDecimal === -1) {
- AddToResult($mod.DecimalSeparator);
- ToResult(ADigit);
- } else {
- ToResult(ADigit);
- if ((ThousandSep && ((DistToDecimal % 3) === 0)) && (DistToDecimal > 1)) AddToResult($mod.ThousandSeparator);
- };
- };
- function GetDigit() {
- var Result = "";
- Result = "\x00";
- if (Current <= Available) {
- Result = FV.Digits[Current];
- Current += 1;
- } else if (DistToDecimal <= LastDigit) {
- DistToDecimal -= 1}
- else Result = "0";
- return Result;
- };
- function CopyDigit() {
- if (PadZeroes === 0) {
- WriteDigit(GetDigit())}
- else if (PadZeroes < 0) {
- PadZeroes += 1;
- if (DistToDecimal <= FirstDigit) {
- WriteDigit("0")}
- else DistToDecimal -= 1;
- } else {
- while (PadZeroes > 0) {
- WriteDigit(GetDigit());
- PadZeroes -= 1;
- };
- WriteDigit(GetDigit());
- };
- };
- function GetSections(SP) {
- var Result = 0;
- var FL = 0;
- var i = 0;
- var C = "";
- var Q = "";
- var inQuote = false;
- Result = 1;
- SP.get()[1] = -1;
- SP.get()[2] = -1;
- SP.get()[3] = -1;
- inQuote = false;
- Q = "\x00";
- i = 1;
- FL = Fmt.length;
- while (i <= FL) {
- C = Fmt.charAt(i - 1);
- var $tmp1 = C;
- if ($tmp1 === ";") {
- if (!inQuote) {
- if (Result > 3) throw $mod.Exception.$create("Create$1",["Invalid float format"]);
- SP.get()[Result] = i + 1;
- Result += 1;
- };
- } else if (($tmp1 === '"') || ($tmp1 === "'")) {
- if (inQuote) {
- inQuote = C !== Q}
- else {
- inQuote = true;
- Q = C;
- };
- };
- i += 1;
- };
- if (SP.get()[Result] === -1) SP.get()[Result] = FL + 1;
- return Result;
- };
- function AnalyzeFormat() {
- var I = 0;
- var Len = 0;
- var Q = "";
- var C = "";
- var InQuote = false;
- Len = Section.length;
- I = 1;
- InQuote = false;
- Q = "\x00";
- while (I <= Len) {
- C = Section.charAt(I - 1);
- if (C.charCodeAt() in rtl.createSet(34,39)) {
- if (InQuote) {
- InQuote = C !== Q}
- else {
- InQuote = true;
- Q = C;
- };
- } else if (!InQuote) {
- var $tmp1 = C;
- if ($tmp1 === ".") {
- if (DecimalPos === 0) DecimalPos = RequestedDigits + 1}
- else if ($tmp1 === ",") {
- ThousandSep = $mod.ThousandSeparator !== "\x00"}
- else if (($tmp1 === "e") || ($tmp1 === "E")) {
- I += 1;
- if (I < Len) {
- C = Section.charAt(I - 1);
- IsScientific = C.charCodeAt() in rtl.createSet(45,43);
- if (IsScientific) while ((I < Len) && (Section.charAt((I + 1) - 1) === "0")) {
- ExpSize += 1;
- I += 1;
- };
- if (ExpSize > 4) ExpSize = 4;
- };
- } else if ($tmp1 === "#") {
- RequestedDigits += 1}
- else if ($tmp1 === "0") {
- if (RequestedDigits < FirstDigit) FirstDigit = RequestedDigits + 1;
- RequestedDigits += 1;
- LastDigit = RequestedDigits + 1;
- };
- };
- I += 1;
- };
- if (DecimalPos === 0) DecimalPos = RequestedDigits + 1;
- LastDigit = DecimalPos - LastDigit;
- if (LastDigit > 0) LastDigit = 0;
- FirstDigit = DecimalPos - FirstDigit;
- if (FirstDigit < 0) FirstDigit = 0;
- };
- function ValueOutSideScope() {
- var Result = false;
- Result = (((FV.Exponent >= 18) && !IsScientific) || (FV.Exponent === 0x7FF)) || (FV.Exponent === 0x800);
- return Result;
- };
- function CalcRunVars() {
- var D = 0;
- var P = 0;
- if (IsScientific) {
- P = RequestedDigits;
- D = 9999;
- } else {
- P = 18;
- D = (RequestedDigits - DecimalPos) + 1;
- };
- FV = new $mod.TFloatRec($mod.FloatToDecimal(aValue,P,D));
- DistToDecimal = DecimalPos - 1;
- if (IsScientific) {
- PadZeroes = 0}
- else {
- PadZeroes = FV.Exponent - (DecimalPos - 1);
- if (PadZeroes >= 0) DistToDecimal = FV.Exponent;
- };
- Available = -1;
- while ((Available < (rtl.length(FV.Digits) - 1)) && (FV.Digits[Available + 1] !== "\x00")) Available += 1;
- };
- function FormatExponent(ASign, aExponent) {
- var Result = "";
- Result = $mod.IntToStr(aExponent);
- Result = pas.System.StringOfChar("0",ExpSize - Result.length) + Result;
- if (aExponent < 0) {
- Result = "-" + Result}
- else if ((aExponent > 0) && (ASign === "+")) Result = ASign + Result;
- return Result;
- };
- var I = 0;
- var S = 0;
- var C = "";
- var Q = "";
- var PA = [];
- var InLiteral = false;
- PA = rtl.arraySetLength(PA,0,4);
- Result = "";
- InitVars();
- if (E > 0) {
- S = 1}
- else if (E < 0) {
- S = 2}
- else S = 3;
- PA[0] = 0;
- I = GetSections({get: function () {
- return PA;
- }, set: function (v) {
- PA = v;
- }});
- if ((I < S) || ((PA[S] - PA[S - 1]) === 0)) S = 1;
- SectionLength = (PA[S] - PA[S - 1]) - 1;
- Section = pas.System.Copy(Fmt,PA[S - 1] + 1,SectionLength);
- Section = rtl.strSetLength(Section,SectionLength);
- AnalyzeFormat();
- CalcRunVars();
- if ((SectionLength === 0) || ValueOutSideScope()) {
- Section=E.toPrecision(15);
- Result = Section;
- };
- I = 1;
- Current = 0;
- Q = " ";
- InLiteral = false;
- if (FV.Negative && (S === 1)) ToResult("-");
- while (I <= SectionLength) {
- C = Section.charAt(I - 1);
- if (C.charCodeAt() in rtl.createSet(34,39)) {
- if (InLiteral) {
- InLiteral = C !== Q}
- else {
- InLiteral = true;
- Q = C;
- };
- } else if (InLiteral) {
- ToResult(C)}
- else {
- var $tmp1 = C;
- if (($tmp1 === "0") || ($tmp1 === "#")) {
- CopyDigit()}
- else if (($tmp1 === ".") || ($tmp1 === ",")) {}
- else if (($tmp1 === "e") || ($tmp1 === "E")) {
- ToResult(C);
- I += 1;
- if (I <= Section.length) {
- C = Section.charAt(I - 1);
- if (C.charCodeAt() in rtl.createSet(43,45)) {
- AddToResult(FormatExponent(C,(FV.Exponent - DecimalPos) + 1));
- while ((I < SectionLength) && (Section.charAt((I + 1) - 1) === "0")) I += 1;
- };
- };
- } else {
- ToResult(C);
- };
- };
- I += 1;
- };
- return Result;
- };
- this.TrueBoolStrs = [];
- this.FalseBoolStrs = [];
- this.StrToBool = function (S) {
- var Result = false;
- if (!$mod.TryStrToBool(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidBoolean,[S]]);
- return Result;
- };
- this.BoolToStr = function (B, UseBoolStrs) {
- var Result = "";
- if (UseBoolStrs) {
- $impl.CheckBoolStrs();
- if (B) {
- Result = $mod.TrueBoolStrs[0]}
- else Result = $mod.FalseBoolStrs[0];
- } else if (B) {
- Result = "-1"}
- else Result = "0";
- return Result;
- };
- this.BoolToStr$1 = function (B, TrueS, FalseS) {
- var Result = "";
- if (B) {
- Result = TrueS}
- else Result = FalseS;
- return Result;
- };
- this.StrToBoolDef = function (S, Default) {
- var Result = false;
- if (!$mod.TryStrToBool(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = Default;
- return Result;
- };
- this.TryStrToBool = function (S, Value) {
- var Result = false;
- var Temp = "";
- var I = 0;
- var D = 0.0;
- var Code = 0;
- Temp = $mod.UpperCase(S);
- pas.System.val$7(Temp,{get: function () {
- return D;
- }, set: function (v) {
- D = v;
- }},{get: function () {
- return Code;
- }, set: function (v) {
- Code = v;
- }});
- Result = true;
- if (Code === 0) {
- Value.set(D !== 0.0)}
- else {
- $impl.CheckBoolStrs();
- for (var $l1 = 0, $end2 = rtl.length($mod.TrueBoolStrs) - 1; $l1 <= $end2; $l1++) {
- I = $l1;
- if (Temp === $mod.UpperCase($mod.TrueBoolStrs[I])) {
- Value.set(true);
- return Result;
- };
- };
- for (var $l3 = 0, $end4 = rtl.length($mod.FalseBoolStrs) - 1; $l3 <= $end4; $l3++) {
- I = $l3;
- if (Temp === $mod.UpperCase($mod.FalseBoolStrs[I])) {
- Value.set(false);
- return Result;
- };
- };
- Result = false;
- };
- return Result;
- };
- this.ConfigExtension = ".cfg";
- this.SysConfigDir = "";
- this.OnGetEnvironmentVariable = null;
- this.OnGetEnvironmentString = null;
- this.OnGetEnvironmentVariableCount = null;
- this.GetEnvironmentVariable = function (EnvVar) {
- var Result = "";
- if ($mod.OnGetEnvironmentVariable != null) {
- Result = $mod.OnGetEnvironmentVariable(EnvVar)}
- else Result = "";
- return Result;
- };
- this.GetEnvironmentVariableCount = function () {
- var Result = 0;
- if ($mod.OnGetEnvironmentVariableCount != null) {
- Result = $mod.OnGetEnvironmentVariableCount()}
- else Result = 0;
- return Result;
- };
- this.GetEnvironmentString = function (Index) {
- var Result = "";
- if ($mod.OnGetEnvironmentString != null) {
- Result = $mod.OnGetEnvironmentString(Index)}
- else Result = "";
- return Result;
- };
- this.ShowException = function (ExceptObject, ExceptAddr) {
- var S = "";
- S = "Application raised an exception " + ExceptObject.$classname;
- if ($mod.Exception.isPrototypeOf(ExceptObject)) S = (S + " : ") + ExceptObject.fMessage;
- window.alert(S);
- if (ExceptAddr === null) ;
- };
- this.Abort = function () {
- throw $mod.EAbort.$create("Create$1",[$impl.SAbortError]);
- };
- this.TEventType = {"0": "etCustom", etCustom: 0, "1": "etInfo", etInfo: 1, "2": "etWarning", etWarning: 2, "3": "etError", etError: 3, "4": "etDebug", etDebug: 4};
- this.TSystemTime = function (s) {
- if (s) {
- this.Year = s.Year;
- this.Month = s.Month;
- this.Day = s.Day;
- this.DayOfWeek = s.DayOfWeek;
- this.Hour = s.Hour;
- this.Minute = s.Minute;
- this.Second = s.Second;
- this.MilliSecond = s.MilliSecond;
- } else {
- this.Year = 0;
- this.Month = 0;
- this.Day = 0;
- this.DayOfWeek = 0;
- this.Hour = 0;
- this.Minute = 0;
- this.Second = 0;
- this.MilliSecond = 0;
- };
- this.$equal = function (b) {
- 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)))))));
- };
- };
- this.TTimeStamp = function (s) {
- if (s) {
- this.Time = s.Time;
- this.date = s.date;
- } else {
- this.Time = 0;
- this.date = 0;
- };
- this.$equal = function (b) {
- return (this.Time === b.Time) && (this.date === b.date);
- };
- };
- this.TimeSeparator = ":";
- this.DateSeparator = "-";
- this.ShortDateFormat = "yyyy-mm-dd";
- this.LongDateFormat = "ddd, yyyy-mm-dd";
- this.ShortTimeFormat = "hh:nn";
- this.LongTimeFormat = "hh:nn:ss";
- this.DecimalSeparator = ".";
- this.ThousandSeparator = "";
- this.TimeAMString = "AM";
- this.TimePMString = "PM";
- this.HoursPerDay = 24;
- this.MinsPerHour = 60;
- this.SecsPerMin = 60;
- this.MSecsPerSec = 1000;
- this.MinsPerDay = 24 * 60;
- this.SecsPerDay = 1440 * 60;
- this.MSecsPerDay = 86400 * 1000;
- this.MaxDateTime = 2958465.99999999;
- this.MinDateTime = -693593.99999999;
- this.JulianEpoch = -2415018.5;
- this.UnixEpoch = -2415018.5 + 2440587.5;
- this.DateDelta = 693594;
- this.UnixDateDelta = 25569;
- 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]];
- this.ShortMonthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
- this.LongMonthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"];
- this.ShortDayNames = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
- this.LongDayNames = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
- rtl.createClass($mod,"TFormatSettings",pas.System.TObject,function () {
- this.GetCurrencyDecimals = function () {
- var Result = 0;
- Result = $mod.CurrencyDecimals;
- return Result;
- };
- this.GetCurrencyFormat = function () {
- var Result = 0;
- Result = $mod.CurrencyFormat;
- return Result;
- };
- this.GetCurrencyString = function () {
- var Result = "";
- Result = $mod.CurrencyString;
- return Result;
- };
- this.GetDateSeparator = function () {
- var Result = "";
- Result = $mod.DateSeparator;
- return Result;
- };
- this.GetDecimalSeparator = function () {
- var Result = "";
- Result = $mod.DecimalSeparator;
- return Result;
- };
- this.GetLongDateFormat = function () {
- var Result = "";
- Result = $mod.LongDateFormat;
- return Result;
- };
- this.GetLongDayNames = function () {
- var Result = rtl.arraySetLength(null,"",7);
- Result = $mod.LongDayNames.slice(0);
- return Result;
- };
- this.GetLongMonthNames = function () {
- var Result = rtl.arraySetLength(null,"",12);
- Result = $mod.LongMonthNames.slice(0);
- return Result;
- };
- this.GetLongTimeFormat = function () {
- var Result = "";
- Result = $mod.LongTimeFormat;
- return Result;
- };
- this.GetNegCurrFormat = function () {
- var Result = 0;
- Result = $mod.NegCurrFormat;
- return Result;
- };
- this.GetShortDateFormat = function () {
- var Result = "";
- Result = $mod.ShortDateFormat;
- return Result;
- };
- this.GetShortDayNames = function () {
- var Result = rtl.arraySetLength(null,"",7);
- Result = $mod.ShortDayNames.slice(0);
- return Result;
- };
- this.GetShortMonthNames = function () {
- var Result = rtl.arraySetLength(null,"",12);
- Result = $mod.ShortMonthNames.slice(0);
- return Result;
- };
- this.GetShortTimeFormat = function () {
- var Result = "";
- Result = $mod.ShortTimeFormat;
- return Result;
- };
- this.GetThousandSeparator = function () {
- var Result = "";
- Result = $mod.ThousandSeparator;
- return Result;
- };
- this.GetTimeAMString = function () {
- var Result = "";
- Result = $mod.TimeAMString;
- return Result;
- };
- this.GetTimePMString = function () {
- var Result = "";
- Result = $mod.TimePMString;
- return Result;
- };
- this.GetTimeSeparator = function () {
- var Result = "";
- Result = $mod.TimeSeparator;
- return Result;
- };
- this.SetCurrencyFormat = function (AValue) {
- $mod.CurrencyFormat = AValue;
- };
- this.SetCurrencyString = function (AValue) {
- $mod.CurrencyString = AValue;
- };
- this.SetDateSeparator = function (Value) {
- $mod.DateSeparator = Value;
- };
- this.SetDecimalSeparator = function (Value) {
- $mod.DecimalSeparator = Value;
- };
- this.SetLongDateFormat = function (Value) {
- $mod.LongDateFormat = Value;
- };
- this.SetLongDayNames = function (AValue) {
- $mod.LongDayNames = AValue.slice(0);
- };
- this.SetLongMonthNames = function (AValue) {
- $mod.LongMonthNames = AValue.slice(0);
- };
- this.SetLongTimeFormat = function (Value) {
- $mod.LongTimeFormat = Value;
- };
- this.SetNegCurrFormat = function (AValue) {
- $mod.NegCurrFormat = AValue;
- };
- this.SetShortDateFormat = function (Value) {
- $mod.ShortDateFormat = Value;
- };
- this.SetShortDayNames = function (AValue) {
- $mod.ShortDayNames = AValue.slice(0);
- };
- this.SetShortMonthNames = function (AValue) {
- $mod.ShortMonthNames = AValue.slice(0);
- };
- this.SetShortTimeFormat = function (Value) {
- $mod.ShortTimeFormat = Value;
- };
- this.SetCurrencyDecimals = function (AValue) {
- $mod.CurrencyDecimals = AValue;
- };
- this.SetThousandSeparator = function (Value) {
- $mod.ThousandSeparator = Value;
- };
- this.SetTimeAMString = function (Value) {
- $mod.TimeAMString = Value;
- };
- this.SetTimePMString = function (Value) {
- $mod.TimePMString = Value;
- };
- this.SetTimeSeparator = function (Value) {
- $mod.TimeSeparator = Value;
- };
- });
- this.FormatSettings = null;
- this.TwoDigitYearCenturyWindow = 50;
- this.DateTimeToJSDate = function (aDateTime) {
- var Result = null;
- var Y = 0;
- var M = 0;
- var D = 0;
- var h = 0;
- var n = 0;
- var s = 0;
- var z = 0;
- $mod.DecodeDate(pas.System.Trunc(aDateTime),{get: function () {
- return Y;
- }, set: function (v) {
- Y = v;
- }},{get: function () {
- return M;
- }, set: function (v) {
- M = v;
- }},{get: function () {
- return D;
- }, set: function (v) {
- D = v;
- }});
- $mod.DecodeTime(pas.System.Frac(aDateTime),{get: function () {
- return h;
- }, set: function (v) {
- h = v;
- }},{get: function () {
- return n;
- }, set: function (v) {
- n = v;
- }},{get: function () {
- return s;
- }, set: function (v) {
- s = v;
- }},{get: function () {
- return z;
- }, set: function (v) {
- z = v;
- }});
- Result = new Date(Y,M,D,h,n,s,z);
- return Result;
- };
- this.JSDateToDateTime = function (aDate) {
- var Result = 0.0;
- Result = $mod.EncodeDate(aDate.getFullYear(),aDate.getMonth() + 1,aDate.getDate()) + $mod.EncodeTime(aDate.getHours(),aDate.getMinutes(),aDate.getSeconds(),aDate.getMilliseconds());
- return Result;
- };
- this.DateTimeToTimeStamp = function (DateTime) {
- var Result = new $mod.TTimeStamp();
- var D = 0.0;
- D = DateTime * 86400000;
- if (D < 0) {
- D = D - 0.5}
- else D = D + 0.5;
- Result.Time = pas.System.Trunc(Math.abs(pas.System.Trunc(D)) % 86400000);
- Result.date = 693594 + Math.floor(pas.System.Trunc(D) / 86400000);
- return Result;
- };
- this.TimeStampToDateTime = function (TimeStamp) {
- var Result = 0.0;
- Result = $mod.ComposeDateTime(TimeStamp.date - 693594,TimeStamp.Time / 86400000);
- return Result;
- };
- this.MSecsToTimeStamp = function (MSecs) {
- var Result = new $mod.TTimeStamp();
- Result.date = pas.System.Trunc(MSecs / 86400000);
- MSecs = MSecs - (Result.date * 86400000);
- Result.Time = Math.round(MSecs);
- return Result;
- };
- this.TimeStampToMSecs = function (TimeStamp) {
- var Result = 0;
- Result = TimeStamp.Time + (TimeStamp.date * 86400000);
- return Result;
- };
- this.TryEncodeDate = function (Year, Month, Day, date) {
- var Result = false;
- var c = 0;
- var ya = 0;
- Result = (((((Year > 0) && (Year < 10000)) && (Month >= 1)) && (Month <= 12)) && (Day > 0)) && (Day <= $mod.MonthDays[+$mod.IsLeapYear(Year)][Month - 1]);
- if (Result) {
- if (Month > 2) {
- Month -= 3}
- else {
- Month += 9;
- Year -= 1;
- };
- c = Math.floor(Year / 100);
- ya = Year - (100 * c);
- date.set(((((146097 * c) >>> 2) + ((1461 * ya) >>> 2)) + Math.floor(((153 * Month) + 2) / 5)) + Day);
- date.set(date.get() - 693900);
- };
- return Result;
- };
- this.TryEncodeTime = function (Hour, Min, Sec, MSec, Time) {
- var Result = false;
- Result = (((Hour < 24) && (Min < 60)) && (Sec < 60)) && (MSec < 1000);
- if (Result) Time.set(((((Hour * 3600000) + (Min * 60000)) + (Sec * 1000)) + MSec) / 86400000);
- return Result;
- };
- this.EncodeDate = function (Year, Month, Day) {
- var Result = 0.0;
- if (!$mod.TryEncodeDate(Year,Month,Day,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",["%s-%s-%s is not a valid date specification",[$mod.IntToStr(Year),$mod.IntToStr(Month),$mod.IntToStr(Day)]]);
- return Result;
- };
- this.EncodeTime = function (Hour, Minute, Second, MilliSecond) {
- var Result = 0.0;
- if (!$mod.TryEncodeTime(Hour,Minute,Second,MilliSecond,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) 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)]]);
- return Result;
- };
- this.ComposeDateTime = function (date, Time) {
- var Result = 0.0;
- if (date < 0) {
- Result = pas.System.Trunc(date) - Math.abs(pas.System.Frac(Time))}
- else Result = pas.System.Trunc(date) + Math.abs(pas.System.Frac(Time));
- return Result;
- };
- this.DecodeDate = function (date, Year, Month, Day) {
- var ly = 0;
- var ld = 0;
- var lm = 0;
- var j = 0;
- if (date <= -693594) {
- Year.set(0);
- Month.set(0);
- Day.set(0);
- } else {
- if (date > 0) {
- date = date + (1 / (86400000 * 2))}
- else date = date - (1 / (86400000 * 2));
- if (date > $mod.MaxDateTime) date = $mod.MaxDateTime;
- j = ((pas.System.Trunc(date) + 693900) << 2) - 1;
- ly = Math.floor(j / 146097);
- j = j - (146097 * ly);
- ld = j >>> 2;
- j = Math.floor(((ld << 2) + 3) / 1461);
- ld = (((ld << 2) + 7) - (1461 * j)) >>> 2;
- lm = Math.floor(((5 * ld) - 3) / 153);
- ld = Math.floor((((5 * ld) + 2) - (153 * lm)) / 5);
- ly = (100 * ly) + j;
- if (lm < 10) {
- lm += 3}
- else {
- lm -= 9;
- ly += 1;
- };
- Year.set(ly);
- Month.set(lm);
- Day.set(ld);
- };
- };
- this.DecodeDateFully = function (DateTime, Year, Month, Day, DOW) {
- var Result = false;
- $mod.DecodeDate(DateTime,Year,Month,Day);
- DOW.set($mod.DayOfWeek(DateTime));
- Result = $mod.IsLeapYear(Year.get());
- return Result;
- };
- this.DecodeTime = function (Time, Hour, Minute, Second, MilliSecond) {
- var l = 0;
- l = $mod.DateTimeToTimeStamp(Time).Time;
- Hour.set(Math.floor(l / 3600000));
- l = l % 3600000;
- Minute.set(Math.floor(l / 60000));
- l = l % 60000;
- Second.set(Math.floor(l / 1000));
- l = l % 1000;
- MilliSecond.set(l);
- };
- this.DateTimeToSystemTime = function (DateTime, SystemTime) {
- $mod.DecodeDateFully(DateTime,{p: SystemTime.get(), get: function () {
- return this.p.Year;
- }, set: function (v) {
- this.p.Year = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.Month;
- }, set: function (v) {
- this.p.Month = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.Day;
- }, set: function (v) {
- this.p.Day = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.DayOfWeek;
- }, set: function (v) {
- this.p.DayOfWeek = v;
- }});
- $mod.DecodeTime(DateTime,{p: SystemTime.get(), get: function () {
- return this.p.Hour;
- }, set: function (v) {
- this.p.Hour = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.Minute;
- }, set: function (v) {
- this.p.Minute = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.Second;
- }, set: function (v) {
- this.p.Second = v;
- }},{p: SystemTime.get(), get: function () {
- return this.p.MilliSecond;
- }, set: function (v) {
- this.p.MilliSecond = v;
- }});
- SystemTime.get().DayOfWeek -= 1;
- };
- this.SystemTimeToDateTime = function (SystemTime) {
- var Result = 0.0;
- Result = $mod.ComposeDateTime($impl.DoEncodeDate(SystemTime.Year,SystemTime.Month,SystemTime.Day),$impl.DoEncodeTime(SystemTime.Hour,SystemTime.Minute,SystemTime.Second,SystemTime.MilliSecond));
- return Result;
- };
- this.DayOfWeek = function (DateTime) {
- var Result = 0;
- Result = 1 + ((pas.System.Trunc(DateTime) - 1) % 7);
- if (Result <= 0) Result += 7;
- return Result;
- };
- this.date = function () {
- var Result = 0.0;
- Result = pas.System.Trunc($mod.Now());
- return Result;
- };
- this.Time = function () {
- var Result = 0.0;
- Result = $mod.Now() - $mod.date();
- return Result;
- };
- this.Now = function () {
- var Result = 0.0;
- Result = $mod.JSDateToDateTime(new Date());
- return Result;
- };
- this.IncMonth = function (DateTime, NumberOfMonths) {
- var Result = 0.0;
- var Year = 0;
- var Month = 0;
- var Day = 0;
- $mod.DecodeDate(DateTime,{get: function () {
- return Year;
- }, set: function (v) {
- Year = v;
- }},{get: function () {
- return Month;
- }, set: function (v) {
- Month = v;
- }},{get: function () {
- return Day;
- }, set: function (v) {
- Day = v;
- }});
- $mod.IncAMonth({get: function () {
- return Year;
- }, set: function (v) {
- Year = v;
- }},{get: function () {
- return Month;
- }, set: function (v) {
- Month = v;
- }},{get: function () {
- return Day;
- }, set: function (v) {
- Day = v;
- }},NumberOfMonths);
- Result = $mod.ComposeDateTime($impl.DoEncodeDate(Year,Month,Day),DateTime);
- return Result;
- };
- this.IncAMonth = function (Year, Month, Day, NumberOfMonths) {
- var TempMonth = 0;
- var S = 0;
- if (NumberOfMonths >= 0) {
- S = 1}
- else S = -1;
- Year.set(Year.get() + Math.floor(NumberOfMonths / 12));
- TempMonth = (Month.get() + (NumberOfMonths % 12)) - 1;
- if ((TempMonth > 11) || (TempMonth < 0)) {
- TempMonth -= S * 12;
- Year.set(Year.get() + S);
- };
- Month.set(TempMonth + 1);
- if (Day.get() > $mod.MonthDays[+$mod.IsLeapYear(Year.get())][Month.get() - 1]) Day.set($mod.MonthDays[+$mod.IsLeapYear(Year.get())][Month.get() - 1]);
- };
- this.IsLeapYear = function (Year) {
- var Result = false;
- Result = ((Year % 4) === 0) && (((Year % 100) !== 0) || ((Year % 400) === 0));
- return Result;
- };
- this.DateToStr = function (date) {
- var Result = "";
- Result = $mod.FormatDateTime("ddddd",date);
- return Result;
- };
- this.TimeToStr = function (Time) {
- var Result = "";
- Result = $mod.FormatDateTime("tt",Time);
- return Result;
- };
- this.DateTimeToStr = function (DateTime, ForceTimeIfZero) {
- var Result = "";
- Result = $mod.FormatDateTime($impl.DateTimeToStrFormat[+ForceTimeIfZero],DateTime);
- return Result;
- };
- this.StrToDate = function (S) {
- var Result = 0.0;
- Result = $mod.StrToDate$2(S,$mod.ShortDateFormat,"\x00");
- return Result;
- };
- this.StrToDate$1 = function (S, separator) {
- var Result = 0.0;
- Result = $mod.StrToDate$2(S,$mod.ShortDateFormat,separator);
- return Result;
- };
- this.StrToDate$2 = function (S, useformat, separator) {
- var Result = 0.0;
- var MSg = "";
- Result = $impl.IntStrToDate({get: function () {
- return MSg;
- }, set: function (v) {
- MSg = v;
- }},S,useformat,separator);
- if (MSg !== "") throw $mod.EConvertError.$create("Create$1",[MSg]);
- return Result;
- };
- this.StrToTime = function (S) {
- var Result = 0.0;
- Result = $mod.StrToTime$1(S,$mod.TimeSeparator);
- return Result;
- };
- this.StrToTime$1 = function (S, separator) {
- var Result = 0.0;
- var Msg = "";
- Result = $impl.IntStrToTime({get: function () {
- return Msg;
- }, set: function (v) {
- Msg = v;
- }},S,S.length,separator);
- if (Msg !== "") throw $mod.EConvertError.$create("Create$1",[Msg]);
- return Result;
- };
- this.StrToDateTime = function (S) {
- var Result = 0.0;
- var TimeStr = "";
- var DateStr = "";
- var PartsFound = 0;
- PartsFound = $impl.SplitDateTimeStr(S,{get: function () {
- return DateStr;
- }, set: function (v) {
- DateStr = v;
- }},{get: function () {
- return TimeStr;
- }, set: function (v) {
- TimeStr = v;
- }});
- var $tmp1 = PartsFound;
- if ($tmp1 === 0) {
- Result = $mod.StrToDate("")}
- else if ($tmp1 === 1) {
- if (DateStr.length > 0) {
- Result = $mod.StrToDate$2(DateStr,$mod.ShortDateFormat,$mod.DateSeparator)}
- else Result = $mod.StrToTime(TimeStr)}
- else if ($tmp1 === 2) Result = $mod.ComposeDateTime($mod.StrToDate$2(DateStr,$mod.ShortDateFormat,$mod.DateSeparator),$mod.StrToTime(TimeStr));
- return Result;
- };
- this.FormatDateTime = function (FormatStr, DateTime) {
- var Result = "";
- function StoreStr(APos, Len) {
- Result = Result + pas.System.Copy(FormatStr,APos,Len);
- };
- function StoreString(AStr) {
- Result = Result + AStr;
- };
- function StoreInt(Value, Digits) {
- var S = "";
- S = $mod.IntToStr(Value);
- while (S.length < Digits) S = "0" + S;
- StoreString(S);
- };
- var Year = 0;
- var Month = 0;
- var Day = 0;
- var DayOfWeek = 0;
- var Hour = 0;
- var Minute = 0;
- var Second = 0;
- var MilliSecond = 0;
- function StoreFormat(FormatStr, Nesting, TimeFlag) {
- var Token = "";
- var lastformattoken = "";
- var prevlasttoken = "";
- var Count = 0;
- var Clock12 = false;
- var tmp = 0;
- var isInterval = false;
- var P = 0;
- var FormatCurrent = 0;
- var FormatEnd = 0;
- if (Nesting > 1) return;
- FormatCurrent = 1;
- FormatEnd = FormatStr.length;
- Clock12 = false;
- isInterval = false;
- P = 1;
- while (P <= FormatEnd) {
- Token = FormatStr.charAt(P - 1);
- var $tmp1 = Token;
- if (($tmp1 === "'") || ($tmp1 === '"')) {
- P += 1;
- while ((P < FormatEnd) && (FormatStr.charAt(P - 1) !== Token)) P += 1;
- } else if (($tmp1 === "A") || ($tmp1 === "a")) {
- 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)) {
- Clock12 = true;
- break;
- };
- };
- P += 1;
- };
- Token = "ÿ";
- lastformattoken = " ";
- prevlasttoken = "H";
- while (FormatCurrent <= FormatEnd) {
- Token = $mod.UpperCase(FormatStr.charAt(FormatCurrent - 1)).charAt(0);
- Count = 1;
- P = FormatCurrent + 1;
- var $tmp2 = Token;
- if (($tmp2 === "'") || ($tmp2 === '"')) {
- while ((P < FormatEnd) && (FormatStr.charAt(P - 1) !== Token)) P += 1;
- P += 1;
- Count = P - FormatCurrent;
- StoreStr(FormatCurrent + 1,Count - 2);
- } else if ($tmp2 === "A") {
- if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,4),"AMPM") === 0) {
- Count = 4;
- if (Hour < 12) {
- StoreString($mod.TimeAMString)}
- else StoreString($mod.TimePMString);
- } else if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,5),"AM\/PM") === 0) {
- Count = 5;
- if (Hour < 12) {
- StoreStr(FormatCurrent,2)}
- else StoreStr(FormatCurrent + 3,2);
- } else if ($mod.CompareText(pas.System.Copy(FormatStr,FormatCurrent,3),"A\/P") === 0) {
- Count = 3;
- if (Hour < 12) {
- StoreStr(FormatCurrent,1)}
- else StoreStr(FormatCurrent + 2,1);
- } else throw $mod.EConvertError.$create("Create$1",["Illegal character in format string"]);
- } else if ($tmp2 === "\/") {
- StoreString($mod.DateSeparator);
- } else if ($tmp2 === ":") {
- StoreString($mod.TimeSeparator)}
- else if ((((((((((($tmp2 === " ") || ($tmp2 === "C")) || ($tmp2 === "D")) || ($tmp2 === "H")) || ($tmp2 === "M")) || ($tmp2 === "N")) || ($tmp2 === "S")) || ($tmp2 === "T")) || ($tmp2 === "Y")) || ($tmp2 === "Z")) || ($tmp2 === "F")) {
- while ((P <= FormatEnd) && ($mod.UpperCase(FormatStr.charAt(P - 1)) === Token)) P += 1;
- Count = P - FormatCurrent;
- var $tmp3 = Token;
- if ($tmp3 === " ") {
- StoreStr(FormatCurrent,Count)}
- else if ($tmp3 === "Y") {
- if (Count > 2) {
- StoreInt(Year,4)}
- else StoreInt(Year % 100,2);
- } else if ($tmp3 === "M") {
- if (isInterval && ((prevlasttoken === "H") || TimeFlag)) {
- StoreInt(Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60),0)}
- else if ((lastformattoken === "H") || TimeFlag) {
- if (Count === 1) {
- StoreInt(Minute,0)}
- else StoreInt(Minute,2);
- } else {
- var $tmp4 = Count;
- if ($tmp4 === 1) {
- StoreInt(Month,0)}
- else if ($tmp4 === 2) {
- StoreInt(Month,2)}
- else if ($tmp4 === 3) {
- StoreString($mod.ShortMonthNames[Month - 1])}
- else {
- StoreString($mod.LongMonthNames[Month - 1]);
- };
- };
- } else if ($tmp3 === "D") {
- var $tmp5 = Count;
- if ($tmp5 === 1) {
- StoreInt(Day,0)}
- else if ($tmp5 === 2) {
- StoreInt(Day,2)}
- else if ($tmp5 === 3) {
- StoreString($mod.ShortDayNames[DayOfWeek])}
- else if ($tmp5 === 4) {
- StoreString($mod.LongDayNames[DayOfWeek])}
- else if ($tmp5 === 5) {
- StoreFormat($mod.ShortDateFormat,Nesting + 1,false)}
- else {
- StoreFormat($mod.LongDateFormat,Nesting + 1,false);
- };
- } else if ($tmp3 === "H") {
- if (isInterval) {
- StoreInt(Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24),0)}
- else if (Clock12) {
- tmp = Hour % 12;
- if (tmp === 0) tmp = 12;
- if (Count === 1) {
- StoreInt(tmp,0)}
- else StoreInt(tmp,2);
- } else {
- if (Count === 1) {
- StoreInt(Hour,0)}
- else StoreInt(Hour,2);
- }}
- else if ($tmp3 === "N") {
- if (isInterval) {
- StoreInt(Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60),0)}
- else if (Count === 1) {
- StoreInt(Minute,0)}
- else StoreInt(Minute,2)}
- else if ($tmp3 === "S") {
- if (isInterval) {
- StoreInt(Second + ((Minute + ((Hour + (pas.System.Trunc(Math.abs(DateTime)) * 24)) * 60)) * 60),0)}
- else if (Count === 1) {
- StoreInt(Second,0)}
- else StoreInt(Second,2)}
- else if ($tmp3 === "Z") {
- if (Count === 1) {
- StoreInt(MilliSecond,0)}
- else StoreInt(MilliSecond,3)}
- else if ($tmp3 === "T") {
- if (Count === 1) {
- StoreFormat($mod.ShortTimeFormat,Nesting + 1,true)}
- else StoreFormat($mod.LongTimeFormat,Nesting + 1,true)}
- else if ($tmp3 === "C") {
- StoreFormat($mod.ShortDateFormat,Nesting + 1,false);
- if (((Hour !== 0) || (Minute !== 0)) || (Second !== 0)) {
- StoreString(" ");
- StoreFormat($mod.LongTimeFormat,Nesting + 1,true);
- };
- } else if ($tmp3 === "F") {
- StoreFormat($mod.ShortDateFormat,Nesting + 1,false);
- StoreString(" ");
- StoreFormat($mod.LongTimeFormat,Nesting + 1,true);
- };
- prevlasttoken = lastformattoken;
- lastformattoken = Token;
- } else {
- StoreString(Token);
- };
- FormatCurrent += Count;
- };
- };
- $mod.DecodeDateFully(DateTime,{get: function () {
- return Year;
- }, set: function (v) {
- Year = v;
- }},{get: function () {
- return Month;
- }, set: function (v) {
- Month = v;
- }},{get: function () {
- return Day;
- }, set: function (v) {
- Day = v;
- }},{get: function () {
- return DayOfWeek;
- }, set: function (v) {
- DayOfWeek = v;
- }});
- $mod.DecodeTime(DateTime,{get: function () {
- return Hour;
- }, set: function (v) {
- Hour = v;
- }},{get: function () {
- return Minute;
- }, set: function (v) {
- Minute = v;
- }},{get: function () {
- return Second;
- }, set: function (v) {
- Second = v;
- }},{get: function () {
- return MilliSecond;
- }, set: function (v) {
- MilliSecond = v;
- }});
- if (FormatStr !== "") {
- StoreFormat(FormatStr,0,false)}
- else StoreFormat("C",0,false);
- return Result;
- };
- this.TryStrToDate = function (S, Value) {
- var Result = false;
- Result = $mod.TryStrToDate$2(S,Value,$mod.ShortDateFormat,"\x00");
- return Result;
- };
- this.TryStrToDate$1 = function (S, Value, separator) {
- var Result = false;
- Result = $mod.TryStrToDate$2(S,Value,$mod.ShortDateFormat,separator);
- return Result;
- };
- this.TryStrToDate$2 = function (S, Value, useformat, separator) {
- var Result = false;
- var Msg = "";
- Result = S.length !== 0;
- if (Result) {
- Value.set($impl.IntStrToDate({get: function () {
- return Msg;
- }, set: function (v) {
- Msg = v;
- }},S,useformat,separator));
- Result = Msg === "";
- };
- return Result;
- };
- this.TryStrToTime = function (S, Value) {
- var Result = false;
- Result = $mod.TryStrToTime$1(S,Value,"\x00");
- return Result;
- };
- this.TryStrToTime$1 = function (S, Value, separator) {
- var Result = false;
- var Msg = "";
- Result = S.length !== 0;
- if (Result) {
- Value.set($impl.IntStrToTime({get: function () {
- return Msg;
- }, set: function (v) {
- Msg = v;
- }},S,S.length,separator));
- Result = Msg === "";
- };
- return Result;
- };
- this.TryStrToDateTime = function (S, Value) {
- var Result = false;
- var I = 0;
- var dtdate = 0.0;
- var dttime = 0.0;
- Result = false;
- I = pas.System.Pos($mod.TimeSeparator,S);
- if (I > 0) {
- while ((I > 0) && (S.charAt(I - 1) !== " ")) I -= 1;
- if (I > 0) {
- if (!$mod.TryStrToDate(pas.System.Copy(S,1,I - 1),{get: function () {
- return dtdate;
- }, set: function (v) {
- dtdate = v;
- }})) return Result;
- if (!$mod.TryStrToTime(pas.System.Copy(S,I + 1,S.length - I),{get: function () {
- return dttime;
- }, set: function (v) {
- dttime = v;
- }})) return Result;
- Value.set($mod.ComposeDateTime(dtdate,dttime));
- Result = true;
- } else Result = $mod.TryStrToTime(S,Value);
- } else Result = $mod.TryStrToDate(S,Value);
- return Result;
- };
- this.StrToDateDef = function (S, Defvalue) {
- var Result = 0.0;
- Result = $mod.StrToDateDef$1(S,Defvalue,"\x00");
- return Result;
- };
- this.StrToDateDef$1 = function (S, Defvalue, separator) {
- var Result = 0.0;
- if (!$mod.TryStrToDate$1(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},separator)) Result = Defvalue;
- return Result;
- };
- this.StrToTimeDef = function (S, Defvalue) {
- var Result = 0.0;
- Result = $mod.StrToTimeDef$1(S,Defvalue,"\x00");
- return Result;
- };
- this.StrToTimeDef$1 = function (S, Defvalue, separator) {
- var Result = 0.0;
- if (!$mod.TryStrToTime$1(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},separator)) Result = Defvalue;
- return Result;
- };
- this.StrToDateTimeDef = function (S, Defvalue) {
- var Result = 0.0;
- if (!$mod.TryStrToDateTime(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = Defvalue;
- return Result;
- };
- this.CurrentYear = function () {
- var Result = 0;
- Result = (new Date()).getFullYear();
- return Result;
- };
- this.ReplaceTime = function (dati, NewTime) {
- dati.set($mod.ComposeDateTime(dati.get(),NewTime));
- };
- this.ReplaceDate = function (DateTime, NewDate) {
- var tmp = 0.0;
- tmp = NewDate;
- $mod.ReplaceTime({get: function () {
- return tmp;
- }, set: function (v) {
- tmp = v;
- }},DateTime.get());
- DateTime.set(tmp);
- };
- this.FloatToDateTime = function (Value) {
- var Result = 0.0;
- if ((Value < $mod.MinDateTime) || (Value > $mod.MaxDateTime)) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidDateTime,[$mod.FloatToStr(Value)]]);
- Result = Value;
- return Result;
- };
- this.CurrencyFormat = 0;
- this.NegCurrFormat = 0;
- this.CurrencyDecimals = 2;
- this.CurrencyString = "$";
- this.FloattoCurr = function (Value) {
- var Result = 0;
- if (!$mod.TryFloatToCurr(Value,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidCurrency,[$mod.FloatToStr(Value)]]);
- return Result;
- };
- this.TryFloatToCurr = function (Value, AResult) {
- var Result = false;
- Result = ((Value * 10000) >= $mod.MinCurrency) && ((Value * 10000) <= $mod.MaxCurrency);
- if (Result) AResult.set(Math.floor(Value * 10000));
- return Result;
- };
- this.CurrToStr = function (Value) {
- var Result = "";
- Result = $mod.FloatToStrF(Value / 10000,$mod.TFloatFormat.ffGeneral,-1,0);
- return Result;
- };
- this.StrToCurr = function (S) {
- var Result = 0;
- if (!$mod.TryStrToCurr(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidCurrency,[S]]);
- return Result;
- };
- this.TryStrToCurr = function (S, Value) {
- var Result = false;
- var D = 0.0;
- Result = $mod.TryStrToFloat(S,{get: function () {
- return D;
- }, set: function (v) {
- D = v;
- }});
- if (Result) Value.set(Math.floor(D * 10000));
- return Result;
- };
- this.StrToCurrDef = function (S, Default) {
- var Result = 0;
- var R = 0;
- if ($mod.TryStrToCurr(S,{get: function () {
- return R;
- }, set: function (v) {
- R = v;
- }})) {
- Result = R}
- else Result = Default;
- return Result;
- };
- this.GUID_NULL = new pas.System.TGuid({D1: 0x00000000, D2: 0x0000, D3: 0x0000, D4: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]});
- this.Supports = function (Instance, AClass, Obj) {
- var Result = false;
- Result = ((Instance !== null) && (Instance.QueryInterface(pas.System.IObjectInstance,Obj) === 0)) && Obj.get().$class.InheritsFrom(AClass);
- return Result;
- };
- this.Supports$1 = function (Instance, IID, Intf) {
- var Result = false;
- Result = (Instance !== null) && (Instance.QueryInterface(IID,Intf) === 0);
- return Result;
- };
- this.Supports$2 = function (Instance, IID, Intf) {
- var Result = false;
- Result = (Instance !== null) && Instance.GetInterface(IID,Intf);
- return Result;
- };
- this.Supports$3 = function (Instance, IID, Intf) {
- var Result = false;
- Result = (Instance !== null) && Instance.GetInterfaceByStr(IID,Intf);
- return Result;
- };
- this.Supports$4 = function (Instance, AClass) {
- var Result = false;
- var Temp = null;
- Result = $mod.Supports(Instance,AClass,{get: function () {
- return Temp;
- }, set: function (v) {
- Temp = v;
- }});
- return Result;
- };
- this.Supports$5 = function (Instance, IID) {
- var Result = false;
- var Temp = null;
- try {
- Result = $mod.Supports$1(Instance,IID,{get: function () {
- return Temp;
- }, set: function (v) {
- Temp = v;
- }});
- } finally {
- rtl._Release(Temp);
- };
- return Result;
- };
- this.Supports$6 = function (Instance, IID) {
- var Result = false;
- var Temp = null;
- Result = $mod.Supports$2(Instance,IID,{get: function () {
- return Temp;
- }, set: function (v) {
- Temp = v;
- }});
- if (Temp && Temp.$kind==='com') Temp._Release();
- return Result;
- };
- this.Supports$7 = function (Instance, IID) {
- var Result = false;
- var Temp = null;
- Result = $mod.Supports$3(Instance,IID,{get: function () {
- return Temp;
- }, set: function (v) {
- Temp = v;
- }});
- if (Temp && Temp.$kind==='com') Temp._Release();
- return Result;
- };
- this.Supports$8 = function (AClass, IID) {
- var Result = false;
- var maps = undefined;
- if (AClass === null) return false;
- maps = AClass["$intfmaps"];
- if (!maps) return false;
- if (rtl.getObject(maps)[$mod.GUIDToString(IID)]) return true;
- Result = false;
- return Result;
- };
- this.Supports$9 = function (AClass, IID) {
- var Result = false;
- var maps = undefined;
- if (AClass === null) return false;
- maps = AClass["$intfmaps"];
- if (!maps) return false;
- if (rtl.getObject(maps)[$mod.UpperCase(IID)]) return true;
- Result = false;
- return Result;
- };
- this.TryStringToGUID = function (s, Guid) {
- var Result = false;
- var re = null;
- if (s.length !== 38) return false;
- 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}\\}$");
- Result = re.test(s);
- if (!Result) {
- Guid.get().D1 = 0;
- return Result;
- };
- rtl.strToGUIDR(s,Guid.get());
- Result = true;
- return Result;
- };
- this.StringToGUID = function (S) {
- var Result = new pas.System.TGuid();
- if (!$mod.TryStringToGUID(S,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidGUID,[S]]);
- return Result;
- };
- this.GUIDToString = function (guid) {
- var Result = "";
- Result = rtl.guidrToStr(guid);
- return Result;
- };
- this.IsEqualGUID = function (guid1, guid2) {
- var Result = false;
- var i = 0;
- if (((guid1.D1 !== guid2.D1) || (guid1.D2 !== guid2.D2)) || (guid1.D3 !== guid2.D3)) return false;
- for (i = 0; i <= 7; i++) if (guid1.D4[i] !== guid2.D4[i]) return false;
- Result = true;
- return Result;
- };
- this.GuidCase = function (guid, List) {
- var Result = 0;
- for (var $l1 = rtl.length(List) - 1; $l1 >= 0; $l1--) {
- Result = $l1;
- if ($mod.IsEqualGUID(guid,List[Result])) return Result;
- };
- Result = -1;
- return Result;
- };
- $mod.$init = function () {
- $mod.FormatSettings = $mod.TFormatSettings.$create("Create");
- };
- },null,function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.SAbortError = "Operation aborted";
- $impl.CheckBoolStrs = function () {
- if (rtl.length($mod.TrueBoolStrs) === 0) {
- $mod.TrueBoolStrs = rtl.arraySetLength($mod.TrueBoolStrs,"",1);
- $mod.TrueBoolStrs[0] = "True";
- };
- if (rtl.length($mod.FalseBoolStrs) === 0) {
- $mod.FalseBoolStrs = rtl.arraySetLength($mod.FalseBoolStrs,"",1);
- $mod.FalseBoolStrs[0] = "False";
- };
- };
- $impl.feInvalidFormat = 1;
- $impl.feMissingArgument = 2;
- $impl.feInvalidArgIndex = 3;
- $impl.DoFormatError = function (ErrCode, fmt) {
- var $tmp1 = ErrCode;
- if ($tmp1 === 1) {
- throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidFormat,[fmt]])}
- else if ($tmp1 === 2) {
- throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SArgumentMissing,[fmt]])}
- else if ($tmp1 === 3) throw $mod.EConvertError.$create("CreateFmt",[pas.RTLConsts.SInvalidArgIndex,[fmt]]);
- };
- $impl.maxdigits = 15;
- $impl.ReplaceDecimalSep = function (S, DS) {
- var Result = "";
- var P = 0;
- P = pas.System.Pos(".",S);
- if (P > 0) {
- Result = (pas.System.Copy(S,1,P - 1) + DS) + pas.System.Copy(S,P + 1,S.length - P)}
- else Result = S;
- return Result;
- };
- $impl.FormatGeneralFloat = function (Value, Precision, DS) {
- var Result = "";
- var P = 0;
- var PE = 0;
- var Q = 0;
- var Exponent = 0;
- if ((Precision === -1) || (Precision > 15)) Precision = 15;
- Result = rtl.floatToStr(Value,Precision + 7);
- Result = $mod.TrimLeft(Result);
- P = pas.System.Pos(".",Result);
- if (P === 0) return Result;
- PE = pas.System.Pos("E",Result);
- if (PE === 0) {
- Result = $impl.ReplaceDecimalSep(Result,DS);
- return Result;
- };
- Q = PE + 2;
- Exponent = 0;
- while (Q <= Result.length) {
- Exponent = ((Exponent * 10) + Result.charCodeAt(Q - 1)) - "0".charCodeAt();
- Q += 1;
- };
- if (Result.charAt((PE + 1) - 1) === "-") Exponent = -Exponent;
- if (((P + Exponent) < PE) && (Exponent > -6)) {
- Result = rtl.strSetLength(Result,PE - 1);
- if (Exponent >= 0) {
- for (var $l1 = 0, $end2 = Exponent - 1; $l1 <= $end2; $l1++) {
- Q = $l1;
- Result = rtl.setCharAt(Result,P - 1,Result.charAt((P + 1) - 1));
- P += 1;
- };
- Result = rtl.setCharAt(Result,P - 1,".");
- P = 1;
- if (Result.charAt(P - 1) === "-") P += 1;
- while (((Result.charAt(P - 1) === "0") && (P < Result.length)) && (pas.System.Copy(Result,P + 1,DS.length) !== DS)) pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P,1);
- } else {
- pas.System.Insert(pas.System.Copy("00000",1,-Exponent),{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P - 1);
- Result = rtl.setCharAt(Result,(P - Exponent) - 1,Result.charAt(((P - Exponent) - 1) - 1));
- Result = rtl.setCharAt(Result,P - 1,".");
- if (Exponent !== -1) Result = rtl.setCharAt(Result,((P - Exponent) - 1) - 1,"0");
- };
- Q = Result.length;
- while ((Q > 0) && (Result.charAt(Q - 1) === "0")) Q -= 1;
- if (Result.charAt(Q - 1) === ".") Q -= 1;
- if ((Q === 0) || ((Q === 1) && (Result.charAt(0) === "-"))) {
- Result = "0"}
- else Result = rtl.strSetLength(Result,Q);
- } else {
- while (Result.charAt((PE - 1) - 1) === "0") {
- pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},PE - 1,1);
- PE -= 1;
- };
- if (Result.charAt((PE - 1) - 1) === DS) {
- pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},PE - 1,1);
- PE -= 1;
- };
- if (Result.charAt((PE + 1) - 1) === "+") {
- pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},PE + 1,1)}
- else PE += 1;
- while (Result.charAt((PE + 1) - 1) === "0") pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},PE + 1,1);
- };
- Result = $impl.ReplaceDecimalSep(Result,DS);
- return Result;
- };
- $impl.FormatExponentFloat = function (Value, Precision, Digits, DS) {
- var Result = "";
- var P = 0;
- DS = $mod.DecimalSeparator;
- if ((Precision === -1) || (Precision > 15)) Precision = 15;
- Result = rtl.floatToStr(Value,Precision + 7);
- while (Result.charAt(0) === " ") pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},1,1);
- P = pas.System.Pos("E",Result);
- if (P === 0) {
- Result = $impl.ReplaceDecimalSep(Result,DS);
- return Result;
- };
- P += 2;
- if (Digits > 4) Digits = 4;
- Digits = ((Result.length - P) - Digits) + 1;
- if (Digits < 0) {
- pas.System.Insert(pas.System.Copy("0000",1,-Digits),{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P)}
- else while ((Digits > 0) && (Result.charAt(P - 1) === "0")) {
- pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P,1);
- if (P > Result.length) {
- pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P - 2,2);
- break;
- };
- Digits -= 1;
- };
- Result = $impl.ReplaceDecimalSep(Result,DS);
- return Result;
- };
- $impl.FormatFixedFloat = function (Value, Digits, DS) {
- var Result = "";
- if (Digits === -1) {
- Digits = 2}
- else if (Digits > 18) Digits = 18;
- Result = rtl.floatToStr(Value,0,Digits);
- if ((Result !== "") && (Result.charAt(0) === " ")) pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},1,1);
- Result = $impl.ReplaceDecimalSep(Result,DS);
- return Result;
- };
- $impl.FormatNumberFloat = function (Value, Digits, DS, TS) {
- var Result = "";
- var P = 0;
- if (Digits === -1) {
- Digits = 2}
- else if (Digits > 15) Digits = 15;
- Result = rtl.floatToStr(Value,0,Digits);
- if ((Result !== "") && (Result.charAt(0) === " ")) pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},1,1);
- P = pas.System.Pos(".",Result);
- Result = $impl.ReplaceDecimalSep(Result,DS);
- P -= 3;
- if ((TS !== "") && (TS !== "\x00")) while (P > 1) {
- if (Result.charAt((P - 1) - 1) !== "-") pas.System.Insert(TS,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P);
- P -= 3;
- };
- return Result;
- };
- $impl.RemoveLeadingNegativeSign = function (AValue, DS) {
- var Result = false;
- var i = 0;
- var TS = "";
- var StartPos = 0;
- Result = false;
- StartPos = 2;
- TS = $mod.ThousandSeparator;
- for (var $l1 = StartPos, $end2 = AValue.get().length; $l1 <= $end2; $l1++) {
- i = $l1;
- Result = (AValue.get().charCodeAt(i - 1) in rtl.createSet(48,DS.charCodeAt(),69,43)) || (AValue.get() === TS);
- if (!Result) break;
- };
- if (Result) pas.System.Delete(AValue,1,1);
- return Result;
- };
- $impl.FormatNumberCurrency = function (Value, Digits, DS, TS) {
- var Result = "";
- var Negative = false;
- var P = 0;
- if (Digits === -1) {
- Digits = $mod.CurrencyDecimals}
- else if (Digits > 18) Digits = 18;
- Result = rtl.spaceLeft("" + Value,0);
- Negative = Result.charAt(0) === "-";
- if (Negative) pas.System.Delete({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},1,1);
- P = pas.System.Pos(".",Result);
- if (P !== 0) {
- Result = $impl.ReplaceDecimalSep(Result,DS)}
- else P = Result.length + 1;
- P -= 3;
- while (P > 1) {
- if ($mod.ThousandSeparator !== "\x00") pas.System.Insert($mod.FormatSettings.GetThousandSeparator(),{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},P);
- P -= 3;
- };
- if ((Result.length > 1) && Negative) Negative = !$impl.RemoveLeadingNegativeSign({get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }},DS);
- if (!Negative) {
- var $tmp1 = $mod.CurrencyFormat;
- if ($tmp1 === 0) {
- Result = $mod.CurrencyString + Result}
- else if ($tmp1 === 1) {
- Result = Result + $mod.CurrencyString}
- else if ($tmp1 === 2) {
- Result = ($mod.CurrencyString + " ") + Result}
- else if ($tmp1 === 3) Result = (Result + " ") + $mod.CurrencyString;
- } else {
- var $tmp2 = $mod.NegCurrFormat;
- if ($tmp2 === 0) {
- Result = (("(" + $mod.CurrencyString) + Result) + ")"}
- else if ($tmp2 === 1) {
- Result = ("-" + $mod.CurrencyString) + Result}
- else if ($tmp2 === 2) {
- Result = ($mod.CurrencyString + "-") + Result}
- else if ($tmp2 === 3) {
- Result = ($mod.CurrencyString + Result) + "-"}
- else if ($tmp2 === 4) {
- Result = (("(" + Result) + $mod.CurrencyString) + ")"}
- else if ($tmp2 === 5) {
- Result = ("-" + Result) + $mod.CurrencyString}
- else if ($tmp2 === 6) {
- Result = (Result + "-") + $mod.CurrencyString}
- else if ($tmp2 === 7) {
- Result = (Result + $mod.CurrencyString) + "-"}
- else if ($tmp2 === 8) {
- Result = (("-" + Result) + " ") + $mod.CurrencyString}
- else if ($tmp2 === 9) {
- Result = (("-" + $mod.CurrencyString) + " ") + Result}
- else if ($tmp2 === 10) {
- Result = ((Result + " ") + $mod.CurrencyString) + "-"}
- else if ($tmp2 === 11) {
- Result = (($mod.CurrencyString + " ") + Result) + "-"}
- else if ($tmp2 === 12) {
- Result = (($mod.CurrencyString + " ") + "-") + Result}
- else if ($tmp2 === 13) {
- Result = ((Result + "-") + " ") + $mod.CurrencyString}
- else if ($tmp2 === 14) {
- Result = ((("(" + $mod.CurrencyString) + " ") + Result) + ")"}
- else if ($tmp2 === 15) Result = ((("(" + Result) + " ") + $mod.CurrencyString) + ")";
- };
- if (TS === "") ;
- return Result;
- };
- $impl.RESpecials = "([\\[\\]\\(\\)\\\\\\.\\*])";
- $impl.DoEncodeDate = function (Year, Month, Day) {
- var Result = 0;
- var D = 0.0;
- if ($mod.TryEncodeDate(Year,Month,Day,{get: function () {
- return D;
- }, set: function (v) {
- D = v;
- }})) {
- Result = pas.System.Trunc(D)}
- else Result = 0;
- return Result;
- };
- $impl.DoEncodeTime = function (Hour, Minute, Second, MilliSecond) {
- var Result = 0.0;
- if (!$mod.TryEncodeTime(Hour,Minute,Second,MilliSecond,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) Result = 0;
- return Result;
- };
- $impl.DateTimeToStrFormat = ["c","f"];
- var WhiteSpace = " \b\t\n\f\r";
- var Digits = "0123456789";
- $impl.IntStrToDate = function (ErrorMsg, S, useformat, separator) {
- var Result = 0.0;
- function FixErrorMsg(errmarg) {
- ErrorMsg.set($mod.Format(pas.RTLConsts.SInvalidDateFormat,[errmarg]));
- };
- var df = "";
- var d = 0;
- var m = 0;
- var y = 0;
- var ly = 0;
- var ld = 0;
- var lm = 0;
- var n = 0;
- var i = 0;
- var len = 0;
- var c = 0;
- var dp = 0;
- var mp = 0;
- var yp = 0;
- var which = 0;
- var s1 = "";
- var values = [];
- var YearMoreThenTwoDigits = false;
- values = rtl.arraySetLength(values,0,4);
- Result = 0;
- len = S.length;
- ErrorMsg.set("");
- while ((len > 0) && (pas.System.Pos(S.charAt(len - 1),WhiteSpace) > 0)) len -= 1;
- if (len === 0) {
- FixErrorMsg(S);
- return Result;
- };
- YearMoreThenTwoDigits = false;
- if (separator === "\x00") if ($mod.DateSeparator !== "\x00") {
- separator = $mod.DateSeparator}
- else separator = "-";
- df = $mod.UpperCase(useformat);
- yp = 0;
- mp = 0;
- dp = 0;
- which = 0;
- i = 0;
- while ((i < df.length) && (which < 3)) {
- i += 1;
- var $tmp1 = df.charAt(i - 1);
- if ($tmp1 === "Y") {
- if (yp === 0) {
- which += 1;
- yp = which;
- }}
- else if ($tmp1 === "M") {
- if (mp === 0) {
- which += 1;
- mp = which;
- }}
- else if ($tmp1 === "D") if (dp === 0) {
- which += 1;
- dp = which;
- };
- };
- for (i = 1; i <= 3; i++) values[i] = 0;
- s1 = "";
- n = 0;
- for (var $l2 = 1, $end3 = len; $l2 <= $end3; $l2++) {
- i = $l2;
- if (pas.System.Pos(S.charAt(i - 1),Digits) > 0) s1 = s1 + S.charAt(i - 1);
- if ((separator !== " ") && (S.charAt(i - 1) === " ")) continue;
- if ((S.charAt(i - 1) === separator) || ((i === len) && (pas.System.Pos(S.charAt(i - 1),Digits) > 0))) {
- n += 1;
- if (n > 3) {
- FixErrorMsg(S);
- return Result;
- };
- if ((n === yp) && (s1.length > 2)) YearMoreThenTwoDigits = true;
- pas.System.val$5(s1,{a: n, p: values, get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }},{get: function () {
- return c;
- }, set: function (v) {
- c = v;
- }});
- if (c !== 0) {
- FixErrorMsg(S);
- return Result;
- };
- s1 = "";
- } else if (pas.System.Pos(S.charAt(i - 1),Digits) === 0) {
- FixErrorMsg(S);
- return Result;
- };
- };
- if ((which < 3) && (n > which)) {
- FixErrorMsg(S);
- return Result;
- };
- $mod.DecodeDate($mod.date(),{get: function () {
- return ly;
- }, set: function (v) {
- ly = v;
- }},{get: function () {
- return lm;
- }, set: function (v) {
- lm = v;
- }},{get: function () {
- return ld;
- }, set: function (v) {
- ld = v;
- }});
- if (n === 3) {
- y = values[yp];
- m = values[mp];
- d = values[dp];
- } else {
- y = ly;
- if (n < 2) {
- d = values[1];
- m = lm;
- } else if (dp < mp) {
- d = values[1];
- m = values[2];
- } else {
- d = values[2];
- m = values[1];
- };
- };
- if (((y >= 0) && (y < 100)) && !YearMoreThenTwoDigits) {
- ly = ly - $mod.TwoDigitYearCenturyWindow;
- y += Math.floor(ly / 100) * 100;
- if (($mod.TwoDigitYearCenturyWindow > 0) && (y < ly)) y += 100;
- };
- if (!$mod.TryEncodeDate(y,m,d,{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) ErrorMsg.set(pas.RTLConsts.SErrInvalidDate);
- return Result;
- };
- var AMPM_None = 0;
- var AMPM_AM = 1;
- var AMPM_PM = 2;
- var tiHour = 0;
- var tiMin = 1;
- var tiSec = 2;
- var tiMSec = 3;
- var Digits$1 = "0123456789";
- $impl.IntStrToTime = function (ErrorMsg, S, Len, separator) {
- var Result = 0.0;
- var AmPm = 0;
- var TimeValues = [];
- function SplitElements(TimeValues, AmPm) {
- var Result = false;
- var Cur = 0;
- var Offset = 0;
- var ElemLen = 0;
- var Err = 0;
- var TimeIndex = 0;
- var FirstSignificantDigit = 0;
- var Value = 0;
- var DigitPending = false;
- var MSecPending = false;
- var AmPmStr = "";
- var CurChar = "";
- var I = 0;
- var allowedchars = "";
- Result = false;
- AmPm.set(0);
- MSecPending = false;
- TimeIndex = 0;
- for (I = 0; I <= 3; I++) TimeValues.get()[I] = 0;
- Cur = 1;
- while ((Cur < Len) && (S.charAt(Cur - 1) === " ")) Cur += 1;
- Offset = Cur;
- if (((Cur > (Len - 1)) || (S.charAt(Cur - 1) === separator)) || (S.charAt(Cur - 1) === $mod.DecimalSeparator)) {
- return Result;
- };
- DigitPending = pas.System.Pos(S.charAt(Cur - 1),Digits$1) > 0;
- while (Cur <= Len) {
- CurChar = S.charAt(Cur - 1);
- if (pas.System.Pos(CurChar,Digits$1) > 0) {
- if (!DigitPending || (TimeIndex > 3)) {
- return Result;
- };
- Offset = Cur;
- if (CurChar !== "0") {
- FirstSignificantDigit = Offset}
- else FirstSignificantDigit = -1;
- while ((Cur < Len) && (pas.System.Pos(S.charAt((Cur + 1) - 1),Digits$1) > 0)) {
- if ((FirstSignificantDigit === -1) && (S.charAt(Cur - 1) !== "0")) FirstSignificantDigit = Cur;
- Cur += 1;
- };
- if (FirstSignificantDigit === -1) FirstSignificantDigit = Cur;
- ElemLen = (1 + Cur) - FirstSignificantDigit;
- if ((ElemLen <= 2) || ((ElemLen <= 3) && (TimeIndex === 3))) {
- pas.System.val$5(pas.System.Copy(S,FirstSignificantDigit,ElemLen),{get: function () {
- return Value;
- }, set: function (v) {
- Value = v;
- }},{get: function () {
- return Err;
- }, set: function (v) {
- Err = v;
- }});
- TimeValues.get()[TimeIndex] = Value;
- TimeIndex += 1;
- DigitPending = false;
- } else {
- return Result;
- };
- } else if (CurChar === " ") {}
- else if (CurChar === separator) {
- if (DigitPending || (TimeIndex > 2)) {
- return Result;
- };
- DigitPending = true;
- MSecPending = false;
- } else if (CurChar === $mod.DecimalSeparator) {
- if ((DigitPending || MSecPending) || (TimeIndex !== 3)) {
- return Result;
- };
- DigitPending = true;
- MSecPending = true;
- } else {
- if ((AmPm.get() !== 0) || DigitPending) {
- return Result;
- };
- Offset = Cur;
- allowedchars = $mod.DecimalSeparator + " ";
- if (separator !== "\x00") allowedchars = allowedchars + separator;
- 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;
- ElemLen = (1 + Cur) - Offset;
- AmPmStr = pas.System.Copy(S,1 + Offset,ElemLen);
- if ($mod.CompareText(AmPmStr,$mod.TimeAMString) === 0) {
- AmPm.set(1)}
- else if ($mod.CompareText(AmPmStr,$mod.TimePMString) === 0) {
- AmPm.set(2)}
- else if ($mod.CompareText(AmPmStr,"AM") === 0) {
- AmPm.set(1)}
- else if ($mod.CompareText(AmPmStr,"PM") === 0) {
- AmPm.set(2)}
- else {
- return Result;
- };
- if (TimeIndex === 0) {
- DigitPending = true;
- } else {
- TimeIndex = 3 + 1;
- DigitPending = false;
- };
- };
- Cur += 1;
- };
- if (((TimeIndex === 0) || ((AmPm.get() !== 0) && ((TimeValues.get()[0] > 12) || (TimeValues.get()[0] === 0)))) || DigitPending) return Result;
- Result = true;
- return Result;
- };
- TimeValues = rtl.arraySetLength(TimeValues,0,4);
- if (separator === "\x00") if ($mod.TimeSeparator !== "\x00") {
- separator = $mod.TimeSeparator}
- else separator = ":";
- AmPm = 0;
- if (!SplitElements({get: function () {
- return TimeValues;
- }, set: function (v) {
- TimeValues = v;
- }},{get: function () {
- return AmPm;
- }, set: function (v) {
- AmPm = v;
- }})) {
- ErrorMsg.set($mod.Format(pas.RTLConsts.SErrInvalidTimeFormat,[S]));
- return Result;
- };
- if ((AmPm === 2) && (TimeValues[0] !== 12)) {
- TimeValues[0] += 12}
- else if ((AmPm === 1) && (TimeValues[0] === 12)) TimeValues[0] = 0;
- if (!$mod.TryEncodeTime(TimeValues[0],TimeValues[1],TimeValues[2],TimeValues[3],{get: function () {
- return Result;
- }, set: function (v) {
- Result = v;
- }})) ErrorMsg.set($mod.Format(pas.RTLConsts.SErrInvalidTimeFormat,[S]));
- return Result;
- };
- var WhiteSpace$1 = "\t\n\r ";
- $impl.SplitDateTimeStr = function (DateTimeStr, DateStr, TimeStr) {
- var Result = 0;
- var p = 0;
- var DummyDT = 0.0;
- Result = 0;
- DateStr.set("");
- TimeStr.set("");
- DateTimeStr = $mod.Trim(DateTimeStr);
- if (DateTimeStr.length === 0) return Result;
- if ((($mod.DateSeparator === " ") && ($mod.TimeSeparator === " ")) && (pas.System.Pos(" ",DateTimeStr) > 0)) {
- DateStr.set(DateTimeStr);
- return 1;
- };
- p = 1;
- if ($mod.DateSeparator !== " ") {
- while ((p < DateTimeStr.length) && !(pas.System.Pos(DateTimeStr.charAt((p + 1) - 1),WhiteSpace$1) > 0)) p += 1;
- } else {
- p = pas.System.Pos($mod.TimeSeparator,DateTimeStr);
- if (p !== 0) do {
- p -= 1;
- } while (!((p === 0) || (pas.System.Pos(DateTimeStr.charAt(p - 1),WhiteSpace$1) > 0)));
- };
- if (p === 0) p = DateTimeStr.length;
- DateStr.set(pas.System.Copy(DateTimeStr,1,p));
- TimeStr.set($mod.Trim(pas.System.Copy(DateTimeStr,p + 1,100)));
- if (TimeStr.get().length !== 0) {
- Result = 2}
- else {
- Result = 1;
- if ((($mod.DateSeparator !== $mod.TimeSeparator) && (pas.System.Pos($mod.TimeSeparator,DateStr.get()) > 0)) || (($mod.DateSeparator === $mod.TimeSeparator) && !$mod.TryStrToDate(DateStr.get(),{get: function () {
- return DummyDT;
- }, set: function (v) {
- DummyDT = v;
- }}))) {
- TimeStr.set(DateStr.get());
- DateStr.set("");
- };
- };
- return Result;
- };
- });
- rtl.module("math",["System","SysUtils"],function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- this.MinInteger = -0x10000000000000;
- this.MaxInteger = 0xfffffffffffff;
- this.MinDouble = 5.0e-324;
- this.MaxDouble = 1.7e+308;
- this.InRange = function (AValue, AMin, AMax) {
- return (AValue >= AMin) && (AValue <= AMax);
- };
- this.InRange$1 = function (AValue, AMin, AMax) {
- return (AValue >= AMin) && (AValue <= AMax);
- };
- this.EnsureRange = function (AValue, AMin, AMax) {
- if (AValue<AMin){ return AMin;
- } else if (AValue>AMax){ return AMax;
- } else return AValue;
- };
- this.EnsureRange$1 = function (AValue, AMin, AMax) {
- if (AValue<AMin){ return AMin;
- } else if (AValue>AMax){ return AMax;
- } else return AValue;
- };
- this.RoundTo = function (AValue, Digits) {
- var Result = 0.0;
- var RV = 0.0;
- RV = $mod.IntPower(10,Digits);
- Result = Math.round(AValue / RV) * RV;
- return Result;
- };
- this.SimpleRoundTo = function (AValue, Digits) {
- var Result = 0.0;
- var RV = 0.0;
- RV = $mod.IntPower(10,-Digits);
- if (AValue < 0) {
- Result = pas.System.Int((AValue * RV) - 0.5) / RV}
- else Result = pas.System.Int((AValue * RV) + 0.5) / RV;
- return Result;
- };
- this.randg = function (mean, stddev) {
- var Result = 0.0;
- var U1 = 0.0;
- var S2 = 0.0;
- do {
- U1 = (2 * Math.random()) - 1;
- S2 = pas.System.Sqr$1(U1) + pas.System.Sqr$1((2 * Math.random()) - 1);
- } while (!(S2 < 1));
- Result = ((Math.sqrt((-2 * Math.log(S2)) / S2) * U1) * stddev) + mean;
- return Result;
- };
- this.RandomRange = function (aFrom, aTo) {
- var Result = 0;
- Result = pas.System.Random(Math.abs(aFrom - aTo)) + Math.min(aTo,aFrom);
- return Result;
- };
- this.RandomRange$1 = function (aFrom, aTo) {
- var Result = 0;
- var m = 0;
- if (aFrom < aTo) {
- m = aFrom}
- else m = aTo;
- Result = pas.System.Random(Math.abs(aFrom - aTo)) + m;
- return Result;
- };
- this.NegativeValue = -1;
- this.ZeroValue = 0;
- this.PositiveValue = 1;
- this.IsZero = function (d, Epsilon) {
- var Result = false;
- if (Epsilon === 0) Epsilon = 1E-12;
- Result = Math.abs(d) <= Epsilon;
- return Result;
- };
- this.IsZero$1 = function (d) {
- var Result = false;
- Result = Math.abs(d) <= 1E-12;
- return Result;
- };
- this.IsInfinite = function (d) {
- return (d==Infinite) || (d==-Infinite);
- };
- this.SameValue = function (A, B, Epsilon) {
- var Result = false;
- if (Epsilon === 0.0) Epsilon = Math.max(Math.min(Math.abs(A),Math.abs(B)) * 1E-12,1E-12);
- if (A > B) {
- Result = (A - B) <= Epsilon}
- else Result = (B - A) <= Epsilon;
- return Result;
- };
- this.LogN = function (A, Base) {
- var Result = 0.0;
- Result = Math.log(A) / Math.log(Base);
- return Result;
- };
- this.Ceil = function (A) {
- var Result = 0;
- Result = pas.System.Trunc(Math.ceil(A));
- return Result;
- };
- this.Floor = function (A) {
- var Result = 0;
- Result = pas.System.Trunc(Math.floor(A));
- return Result;
- };
- this.Ceil64 = function (A) {
- var Result = 0;
- Result = pas.System.Trunc(Math.ceil(A));
- return Result;
- };
- this.Floor64 = function (A) {
- var Result = 0;
- Result = pas.System.Trunc(Math.ceil(A));
- return Result;
- };
- this.ldexp = function (x, p) {
- var Result = 0.0;
- Result = x * $mod.IntPower(2.0,p);
- return Result;
- };
- this.Frexp = function (X, Mantissa, Exponent) {
- Exponent.set(0);
- if (X !== 0) if (Math.abs(X) < 0.5) {
- do {
- X = X * 2;
- Exponent.set(Exponent.get() - 1);
- } while (!(Math.abs(X) >= 0.5))}
- else while (Math.abs(X) >= 1) {
- X = X / 2;
- Exponent.set(Exponent.get() + 1);
- };
- Mantissa.set(X);
- };
- this.lnxp1 = function (x) {
- var Result = 0.0;
- var y = 0.0;
- if (x >= 4.0) {
- Result = Math.log(1.0 + x)}
- else {
- y = 1.0 + x;
- if (y === 1.0) {
- Result = x}
- else {
- Result = Math.log(y);
- if (y > 0.0) Result = Result + ((x - (y - 1.0)) / y);
- };
- };
- return Result;
- };
- this.IntPower = function (base, exponent) {
- var Result = 0.0;
- var i = 0;
- if ((base === 0.0) && (exponent === 0)) {
- Result = 1}
- else {
- i = Math.abs(exponent);
- Result = 1.0;
- while (i > 0) {
- while ((i & 1) === 0) {
- i = i >>> 1;
- base = pas.System.Sqr$1(base);
- };
- i = i - 1;
- Result = Result * base;
- };
- if (exponent < 0) Result = 1.0 / Result;
- };
- return Result;
- };
- this.DivMod = function (Dividend, Divisor, Result, Remainder) {
- if (Dividend < 0) {
- Dividend = -Dividend;
- Result.set(-Math.floor(Dividend / Divisor));
- Remainder.set(-(Dividend + (Result.get() * Divisor)));
- } else {
- Result.set(Math.floor(Dividend / Divisor));
- Remainder.set(Dividend - (Result.get() * Divisor));
- };
- };
- this.DivMod$1 = function (Dividend, Divisor, Result, Remainder) {
- if (Dividend < 0) {
- Dividend = -Dividend;
- Result.set(-Math.floor(Dividend / Divisor));
- Remainder.set(-(Dividend + (Result.get() * Divisor)));
- } else {
- Result.set(Math.floor(Dividend / Divisor));
- Remainder.set(Dividend - (Result.get() * Divisor));
- };
- };
- this.DivMod$2 = function (Dividend, Divisor, Result, Remainder) {
- Result.set(Math.floor(Dividend / Divisor));
- Remainder.set(Dividend - (Result.get() * Divisor));
- };
- this.DivMod$3 = function (Dividend, Divisor, Result, Remainder) {
- if (Dividend < 0) {
- Dividend = -Dividend;
- Result.set(-Math.floor(Dividend / Divisor));
- Remainder.set(-(Dividend + (Result.get() * Divisor)));
- } else {
- Result.set(Math.floor(Dividend / Divisor));
- Remainder.set(Dividend - (Result.get() * Divisor));
- };
- };
- this.DegToRad = function (deg) {
- var Result = 0.0;
- Result = deg * (Math.PI / 180.0);
- return Result;
- };
- this.RadToDeg = function (rad) {
- var Result = 0.0;
- Result = rad * (180.0 / Math.PI);
- return Result;
- };
- this.GradToRad = function (grad) {
- var Result = 0.0;
- Result = grad * (Math.PI / 200.0);
- return Result;
- };
- this.RadToGrad = function (rad) {
- var Result = 0.0;
- Result = rad * (200.0 / Math.PI);
- return Result;
- };
- this.DegToGrad = function (deg) {
- var Result = 0.0;
- Result = deg * (200.0 / 180.0);
- return Result;
- };
- this.GradToDeg = function (grad) {
- var Result = 0.0;
- Result = grad * (180.0 / 200.0);
- return Result;
- };
- this.CycleToRad = function (cycle) {
- var Result = 0.0;
- Result = (2 * Math.PI) * cycle;
- return Result;
- };
- this.RadToCycle = function (rad) {
- var Result = 0.0;
- Result = rad * (1 / (2 * Math.PI));
- return Result;
- };
- this.DegNormalize = function (deg) {
- var Result = 0.0;
- Result = deg - (pas.System.Int(deg / 360) * 360);
- if (Result < 0) Result = Result + 360;
- return Result;
- };
- this.Norm = function (data) {
- var Result = 0.0;
- Result = Math.sqrt($impl.sumofsquares(data));
- return Result;
- };
- this.Mean = function (data) {
- var Result = 0.0;
- var N = 0;
- N = rtl.length(data);
- if (N === 0) {
- Result = 0}
- else Result = $mod.Sum(data) / N;
- return Result;
- };
- this.Sum = function (data) {
- var Result = 0.0;
- var i = 0;
- var N = 0;
- N = rtl.length(data);
- Result = 0.0;
- for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
- i = $l1;
- Result = Result + data[i];
- };
- return Result;
- };
- this.SumsAndSquares = function (data, Sum, SumOfSquares) {
- var i = 0;
- var n = 0;
- var t = 0.0;
- var s = 0.0;
- var ss = 0.0;
- n = rtl.length(data);
- ss = 0.0;
- s = 0.0;
- for (var $l1 = 0, $end2 = n - 1; $l1 <= $end2; $l1++) {
- i = $l1;
- t = data[i];
- ss = ss + pas.System.Sqr$1(t);
- s = s + t;
- };
- Sum.set(s);
- SumOfSquares.set(ss);
- };
- this.StdDev = function (data) {
- var Result = 0.0;
- Result = Math.sqrt($mod.Variance(data));
- return Result;
- };
- this.MeanAndStdDev = function (data, Mean, StdDev) {
- var I = 0;
- var N = 0;
- var M = 0.0;
- var S = 0.0;
- N = rtl.length(data);
- M = 0;
- S = 0;
- for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
- I = $l1;
- M = M + data[I];
- S = S + pas.System.Sqr$1(data[I]);
- };
- M = M / N;
- S = S - (N * pas.System.Sqr$1(M));
- if (N > 1) {
- S = Math.sqrt(S / (N - 1))}
- else S = 0;
- Mean.set(M);
- StdDev.set(S);
- };
- this.Variance = function (data) {
- var Result = 0.0;
- var n = 0;
- n = rtl.length(data);
- if (n === 1) {
- Result = 0}
- else Result = $mod.TotalVariance(data) / (n - 1);
- return Result;
- };
- this.TotalVariance = function (data) {
- var Result = 0.0;
- var S = 0.0;
- var SS = 0.0;
- var N = 0;
- N = rtl.length(data);
- if (rtl.length(data) === 1) {
- Result = 0}
- else {
- $mod.SumsAndSquares(data,{get: function () {
- return S;
- }, set: function (v) {
- S = v;
- }},{get: function () {
- return SS;
- }, set: function (v) {
- SS = v;
- }});
- Result = SS - (pas.System.Sqr$1(S) / N);
- };
- return Result;
- };
- this.PopNStdDev = function (data) {
- var Result = 0.0;
- Result = Math.sqrt($mod.PopNVariance(data));
- return Result;
- };
- this.PopNVariance = function (data) {
- var Result = 0.0;
- var N = 0;
- N = rtl.length(data);
- if (N === 0) {
- Result = 0}
- else Result = $mod.TotalVariance(data) / N;
- return Result;
- };
- this.MomentSkewKurtosis = function (data, m1, m2, m3, m4, skew, kurtosis) {
- var i = 0;
- var N = 0;
- var deviation = 0.0;
- var deviation2 = 0.0;
- var reciprocalN = 0.0;
- var lm1 = 0.0;
- var lm2 = 0.0;
- var lm3 = 0.0;
- var lm4 = 0.0;
- var lskew = 0.0;
- var lkurtosis = 0.0;
- N = rtl.length(data);
- lm1 = 0;
- reciprocalN = 1 / N;
- for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
- i = $l1;
- lm1 = lm1 + data[i];
- };
- lm1 = reciprocalN * lm1;
- lm2 = 0;
- lm3 = 0;
- lm4 = 0;
- for (var $l3 = 0, $end4 = N - 1; $l3 <= $end4; $l3++) {
- i = $l3;
- deviation = data[i] - lm1;
- deviation2 = deviation * deviation;
- lm2 = lm2 + deviation2;
- lm3 = lm3 + (deviation2 * deviation);
- lm4 = lm4 + (deviation2 * deviation2);
- };
- lm2 = reciprocalN * lm2;
- lm3 = reciprocalN * lm3;
- lm4 = reciprocalN * lm4;
- lskew = lm3 / (Math.sqrt(lm2) * lm2);
- lkurtosis = lm4 / (lm2 * lm2);
- m1.set(lm1);
- m2.set(lm2);
- m3.set(lm3);
- m4.set(lm4);
- skew.set(lskew);
- kurtosis.set(lkurtosis);
- };
- this.TPaymentTime = {"0": "ptEndOfPeriod", ptEndOfPeriod: 0, "1": "ptStartOfPeriod", ptStartOfPeriod: 1};
- this.FutureValue = function (ARate, NPeriods, APayment, APresentValue, APaymentTime) {
- var Result = 0.0;
- var q = 0.0;
- var qn = 0.0;
- var factor = 0.0;
- if (ARate === 0) {
- Result = -APresentValue - (APayment * NPeriods)}
- else {
- q = 1.0 + ARate;
- qn = Math.pow(q,NPeriods);
- factor = (qn - 1) / (q - 1);
- if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
- Result = -((APresentValue * qn) + (APayment * factor));
- };
- return Result;
- };
- var DELTA = 0.001;
- var EPS = 1E-9;
- var MAXIT = 20;
- this.InterestRate = function (NPeriods, APayment, APresentValue, AFutureValue, APaymentTime) {
- var Result = 0.0;
- var r1 = 0.0;
- var r2 = 0.0;
- var dr = 0.0;
- var fv1 = 0.0;
- var fv2 = 0.0;
- var iteration = 0;
- iteration = 0;
- r1 = 0.05;
- do {
- r2 = r1 + 0.001;
- fv1 = $mod.FutureValue(r1,NPeriods,APayment,APresentValue,APaymentTime);
- fv2 = $mod.FutureValue(r2,NPeriods,APayment,APresentValue,APaymentTime);
- dr = ((AFutureValue - fv1) / (fv2 - fv1)) * 0.001;
- r1 = r1 + dr;
- iteration += 1;
- } while (!((Math.abs(dr) < 1.0E-9) || (iteration >= 20)));
- Result = r1;
- return Result;
- };
- this.NumberOfPeriods = function (ARate, APayment, APresentValue, AFutureValue, APaymentTime) {
- var Result = 0.0;
- var q = 0.0;
- var x1 = 0.0;
- var x2 = 0.0;
- if (ARate === 0) {
- Result = -(APresentValue + AFutureValue) / APayment}
- else {
- q = 1.0 + ARate;
- if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) APayment = APayment * q;
- x1 = APayment - (AFutureValue * ARate);
- x2 = APayment + (APresentValue * ARate);
- if ((x2 === 0) || ((Math.sign(x1) * Math.sign(x2)) < 0)) {
- Result = Infinity}
- else {
- Result = Math.log(x1 / x2) / Math.log(q);
- };
- };
- return Result;
- };
- this.Payment = function (ARate, NPeriods, APresentValue, AFutureValue, APaymentTime) {
- var Result = 0.0;
- var q = 0.0;
- var qn = 0.0;
- var factor = 0.0;
- if (ARate === 0) {
- Result = -(AFutureValue + APresentValue) / NPeriods}
- else {
- q = 1.0 + ARate;
- qn = Math.pow(q,NPeriods);
- factor = (qn - 1) / (q - 1);
- if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
- Result = -(AFutureValue + (APresentValue * qn)) / factor;
- };
- return Result;
- };
- this.PresentValue = function (ARate, NPeriods, APayment, AFutureValue, APaymentTime) {
- var Result = 0.0;
- var q = 0.0;
- var qn = 0.0;
- var factor = 0.0;
- if (ARate === 0.0) {
- Result = -AFutureValue - (APayment * NPeriods)}
- else {
- q = 1.0 + ARate;
- qn = Math.pow(q,NPeriods);
- factor = (qn - 1) / (q - 1);
- if (APaymentTime === $mod.TPaymentTime.ptStartOfPeriod) factor = factor * q;
- Result = -(AFutureValue + (APayment * factor)) / qn;
- };
- return Result;
- };
- this.IfThen = function (val, ifTrue, ifFalse) {
- var Result = 0;
- if (val) {
- Result = ifTrue}
- else Result = ifFalse;
- return Result;
- };
- this.IfThen$1 = function (val, ifTrue, ifFalse) {
- var Result = 0.0;
- if (val) {
- Result = ifTrue}
- else Result = ifFalse;
- return Result;
- };
- this.EqualsValue = 0;
- this.LessThanValue = -1;
- this.GreaterThanValue = 1;
- this.CompareValue = function (A, B) {
- var Result = -1;
- Result = 1;
- if (A === B) {
- Result = 0}
- else if (A < B) Result = -1;
- return Result;
- };
- this.CompareValue$1 = function (A, B) {
- var Result = -1;
- Result = 1;
- if (A === B) {
- Result = 0}
- else if (A < B) Result = -1;
- return Result;
- };
- this.CompareValue$2 = function (A, B) {
- var Result = -1;
- Result = 1;
- if (A === B) {
- Result = 0}
- else if (A < B) Result = -1;
- return Result;
- };
- this.CompareValue$3 = function (A, B, delta) {
- var Result = -1;
- Result = 1;
- if (Math.abs(A - B) <= delta) {
- Result = 0}
- else if (A < B) Result = -1;
- return Result;
- };
- },null,function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.DZeroResolution = 1E-12;
- $impl.sumofsquares = function (data) {
- var Result = 0.0;
- var i = 0;
- var N = 0;
- N = rtl.length(data);
- Result = 0.0;
- for (var $l1 = 0, $end2 = N - 1; $l1 <= $end2; $l1++) {
- i = $l1;
- Result = Result + pas.System.Sqr$1(data[i]);
- };
- return Result;
- };
- });
- rtl.module("Mat4",["System","vectors","browserconsole","JS","webgl"],function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- rtl.createClass($mod,"TMat4",pas.System.TObject,function () {
- this.$init = function () {
- pas.System.TObject.$init.call(this);
- this.RawComponents = rtl.arraySetLength(null,0.0,4,4);
- };
- this.$final = function () {
- this.RawComponents = undefined;
- pas.System.TObject.$final.call(this);
- };
- this.Identity = function () {
- this.RawComponents[0][0] = 1.0;
- this.RawComponents[0][1] = 0.0;
- this.RawComponents[0][2] = 0.0;
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = 0.0;
- this.RawComponents[1][1] = 1.0;
- this.RawComponents[1][2] = 0.0;
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][0] = 0.0;
- this.RawComponents[2][1] = 0.0;
- this.RawComponents[2][2] = 1.0;
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = 0.0;
- this.RawComponents[3][1] = 0.0;
- this.RawComponents[3][2] = 0.0;
- this.RawComponents[3][3] = 1.0;
- };
- this.Translate = function (tx, ty, tz) {
- this.RawComponents[0][0] = 1.0;
- this.RawComponents[0][1] = 0.0;
- this.RawComponents[0][2] = 0.0;
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = 0.0;
- this.RawComponents[1][1] = 1.0;
- this.RawComponents[1][2] = 0.0;
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][0] = 0.0;
- this.RawComponents[2][1] = 0.0;
- this.RawComponents[2][2] = 1.0;
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = tx;
- this.RawComponents[3][1] = ty;
- this.RawComponents[3][2] = tz;
- this.RawComponents[3][3] = 1.0;
- };
- this.RotateZ = function (Angle) {
- $mod.SinCos(Angle,{a: 1, p: this.RawComponents[0], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }},{a: 0, p: this.RawComponents[0], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }});
- this.RawComponents[0][2] = 0.0;
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = -this.RawComponents[0][1];
- this.RawComponents[1][1] = this.RawComponents[0][0];
- this.RawComponents[1][2] = 0.0;
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][0] = 0.0;
- this.RawComponents[2][1] = 0.0;
- this.RawComponents[2][2] = 1.0;
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = 0.0;
- this.RawComponents[3][1] = 0.0;
- this.RawComponents[3][2] = 0.0;
- this.RawComponents[3][3] = 1.0;
- };
- this.RotateY = function (Angle) {
- $mod.SinCos(Angle,{a: 0, p: this.RawComponents[2], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }},{a: 0, p: this.RawComponents[0], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }});
- this.RawComponents[0][1] = 0.0;
- this.RawComponents[0][2] = -this.RawComponents[2][0];
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = 0.0;
- this.RawComponents[1][1] = 1.0;
- this.RawComponents[1][2] = 0.0;
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][1] = 0.0;
- this.RawComponents[2][2] = this.RawComponents[0][0];
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = 0.0;
- this.RawComponents[3][1] = 0.0;
- this.RawComponents[3][2] = 0.0;
- this.RawComponents[3][3] = 1.0;
- };
- this.RotateX = function (Angle) {
- this.RawComponents[0][0] = 1.0;
- this.RawComponents[0][1] = 0.0;
- this.RawComponents[0][2] = 0.0;
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = 0.0;
- $mod.SinCos(Angle,{a: 2, p: this.RawComponents[1], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }},{a: 1, p: this.RawComponents[1], get: function () {
- return this.p[this.a];
- }, set: function (v) {
- this.p[this.a] = v;
- }});
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][0] = 0.0;
- this.RawComponents[2][1] = -this.RawComponents[1][2];
- this.RawComponents[2][2] = this.RawComponents[1][1];
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = 0.0;
- this.RawComponents[3][1] = 0.0;
- this.RawComponents[3][2] = 0.0;
- this.RawComponents[3][3] = 1.0;
- };
- this.Scale = function (x, y, z) {
- this.RawComponents[0][0] = x;
- this.RawComponents[0][1] = 0;
- this.RawComponents[0][2] = 0;
- this.RawComponents[0][3] = 0;
- this.RawComponents[1][0] = 0;
- this.RawComponents[1][1] = y;
- this.RawComponents[1][2] = 0;
- this.RawComponents[1][3] = 0;
- this.RawComponents[2][0] = 0;
- this.RawComponents[2][1] = 0;
- this.RawComponents[2][2] = z;
- this.RawComponents[2][3] = 0;
- this.RawComponents[3][0] = 0;
- this.RawComponents[3][1] = 0;
- this.RawComponents[3][2] = 0;
- this.RawComponents[3][3] = 1;
- };
- this.Ortho = function (Left, Right, Bottom, Top, zNear, zFar) {
- var rml = 0.0;
- var tmb = 0.0;
- var fmn = 0.0;
- rml = Right - Left;
- tmb = Top - Bottom;
- fmn = zFar - zNear;
- this.RawComponents[0][0] = 2.0 / rml;
- this.RawComponents[0][1] = 0.0;
- this.RawComponents[0][2] = 0.0;
- this.RawComponents[0][3] = 0.0;
- this.RawComponents[1][0] = 0.0;
- this.RawComponents[1][1] = 2.0 / tmb;
- this.RawComponents[1][2] = 0.0;
- this.RawComponents[1][3] = 0.0;
- this.RawComponents[2][0] = 0.0;
- this.RawComponents[2][1] = 0.0;
- this.RawComponents[2][2] = -2.0 / fmn;
- this.RawComponents[2][3] = 0.0;
- this.RawComponents[3][0] = -(Right + Left) / rml;
- this.RawComponents[3][1] = -(Top + Bottom) / tmb;
- this.RawComponents[3][2] = -(zFar + zNear) / fmn;
- this.RawComponents[3][3] = 1.0;
- };
- this.Perspective = function (fovy, Aspect, zNear, zFar) {
- var Sine = 0.0;
- var Cotangent = 0.0;
- var ZDelta = 0.0;
- var Radians = 0.0;
- Radians = (fovy * 0.5) * 0.017453292519944444;
- ZDelta = zFar - zNear;
- Sine = Math.sin(Radians);
- if (!(((ZDelta === 0) || (Sine === 0)) || (Aspect === 0))) {
- Cotangent = Math.cos(Radians) / Sine;
- this.RawComponents = $impl.Matrix4x4Identity.RawComponents.slice(0);
- this.RawComponents[0][0] = Cotangent / Aspect;
- this.RawComponents[1][1] = Cotangent;
- this.RawComponents[2][2] = -(zFar + zNear) / ZDelta;
- this.RawComponents[2][3] = -1 - 0;
- this.RawComponents[3][2] = -((2.0 * zNear) * zFar) / ZDelta;
- this.RawComponents[3][3] = 0.0;
- };
- };
- this.Multiply = function (m) {
- var Result = null;
- Result = $mod.TMat4.$create("Identity");
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- 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]);
- return Result;
- };
- this.CopyList = function () {
- var Result = [];
- var x = 0;
- var y = 0;
- var list = null;
- list = new Array();
- for (x = 0; x <= 3; x++) for (y = 0; y <= 3; y++) list.push(this.RawComponents[x][y]);
- Result = list;
- return Result;
- };
- this.Show = function () {
- var x = 0;
- var y = 0;
- for (y = 0; y <= 3; y++) {
- pas.System.Write("[");
- for (x = 0; x <= 3; x++) {
- if (x < 3) {
- pas.System.Write(this.RawComponents[x][y],",")}
- else pas.System.Write(this.RawComponents[x][y]);
- };
- pas.System.Write("]");
- };
- };
- });
- this.SinCos = function (angle, sinus, cosinus) {
- sinus.set(Math.sin(angle));
- cosinus.set(Math.cos(angle));
- };
- $mod.$init = function () {
- $impl.Matrix4x4Identity = $mod.TMat4.$create("Identity");
- };
- },null,function () {
- "use strict";
- var $mod = this;
- var $impl = $mod.$impl;
- $impl.PI = 3.14159265359;
- $impl.DEG2RAD = 3.14159265359 / 180.0;
- $impl.Matrix4x4Identity = null;
- });
|