cDynArrays.pas 300 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184
  1. {******************************************************************************}
  2. { }
  3. { Library: Fundamentals 4.00 }
  4. { File name: cDynArrays.pas }
  5. { File version: 4.26 }
  6. { Description: Utility functions for dynamic arrays }
  7. { }
  8. { Copyright: Copyright (c) 2000-2012, David J Butler }
  9. { All rights reserved. }
  10. { Redistribution and use in source and binary forms, with }
  11. { or without modification, are permitted provided that }
  12. { the following conditions are met: }
  13. { Redistributions of source code must retain the above }
  14. { copyright notice, this list of conditions and the }
  15. { following disclaimer. }
  16. { THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND }
  17. { CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED }
  18. { WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED }
  19. { WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A }
  20. { PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL }
  21. { THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, }
  22. { INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR }
  23. { CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, }
  24. { PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF }
  25. { USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) }
  26. { HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER }
  27. { IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING }
  28. { NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE }
  29. { USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE }
  30. { POSSIBILITY OF SUCH DAMAGE. }
  31. { }
  32. { Home page: http://fundementals.sourceforge.net }
  33. { Forum: http://sourceforge.net/forum/forum.php?forum_id=2117 }
  34. { E-mail: fundamentalslib at gmail.com }
  35. { }
  36. { Revision history: }
  37. { }
  38. { 2000/03/08 1.01 Initial verison: array functions. }
  39. { 2000/04/10 1.02 Added Append, Renamed Delete to Remove and added }
  40. { StringArrays. }
  41. { 2000/06/01 1.03 Added Range and Dup constructors for dynamic arrays. }
  42. { 2000/06/03 1.04 Added ArrayInsert functions. }
  43. { 2000/06/14 1.05 Unit now generated from a template using a source }
  44. { pre-processor. }
  45. { 2000/07/04 1.06 Revision for first Fundamentals release. }
  46. { 2000/07/24 1.07 Added TrimArray functions. }
  47. { 2000/07/26 1.08 Added Difference functions. }
  48. { 2000/09/02 1.09 Added RemoveDuplicates functions. }
  49. { Added Count functions. }
  50. { Fixed bug in Sort. }
  51. { 2000/09/27 1.10 Fixed bug in ArrayInsert. }
  52. { 2001/11/11 2.11 Revision. }
  53. { 2002/05/31 3.12 Refactored for Fundamentals 3. }
  54. { 2003/09/11 3.13 Added InterfaceArray functions. }
  55. { 2004/01/18 3.14 Added WideStringArray functions. }
  56. { 2004/07/24 3.15 Optimizations of Sort functions. }
  57. { 2004/08/22 3.16 Compilable with Delphi 8. }
  58. { 2005/06/10 4.17 Compilable with FreePascal 2 Win32 i386. }
  59. { 2005/08/19 4.18 Compilable with FreePascal 2 Linux i386. }
  60. { 2005/09/21 4.19 Revised for Fundamentals 4. }
  61. { 2006/03/04 4.20 Compilable with Delphi 2006 Win32/.NET. }
  62. { 2007/06/08 4.21 Compilable with FreePascal 2.04 Win32 i386 }
  63. { 2009/10/09 4.22 Compilable with Delphi 2009 Win32/.NET. }
  64. { 2010/06/27 4.23 Compilable with FreePascal 2.4.0 OSX x86-64. }
  65. { 2011/04/03 4.24 Support for Delphi XE string and integer types. }
  66. { 2011/04/04 4.25 Split dynamic array functions from Utils unit. }
  67. { 2012/08/26 4.26 UnicodeString functions. }
  68. { }
  69. {******************************************************************************}
  70. {$INCLUDE cDefines.inc}
  71. {$IFDEF FREEPASCAL}
  72. {$WARNINGS OFF}
  73. {$HINTS OFF}
  74. {$ENDIF}
  75. {$IFDEF DEBUG}
  76. {$IFDEF SELFTEST}
  77. {$DEFINE DYNARRAYS_SELFTEST}
  78. {$ENDIF}
  79. {$ENDIF}
  80. unit cDynArrays;
  81. interface
  82. uses
  83. { System }
  84. SysUtils,
  85. { Fundamentals }
  86. cUtils;
  87. { }
  88. { Dynamic arrays }
  89. { }
  90. function DynArrayAppend(var V: ByteArray; const R: Byte): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  91. function DynArrayAppend(var V: WordArray; const R: Word): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  92. function DynArrayAppend(var V: LongWordArray; const R: LongWord): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  93. function DynArrayAppend(var V: NativeUIntArray; const R: NativeUInt): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  94. function DynArrayAppend(var V: ShortIntArray; const R: ShortInt): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  95. function DynArrayAppend(var V: SmallIntArray; const R: SmallInt): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  96. function DynArrayAppend(var V: LongIntArray; const R: LongInt): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  97. function DynArrayAppend(var V: Int64Array; const R: Int64): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  98. function DynArrayAppend(var V: NativeIntArray; const R: NativeInt): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  99. function DynArrayAppend(var V: SingleArray; const R: Single): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  100. function DynArrayAppend(var V: DoubleArray; const R: Double): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  101. function DynArrayAppend(var V: ExtendedArray; const R: Extended): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  102. function DynArrayAppend(var V: CurrencyArray; const R: Currency): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  103. function DynArrayAppend(var V: BooleanArray; const R: Boolean): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  104. function DynArrayAppendA(var V: AnsiStringArray; const R: AnsiString): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  105. function DynArrayAppendW(var V: WideStringArray; const R: WideString): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  106. function DynArrayAppendU(var V: UnicodeStringArray; const R: UnicodeString): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  107. function DynArrayAppend(var V: StringArray; const R: String): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  108. {$IFNDEF ManagedCode}
  109. function DynArrayAppend(var V: PointerArray; const R: Pointer): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  110. {$ENDIF}
  111. function DynArrayAppend(var V: ObjectArray; const R: TObject): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  112. function DynArrayAppend(var V: InterfaceArray; const R: IInterface): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  113. function DynArrayAppend(var V: ByteSetArray; const R: ByteSet): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  114. function DynArrayAppend(var V: CharSetArray; const R: CharSet): Integer; overload; {$IFDEF UseInline}inline;{$ENDIF}
  115. function DynArrayAppendByteArray(var V: ByteArray; const R: array of Byte): Integer; overload;
  116. function DynArrayAppendWordArray(var V: WordArray; const R: array of Word): Integer; overload;
  117. function DynArrayAppendCardinalArray(var V: CardinalArray; const R: array of LongWord): Integer; overload;
  118. function DynArrayAppendNativeUIntArray(var V: NativeUIntArray; const R: array of NativeUInt): Integer; overload;
  119. function DynArrayAppendShortIntArray(var V: ShortIntArray; const R: array of ShortInt): Integer; overload;
  120. function DynArrayAppendSmallIntArray(var V: SmallIntArray; const R: array of SmallInt): Integer; overload;
  121. function DynArrayAppendIntegerArray(var V: IntegerArray; const R: array of LongInt): Integer; overload;
  122. function DynArrayAppendInt64Array(var V: Int64Array; const R: array of Int64): Integer; overload;
  123. function DynArrayAppendNativeIntArray(var V: NativeIntArray; const R: array of NativeInt): Integer; overload;
  124. function DynArrayAppendSingleArray(var V: SingleArray; const R: array of Single): Integer; overload;
  125. function DynArrayAppendDoubleArray(var V: DoubleArray; const R: array of Double): Integer; overload;
  126. function DynArrayAppendExtendedArray(var V: ExtendedArray; const R: array of Extended): Integer; overload;
  127. function DynArrayAppendAnsiStringArray(var V: AnsiStringArray; const R: array of AnsiString): Integer; overload;
  128. function DynArrayAppendWideStringArray(var V: WideStringArray; const R: array of WideString): Integer; overload;
  129. function DynArrayAppendUnicodeStringArray(var V: UnicodeStringArray; const R: array of UnicodeString): Integer; overload;
  130. function DynArrayAppendStringArray(var V: StringArray; const R: array of String): Integer; overload;
  131. {$IFNDEF CLR}
  132. function DynArrayAppendCurrencyArray(var V: CurrencyArray; const R: array of Currency): Integer; overload;
  133. function DynArrayAppendPointerArray(var V: PointerArray; const R: array of Pointer): Integer; overload;
  134. function DynArrayAppendCharSetArray(var V: CharSetArray; const R: array of CharSet): Integer; overload;
  135. function DynArrayAppendByteSetArray(var V: ByteSetArray; const R: array of ByteSet): Integer; overload;
  136. {$ENDIF}
  137. function DynArrayAppendObjectArray(var V: ObjectArray; const R: ObjectArray): Integer; overload;
  138. function DynArrayRemove(var V: ByteArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  139. function DynArrayRemove(var V: WordArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  140. function DynArrayRemove(var V: LongWordArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  141. function DynArrayRemove(var V: NativeUIntArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  142. function DynArrayRemove(var V: ShortIntArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  143. function DynArrayRemove(var V: SmallIntArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  144. function DynArrayRemove(var V: LongIntArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  145. function DynArrayRemove(var V: Int64Array; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  146. function DynArrayRemove(var V: NativeIntArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  147. function DynArrayRemove(var V: SingleArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  148. function DynArrayRemove(var V: DoubleArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  149. function DynArrayRemove(var V: ExtendedArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  150. function DynArrayRemoveA(var V: AnsiStringArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  151. function DynArrayRemoveW(var V: WideStringArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  152. function DynArrayRemoveU(var V: UnicodeStringArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  153. function DynArrayRemove(var V: StringArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  154. {$IFNDEF ManagedCode}
  155. function DynArrayRemove(var V: PointerArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  156. {$ENDIF}
  157. {$IFNDEF CLR}
  158. function DynArrayRemove(var V: CurrencyArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  159. {$ENDIF}
  160. function DynArrayRemove(var V: ObjectArray; const Idx: Integer; const Count: Integer = 1;
  161. const FreeObjects: Boolean = False): Integer; overload;
  162. function DynArrayRemove(var V: InterfaceArray; const Idx: Integer; const Count: Integer = 1): Integer; overload;
  163. procedure DynArrayRemoveDuplicates(var V: ByteArray; const IsSorted: Boolean); overload;
  164. procedure DynArrayRemoveDuplicates(var V: WordArray; const IsSorted: Boolean); overload;
  165. procedure DynArrayRemoveDuplicates(var V: LongWordArray; const IsSorted: Boolean); overload;
  166. procedure DynArrayRemoveDuplicates(var V: ShortIntArray; const IsSorted: Boolean); overload;
  167. procedure DynArrayRemoveDuplicates(var V: SmallIntArray; const IsSorted: Boolean); overload;
  168. procedure DynArrayRemoveDuplicates(var V: LongIntArray; const IsSorted: Boolean); overload;
  169. procedure DynArrayRemoveDuplicates(var V: Int64Array; const IsSorted: Boolean); overload;
  170. procedure DynArrayRemoveDuplicates(var V: SingleArray; const IsSorted: Boolean); overload;
  171. procedure DynArrayRemoveDuplicates(var V: DoubleArray; const IsSorted: Boolean); overload;
  172. procedure DynArrayRemoveDuplicates(var V: ExtendedArray; const IsSorted: Boolean); overload;
  173. procedure DynArrayRemoveDuplicatesA(var V: AnsiStringArray; const IsSorted: Boolean); overload;
  174. procedure DynArrayRemoveDuplicatesW(var V: WideStringArray; const IsSorted: Boolean); overload;
  175. procedure DynArrayRemoveDuplicatesU(var V: UnicodeStringArray; const IsSorted: Boolean); overload;
  176. procedure DynArrayRemoveDuplicates(var V: StringArray; const IsSorted: Boolean); overload;
  177. {$IFNDEF ManagedCode}
  178. procedure DynArrayRemoveDuplicates(var V: PointerArray; const IsSorted: Boolean); overload;
  179. {$ENDIF}
  180. procedure DynArrayTrimLeft(var S: ByteArray; const TrimList: array of Byte); overload;
  181. procedure DynArrayTrimLeft(var S: WordArray; const TrimList: array of Word); overload;
  182. procedure DynArrayTrimLeft(var S: LongWordArray; const TrimList: array of LongWord); overload;
  183. procedure DynArrayTrimLeft(var S: ShortIntArray; const TrimList: array of ShortInt); overload;
  184. procedure DynArrayTrimLeft(var S: SmallIntArray; const TrimList: array of SmallInt); overload;
  185. procedure DynArrayTrimLeft(var S: LongIntArray; const TrimList: array of LongInt); overload;
  186. procedure DynArrayTrimLeft(var S: Int64Array; const TrimList: array of Int64); overload;
  187. procedure DynArrayTrimLeft(var S: SingleArray; const TrimList: array of Single); overload;
  188. procedure DynArrayTrimLeft(var S: DoubleArray; const TrimList: array of Double); overload;
  189. procedure DynArrayTrimLeft(var S: ExtendedArray; const TrimList: array of Extended); overload;
  190. procedure DynArrayTrimLeftA(var S: AnsiStringArray; const TrimList: array of AnsiString); overload;
  191. procedure DynArrayTrimLeftW(var S: WideStringArray; const TrimList: array of WideString); overload;
  192. procedure DynArrayTrimLeftU(var S: UnicodeStringArray; const TrimList: array of UnicodeString); overload;
  193. {$IFNDEF ManagedCode}
  194. procedure DynArrayTrimLeft(var S: PointerArray; const TrimList: array of Pointer); overload;
  195. {$ENDIF}
  196. procedure DynArrayTrimRight(var S: ByteArray; const TrimList: array of Byte); overload;
  197. procedure DynArrayTrimRight(var S: WordArray; const TrimList: array of Word); overload;
  198. procedure DynArrayTrimRight(var S: LongWordArray; const TrimList: array of LongWord); overload;
  199. procedure DynArrayTrimRight(var S: ShortIntArray; const TrimList: array of ShortInt); overload;
  200. procedure DynArrayTrimRight(var S: SmallIntArray; const TrimList: array of SmallInt); overload;
  201. procedure DynArrayTrimRight(var S: LongIntArray; const TrimList: array of LongInt); overload;
  202. procedure DynArrayTrimRight(var S: Int64Array; const TrimList: array of Int64); overload;
  203. procedure DynArrayTrimRight(var S: SingleArray; const TrimList: array of Single); overload;
  204. procedure DynArrayTrimRight(var S: DoubleArray; const TrimList: array of Double); overload;
  205. procedure DynArrayTrimRight(var S: ExtendedArray; const TrimList: array of Extended); overload;
  206. procedure DynArrayTrimRightA(var S: AnsiStringArray; const TrimList: array of AnsiString); overload;
  207. procedure DynArrayTrimRightW(var S: WideStringArray; const TrimList: array of WideString); overload;
  208. procedure DynArrayTrimRightU(var S: UnicodeStringArray; const TrimList: array of UnicodeString); overload;
  209. procedure DynArrayTrimRight(var S: StringArray; const TrimList: array of String); overload;
  210. {$IFNDEF ManagedCode}
  211. procedure DynArrayTrimRight(var S: PointerArray; const TrimList: array of Pointer); overload;
  212. {$ENDIF}
  213. function DynArrayInsert(var V: ByteArray; const Idx: Integer; const Count: Integer): Integer; overload;
  214. function DynArrayInsert(var V: WordArray; const Idx: Integer; const Count: Integer): Integer; overload;
  215. function DynArrayInsert(var V: LongWordArray; const Idx: Integer; const Count: Integer): Integer; overload;
  216. function DynArrayInsert(var V: NativeUIntArray; const Idx: Integer; const Count: Integer): Integer; overload;
  217. function DynArrayInsert(var V: ShortIntArray; const Idx: Integer; const Count: Integer): Integer; overload;
  218. function DynArrayInsert(var V: SmallIntArray; const Idx: Integer; const Count: Integer): Integer; overload;
  219. function DynArrayInsert(var V: LongIntArray; const Idx: Integer; const Count: Integer): Integer; overload;
  220. function DynArrayInsert(var V: Int64Array; const Idx: Integer; const Count: Integer): Integer; overload;
  221. function DynArrayInsert(var V: NativeIntArray; const Idx: Integer; const Count: Integer): Integer; overload;
  222. function DynArrayInsert(var V: SingleArray; const Idx: Integer; const Count: Integer): Integer; overload;
  223. function DynArrayInsert(var V: DoubleArray; const Idx: Integer; const Count: Integer): Integer; overload;
  224. function DynArrayInsert(var V: ExtendedArray; const Idx: Integer; const Count: Integer): Integer; overload;
  225. function DynArrayInsert(var V: CurrencyArray; const Idx: Integer; const Count: Integer): Integer; overload;
  226. function DynArrayInsertA(var V: AnsiStringArray; const Idx: Integer; const Count: Integer): Integer; overload;
  227. function DynArrayInsertW(var V: WideStringArray; const Idx: Integer; const Count: Integer): Integer; overload;
  228. function DynArrayInsertU(var V: UnicodeStringArray; const Idx: Integer; const Count: Integer): Integer; overload;
  229. function DynArrayInsert(var V: StringArray; const Idx: Integer; const Count: Integer): Integer; overload;
  230. {$IFNDEF ManagedCode}
  231. function DynArrayInsert(var V: PointerArray; const Idx: Integer; const Count: Integer): Integer; overload;
  232. function DynArrayInsert(var V: ObjectArray; const Idx: Integer; const Count: Integer): Integer; overload;
  233. {$ENDIF}
  234. function DynArrayInsert(var V: InterfaceArray; const Idx: Integer; const Count: Integer): Integer; overload;
  235. function DynArrayPosNext(const Find: Byte; const V: ByteArray; const PrevPos: Integer = -1;
  236. const IsSortedAscending: Boolean = False): Integer; overload;
  237. function DynArrayPosNext(const Find: Word; const V: WordArray; const PrevPos: Integer = -1;
  238. const IsSortedAscending: Boolean = False): Integer; overload;
  239. function DynArrayPosNext(const Find: LongWord; const V: LongWordArray; const PrevPos: Integer = -1;
  240. const IsSortedAscending: Boolean = False): Integer; overload;
  241. function DynArrayPosNext(const Find: NativeUInt; const V: NativeUIntArray; const PrevPos: Integer = -1;
  242. const IsSortedAscending: Boolean = False): Integer; overload;
  243. function DynArrayPosNext(const Find: ShortInt; const V: ShortIntArray; const PrevPos: Integer = -1;
  244. const IsSortedAscending: Boolean = False): Integer; overload;
  245. function DynArrayPosNext(const Find: SmallInt; const V: SmallIntArray; const PrevPos: Integer = -1;
  246. const IsSortedAscending: Boolean = False): Integer; overload;
  247. function DynArrayPosNext(const Find: LongInt; const V: LongIntArray; const PrevPos: Integer = -1;
  248. const IsSortedAscending: Boolean = False): Integer; overload;
  249. function DynArrayPosNext(const Find: Int64; const V: Int64Array; const PrevPos: Integer = -1;
  250. const IsSortedAscending: Boolean = False): Integer; overload;
  251. function DynArrayPosNext(const Find: NativeInt; const V: NativeIntArray; const PrevPos: Integer = -1;
  252. const IsSortedAscending: Boolean = False): Integer; overload;
  253. function DynArrayPosNext(const Find: Single; const V: SingleArray; const PrevPos: Integer = -1;
  254. const IsSortedAscending: Boolean = False): Integer; overload;
  255. function DynArrayPosNext(const Find: Double; const V: DoubleArray; const PrevPos: Integer = -1;
  256. const IsSortedAscending: Boolean = False): Integer; overload;
  257. function DynArrayPosNext(const Find: Extended; const V: ExtendedArray; const PrevPos: Integer = -1;
  258. const IsSortedAscending: Boolean = False): Integer; overload;
  259. function DynArrayPosNext(const Find: Boolean; const V: BooleanArray; const PrevPos: Integer = -1;
  260. const IsSortedAscending: Boolean = False): Integer; overload;
  261. function DynArrayPosNextA(const Find: AnsiString; const V: AnsiStringArray; const PrevPos: Integer = -1;
  262. const IsSortedAscending: Boolean = False): Integer; overload;
  263. function DynArrayPosNextW(const Find: WideString; const V: WideStringArray; const PrevPos: Integer = -1;
  264. const IsSortedAscending: Boolean = False): Integer; overload;
  265. function DynArrayPosNextU(const Find: UnicodeString; const V: UnicodeStringArray; const PrevPos: Integer = -1;
  266. const IsSortedAscending: Boolean = False): Integer; overload;
  267. function DynArrayPosNext(const Find: String; const V: StringArray; const PrevPos: Integer = -1;
  268. const IsSortedAscending: Boolean = False): Integer; overload;
  269. {$IFNDEF ManagedCode}
  270. function DynArrayPosNext(const Find: Pointer; const V: PointerArray;
  271. const PrevPos: Integer = -1): Integer; overload;
  272. {$ENDIF}
  273. function DynArrayPosNext(const Find: TObject; const V: ObjectArray;
  274. const PrevPos: Integer = -1): Integer; overload;
  275. function DynArrayPosNext(const ClassType: TClass; const V: ObjectArray;
  276. const PrevPos: Integer = -1): Integer; overload;
  277. function DynArrayPosNext(const ClassName: String; const V: ObjectArray;
  278. const PrevPos: Integer = -1): Integer; overload;
  279. function DynArrayCount(const Find: Byte; const V: ByteArray;
  280. const IsSortedAscending: Boolean = False): Integer; overload;
  281. function DynArrayCount(const Find: Word; const V: WordArray;
  282. const IsSortedAscending: Boolean = False): Integer; overload;
  283. function DynArrayCount(const Find: LongWord; const V: LongWordArray;
  284. const IsSortedAscending: Boolean = False): Integer; overload;
  285. function DynArrayCount(const Find: ShortInt; const V: ShortIntArray;
  286. const IsSortedAscending: Boolean = False): Integer; overload;
  287. function DynArrayCount(const Find: SmallInt; const V: SmallIntArray;
  288. const IsSortedAscending: Boolean = False): Integer; overload;
  289. function DynArrayCount(const Find: LongInt; const V: LongIntArray;
  290. const IsSortedAscending: Boolean = False): Integer; overload;
  291. function DynArrayCount(const Find: Int64; const V: Int64Array;
  292. const IsSortedAscending: Boolean = False): Integer; overload;
  293. function DynArrayCount(const Find: Single; const V: SingleArray;
  294. const IsSortedAscending: Boolean = False): Integer; overload;
  295. function DynArrayCount(const Find: Double; const V: DoubleArray;
  296. const IsSortedAscending: Boolean = False): Integer; overload;
  297. function DynArrayCount(const Find: Extended; const V: ExtendedArray;
  298. const IsSortedAscending: Boolean = False): Integer; overload;
  299. function DynArrayCountA(const Find: AnsiString; const V: AnsiStringArray;
  300. const IsSortedAscending: Boolean = False): Integer; overload;
  301. function DynArrayCountW(const Find: WideString; const V: WideStringArray;
  302. const IsSortedAscending: Boolean = False): Integer; overload;
  303. function DynArrayCountU(const Find: UnicodeString; const V: UnicodeStringArray;
  304. const IsSortedAscending: Boolean = False): Integer; overload;
  305. function DynArrayCount(const Find: String; const V: StringArray;
  306. const IsSortedAscending: Boolean = False): Integer; overload;
  307. function DynArrayCount(const Find: Boolean; const V: BooleanArray;
  308. const IsSortedAscending: Boolean = False): Integer; overload;
  309. procedure DynArrayRemoveAll(const Find: Byte; var V: ByteArray;
  310. const IsSortedAscending: Boolean = False); overload;
  311. procedure DynArrayRemoveAll(const Find: Word; var V: WordArray;
  312. const IsSortedAscending: Boolean = False); overload;
  313. procedure DynArrayRemoveAll(const Find: LongWord; var V: LongWordArray;
  314. const IsSortedAscending: Boolean = False); overload;
  315. procedure DynArrayRemoveAll(const Find: ShortInt; var V: ShortIntArray;
  316. const IsSortedAscending: Boolean = False); overload;
  317. procedure DynArrayRemoveAll(const Find: SmallInt; var V: SmallIntArray;
  318. const IsSortedAscending: Boolean = False); overload;
  319. procedure DynArrayRemoveAll(const Find: LongInt; var V: LongIntArray;
  320. const IsSortedAscending: Boolean = False); overload;
  321. procedure DynArrayRemoveAll(const Find: Int64; var V: Int64Array;
  322. const IsSortedAscending: Boolean = False); overload;
  323. procedure DynArrayRemoveAll(const Find: Single; var V: SingleArray;
  324. const IsSortedAscending: Boolean = False); overload;
  325. procedure DynArrayRemoveAll(const Find: Double; var V: DoubleArray;
  326. const IsSortedAscending: Boolean = False); overload;
  327. procedure DynArrayRemoveAll(const Find: Extended; var V: ExtendedArray;
  328. const IsSortedAscending: Boolean = False); overload;
  329. procedure DynArrayRemoveAllA(const Find: AnsiString; var V: AnsiStringArray;
  330. const IsSortedAscending: Boolean = False); overload;
  331. procedure DynArrayRemoveAllW(const Find: WideString; var V: WideStringArray;
  332. const IsSortedAscending: Boolean = False); overload;
  333. procedure DynArrayRemoveAllU(const Find: UnicodeString; var V: UnicodeStringArray;
  334. const IsSortedAscending: Boolean = False); overload;
  335. procedure DynArrayRemoveAll(const Find: String; var V: StringArray;
  336. const IsSortedAscending: Boolean = False); overload;
  337. function DynArrayIntersection(const V1, V2: ByteArray;
  338. const IsSortedAscending: Boolean = False): ByteArray; overload;
  339. function DynArrayIntersection(const V1, V2: WordArray;
  340. const IsSortedAscending: Boolean = False): WordArray; overload;
  341. function DynArrayIntersection(const V1, V2: LongWordArray;
  342. const IsSortedAscending: Boolean = False): LongWordArray; overload;
  343. function DynArrayIntersection(const V1, V2: ShortIntArray;
  344. const IsSortedAscending: Boolean = False): ShortIntArray; overload;
  345. function DynArrayIntersection(const V1, V2: SmallIntArray;
  346. const IsSortedAscending: Boolean = False): SmallIntArray; overload;
  347. function DynArrayIntersection(const V1, V2: LongIntArray;
  348. const IsSortedAscending: Boolean = False): LongIntArray; overload;
  349. function DynArrayIntersection(const V1, V2: Int64Array;
  350. const IsSortedAscending: Boolean = False): Int64Array; overload;
  351. function DynArrayIntersection(const V1, V2: SingleArray;
  352. const IsSortedAscending: Boolean = False): SingleArray; overload;
  353. function DynArrayIntersection(const V1, V2: DoubleArray;
  354. const IsSortedAscending: Boolean = False): DoubleArray; overload;
  355. function DynArrayIntersection(const V1, V2: ExtendedArray;
  356. const IsSortedAscending: Boolean = False): ExtendedArray; overload;
  357. function DynArrayIntersectionA(const V1, V2: AnsiStringArray;
  358. const IsSortedAscending: Boolean = False): AnsiStringArray; overload;
  359. function DynArrayIntersectionW(const V1, V2: WideStringArray;
  360. const IsSortedAscending: Boolean = False): WideStringArray; overload;
  361. function DynArrayIntersectionU(const V1, V2: UnicodeStringArray;
  362. const IsSortedAscending: Boolean = False): UnicodeStringArray; overload;
  363. function DynArrayIntersection(const V1, V2: StringArray;
  364. const IsSortedAscending: Boolean = False): StringArray; overload;
  365. function DynArrayDifference(const V1, V2: ByteArray;
  366. const IsSortedAscending: Boolean = False): ByteArray; overload;
  367. function DynArrayDifference(const V1, V2: WordArray;
  368. const IsSortedAscending: Boolean = False): WordArray; overload;
  369. function DynArrayDifference(const V1, V2: LongWordArray;
  370. const IsSortedAscending: Boolean = False): LongWordArray; overload;
  371. function DynArrayDifference(const V1, V2: ShortIntArray;
  372. const IsSortedAscending: Boolean = False): ShortIntArray; overload;
  373. function DynArrayDifference(const V1, V2: SmallIntArray;
  374. const IsSortedAscending: Boolean = False): SmallIntArray; overload;
  375. function DynArrayDifference(const V1, V2: LongIntArray;
  376. const IsSortedAscending: Boolean = False): LongIntArray; overload;
  377. function DynArrayDifference(const V1, V2: Int64Array;
  378. const IsSortedAscending: Boolean = False): Int64Array; overload;
  379. function DynArrayDifference(const V1, V2: SingleArray;
  380. const IsSortedAscending: Boolean = False): SingleArray; overload;
  381. function DynArrayDifference(const V1, V2: DoubleArray;
  382. const IsSortedAscending: Boolean = False): DoubleArray; overload;
  383. function DynArrayDifference(const V1, V2: ExtendedArray;
  384. const IsSortedAscending: Boolean = False): ExtendedArray; overload;
  385. function DynArrayDifferenceA(const V1, V2: AnsiStringArray;
  386. const IsSortedAscending: Boolean = False): AnsiStringArray; overload;
  387. function DynArrayDifferenceW(const V1, V2: WideStringArray;
  388. const IsSortedAscending: Boolean = False): WideStringArray; overload;
  389. function DynArrayDifferenceU(const V1, V2: UnicodeStringArray;
  390. const IsSortedAscending: Boolean = False): UnicodeStringArray; overload;
  391. function DynArrayDifference(const V1, V2: StringArray;
  392. const IsSortedAscending: Boolean = False): StringArray; overload;
  393. procedure DynArrayReverse(var V: ByteArray); overload;
  394. procedure DynArrayReverse(var V: WordArray); overload;
  395. procedure DynArrayReverse(var V: LongWordArray); overload;
  396. procedure DynArrayReverse(var V: ShortIntArray); overload;
  397. procedure DynArrayReverse(var V: SmallIntArray); overload;
  398. procedure DynArrayReverse(var V: LongIntArray); overload;
  399. procedure DynArrayReverse(var V: Int64Array); overload;
  400. procedure DynArrayReverse(var V: SingleArray); overload;
  401. procedure DynArrayReverse(var V: DoubleArray); overload;
  402. procedure DynArrayReverse(var V: ExtendedArray); overload;
  403. procedure DynArrayReverseA(var V: AnsiStringArray); overload;
  404. procedure DynArrayReverseW(var V: WideStringArray); overload;
  405. procedure DynArrayReverseU(var V: UnicodeStringArray); overload;
  406. procedure DynArrayReverse(var V: StringArray); overload;
  407. {$IFNDEF ManagedCode}
  408. procedure DynArrayReverse(var V: PointerArray); overload;
  409. {$ENDIF}
  410. procedure DynArrayReverse(var V: ObjectArray); overload;
  411. function AsBooleanArray(const V: array of Boolean): BooleanArray; overload;
  412. function AsByteArray(const V: array of Byte): ByteArray; overload;
  413. function AsWordArray(const V: array of Word): WordArray; overload;
  414. function AsLongWordArray(const V: array of LongWord): LongWordArray; overload;
  415. function AsCardinalArray(const V: array of Cardinal): CardinalArray; overload;
  416. function AsNativeUIntArray(const V: array of NativeUInt): NativeUIntArray; overload;
  417. function AsShortIntArray(const V: array of ShortInt): ShortIntArray; overload;
  418. function AsSmallIntArray(const V: array of SmallInt): SmallIntArray; overload;
  419. function AsLongIntArray(const V: array of LongInt): LongIntArray; overload;
  420. function AsIntegerArray(const V: array of Integer): IntegerArray; overload;
  421. function AsInt64Array(const V: array of Int64): Int64Array; overload;
  422. function AsNativeIntArray(const V: array of NativeInt): NativeIntArray; overload;
  423. function AsSingleArray(const V: array of Single): SingleArray; overload;
  424. function AsDoubleArray(const V: array of Double): DoubleArray; overload;
  425. function AsExtendedArray(const V: array of Extended): ExtendedArray; overload;
  426. function AsCurrencyArray(const V: array of Currency): CurrencyArray; overload;
  427. function AsAnsiStringArray(const V: array of AnsiString): AnsiStringArray; overload;
  428. function AsWideStringArray(const V: array of WideString): WideStringArray; overload;
  429. function AsUnicodeStringArray(const V: array of UnicodeString): UnicodeStringArray; overload;
  430. function AsStringArray(const V: array of String): StringArray; overload;
  431. {$IFNDEF ManagedCode}
  432. function AsPointerArray(const V: array of Pointer): PointerArray; overload;
  433. {$ENDIF}
  434. function AsCharSetArray(const V: array of CharSet): CharSetArray; overload;
  435. function AsObjectArray(const V: array of TObject): ObjectArray; overload;
  436. function AsInterfaceArray(const V: array of IInterface): InterfaceArray; overload;
  437. function DynArrayRangeByte(const First: Byte; const Count: Integer;
  438. const Increment: Byte = 1): ByteArray;
  439. function DynArrayRangeWord(const First: Word; const Count: Integer;
  440. const Increment: Word = 1): WordArray;
  441. function DynArrayRangeLongWord(const First: LongWord; const Count: Integer;
  442. const Increment: LongWord = 1): LongWordArray;
  443. function DynArrayRangeCardinal(const First: Cardinal; const Count: Integer;
  444. const Increment: Cardinal = 1): CardinalArray;
  445. function DynArrayRangeShortInt(const First: ShortInt; const Count: Integer;
  446. const Increment: ShortInt = 1): ShortIntArray;
  447. function DynArrayRangeSmallInt(const First: SmallInt; const Count: Integer;
  448. const Increment: SmallInt = 1): SmallIntArray;
  449. function DynArrayRangeLongInt(const First: LongInt; const Count: Integer;
  450. const Increment: LongInt = 1): LongIntArray;
  451. function DynArrayRangeInteger(const First: Integer; const Count: Integer;
  452. const Increment: Integer = 1): IntegerArray;
  453. function DynArrayRangeInt64(const First: Int64; const Count: Integer;
  454. const Increment: Int64 = 1): Int64Array;
  455. function DynArrayRangeSingle(const First: Single; const Count: Integer;
  456. const Increment: Single = 1): SingleArray;
  457. function DynArrayRangeDouble(const First: Double; const Count: Integer;
  458. const Increment: Double = 1): DoubleArray;
  459. function DynArrayRangeExtended(const First: Extended; const Count: Integer;
  460. const Increment: Extended = 1): ExtendedArray;
  461. function DynArrayDupByte(const V: Byte; const Count: Integer): ByteArray;
  462. function DynArrayDupWord(const V: Word; const Count: Integer): WordArray;
  463. function DynArrayDupLongWord(const V: LongWord; const Count: Integer): LongWordArray;
  464. function DynArrayDupCardinal(const V: Cardinal; const Count: Integer): CardinalArray;
  465. function DynArrayDupNativeUInt(const V: NativeUInt; const Count: Integer): NativeUIntArray;
  466. function DynArrayDupShortInt(const V: ShortInt; const Count: Integer): ShortIntArray;
  467. function DynArrayDupSmallInt(const V: SmallInt; const Count: Integer): SmallIntArray;
  468. function DynArrayDupLongInt(const V: LongInt; const Count: Integer): LongIntArray;
  469. function DynArrayDupInteger(const V: Integer; const Count: Integer): IntegerArray;
  470. function DynArrayDupInt64(const V: Int64; const Count: Integer): Int64Array;
  471. function DynArrayDupNativeInt(const V: NativeInt; const Count: Integer): NativeIntArray;
  472. function DynArrayDupSingle(const V: Single; const Count: Integer): SingleArray;
  473. function DynArrayDupDouble(const V: Double; const Count: Integer): DoubleArray;
  474. function DynArrayDupExtended(const V: Extended; const Count: Integer): ExtendedArray;
  475. function DynArrayDupCurrency(const V: Currency; const Count: Integer): CurrencyArray;
  476. function DynArrayDupAnsiString(const V: AnsiString; const Count: Integer): AnsiStringArray;
  477. function DynArrayDupWideString(const V: WideString; const Count: Integer): WideStringArray;
  478. function DynArrayDupUnicodeString(const V: UnicodeString; const Count: Integer): UnicodeStringArray;
  479. function DynArrayDupString(const V: String; const Count: Integer): StringArray;
  480. function DynArrayDupCharSet(const V: CharSet; const Count: Integer): CharSetArray;
  481. function DynArrayDupObject(const V: TObject; const Count: Integer): ObjectArray;
  482. procedure SetLengthAndZero(var V: ByteArray; const NewLength: Integer); overload;
  483. procedure SetLengthAndZero(var V: WordArray; const NewLength: Integer); overload;
  484. procedure SetLengthAndZero(var V: LongWordArray; const NewLength: Integer); overload;
  485. procedure SetLengthAndZero(var V: NativeUIntArray; const NewLength: Integer); overload;
  486. procedure SetLengthAndZero(var V: ShortIntArray; const NewLength: Integer); overload;
  487. procedure SetLengthAndZero(var V: SmallIntArray; const NewLength: Integer); overload;
  488. procedure SetLengthAndZero(var V: LongIntArray; const NewLength: Integer); overload;
  489. procedure SetLengthAndZero(var V: Int64Array; const NewLength: Integer); overload;
  490. procedure SetLengthAndZero(var V: NativeIntArray; const NewLength: Integer); overload;
  491. procedure SetLengthAndZero(var V: SingleArray; const NewLength: Integer); overload;
  492. procedure SetLengthAndZero(var V: DoubleArray; const NewLength: Integer); overload;
  493. procedure SetLengthAndZero(var V: ExtendedArray; const NewLength: Integer); overload;
  494. procedure SetLengthAndZero(var V: CurrencyArray; const NewLength: Integer); overload;
  495. procedure SetLengthAndZero(var V: CharSetArray; const NewLength: Integer); overload;
  496. procedure SetLengthAndZero(var V: BooleanArray; const NewLength: Integer); overload;
  497. {$IFNDEF ManagedCode}
  498. procedure SetLengthAndZero(var V: PointerArray; const NewLength: Integer); overload;
  499. {$ENDIF}
  500. procedure SetLengthAndZero(var V: ObjectArray; const NewLength: Integer;
  501. const FreeObjects: Boolean = False); overload;
  502. function DynArrayIsEqual(const V1, V2: ByteArray): Boolean; overload;
  503. function DynArrayIsEqual(const V1, V2: WordArray): Boolean; overload;
  504. function DynArrayIsEqual(const V1, V2: LongWordArray): Boolean; overload;
  505. function DynArrayIsEqual(const V1, V2: ShortIntArray): Boolean; overload;
  506. function DynArrayIsEqual(const V1, V2: SmallIntArray): Boolean; overload;
  507. function DynArrayIsEqual(const V1, V2: LongIntArray): Boolean; overload;
  508. function DynArrayIsEqual(const V1, V2: Int64Array): Boolean; overload;
  509. function DynArrayIsEqual(const V1, V2: SingleArray): Boolean; overload;
  510. function DynArrayIsEqual(const V1, V2: DoubleArray): Boolean; overload;
  511. function DynArrayIsEqual(const V1, V2: ExtendedArray): Boolean; overload;
  512. function DynArrayIsEqual(const V1, V2: CurrencyArray): Boolean; overload;
  513. function DynArrayIsEqualA(const V1, V2: AnsiStringArray): Boolean; overload;
  514. function DynArrayIsEqualW(const V1, V2: WideStringArray): Boolean; overload;
  515. function DynArrayIsEqualU(const V1, V2: UnicodeStringArray): Boolean; overload;
  516. function DynArrayIsEqual(const V1, V2: StringArray): Boolean; overload;
  517. function DynArrayIsEqual(const V1, V2: CharSetArray): Boolean; overload;
  518. function ByteArrayToLongIntArray(const V: ByteArray): LongIntArray;
  519. function WordArrayToLongIntArray(const V: WordArray): LongIntArray;
  520. function ShortIntArrayToLongIntArray(const V: ShortIntArray): LongIntArray;
  521. function SmallIntArrayToLongIntArray(const V: SmallIntArray): LongIntArray;
  522. function LongIntArrayToInt64Array(const V: LongIntArray): Int64Array;
  523. function LongIntArrayToSingleArray(const V: LongIntArray): SingleArray;
  524. function LongIntArrayToDoubleArray(const V: LongIntArray): DoubleArray;
  525. function LongIntArrayToExtendedArray(const V: LongIntArray): ExtendedArray;
  526. function SingleArrayToDoubleArray(const V: SingleArray): DoubleArray;
  527. function SingleArrayToExtendedArray(const V: SingleArray): ExtendedArray;
  528. function SingleArrayToCurrencyArray(const V: SingleArray): CurrencyArray;
  529. function SingleArrayToLongIntArray(const V: SingleArray): LongIntArray;
  530. function SingleArrayToInt64Array(const V: SingleArray): Int64Array;
  531. function DoubleArrayToExtendedArray(const V: DoubleArray): ExtendedArray;
  532. function DoubleArrayToCurrencyArray(const V: DoubleArray): CurrencyArray;
  533. function DoubleArrayToLongIntArray(const V: DoubleArray): LongIntArray;
  534. function DoubleArrayToInt64Array(const V: DoubleArray): Int64Array;
  535. function ExtendedArrayToCurrencyArray(const V: ExtendedArray): CurrencyArray;
  536. function ExtendedArrayToLongIntArray(const V: ExtendedArray): LongIntArray;
  537. function ExtendedArrayToInt64Array(const V: ExtendedArray): Int64Array;
  538. function ByteArrayFromIndexes(const V: ByteArray;
  539. const Indexes: IntegerArray): ByteArray;
  540. function WordArrayFromIndexes(const V: WordArray;
  541. const Indexes: IntegerArray): WordArray;
  542. function LongWordArrayFromIndexes(const V: LongWordArray;
  543. const Indexes: IntegerArray): LongWordArray;
  544. function CardinalArrayFromIndexes(const V: CardinalArray;
  545. const Indexes: IntegerArray): CardinalArray;
  546. function ShortIntArrayFromIndexes(const V: ShortIntArray;
  547. const Indexes: IntegerArray): ShortIntArray;
  548. function SmallIntArrayFromIndexes(const V: SmallIntArray;
  549. const Indexes: IntegerArray): SmallIntArray;
  550. function LongIntArrayFromIndexes(const V: LongIntArray;
  551. const Indexes: IntegerArray): LongIntArray;
  552. function IntegerArrayFromIndexes(const V: IntegerArray;
  553. const Indexes: IntegerArray): IntegerArray;
  554. function Int64ArrayFromIndexes(const V: Int64Array;
  555. const Indexes: IntegerArray): Int64Array;
  556. function SingleArrayFromIndexes(const V: SingleArray;
  557. const Indexes: IntegerArray): SingleArray;
  558. function DoubleArrayFromIndexes(const V: DoubleArray;
  559. const Indexes: IntegerArray): DoubleArray;
  560. function ExtendedArrayFromIndexes(const V: ExtendedArray;
  561. const Indexes: IntegerArray): ExtendedArray;
  562. function StringArrayFromIndexes(const V: StringArray;
  563. const Indexes: IntegerArray): StringArray;
  564. procedure DynArraySort(const V: ByteArray); overload;
  565. procedure DynArraySort(const V: WordArray); overload;
  566. procedure DynArraySort(const V: LongWordArray); overload;
  567. procedure DynArraySort(const V: NativeUIntArray); overload;
  568. procedure DynArraySort(const V: ShortIntArray); overload;
  569. procedure DynArraySort(const V: SmallIntArray); overload;
  570. procedure DynArraySort(const V: LongIntArray); overload;
  571. procedure DynArraySort(const V: Int64Array); overload;
  572. procedure DynArraySort(const V: NativeIntArray); overload;
  573. procedure DynArraySort(const V: SingleArray); overload;
  574. procedure DynArraySort(const V: DoubleArray); overload;
  575. procedure DynArraySort(const V: ExtendedArray); overload;
  576. procedure DynArraySortA(const V: AnsiStringArray); overload;
  577. procedure DynArraySortW(const V: WideStringArray); overload;
  578. procedure DynArraySortU(const V: UnicodeStringArray); overload;
  579. procedure DynArraySort(const V: StringArray); overload;
  580. procedure DynArraySort(const Key: IntegerArray; const Data: IntegerArray); overload;
  581. procedure DynArraySort(const Key: IntegerArray; const Data: Int64Array); overload;
  582. procedure DynArraySort(const Key: IntegerArray; const Data: AnsiStringArray); overload;
  583. procedure DynArraySort(const Key: IntegerArray; const Data: ExtendedArray); overload;
  584. {$IFNDEF ManagedCode}
  585. procedure DynArraySort(const Key: IntegerArray; const Data: PointerArray); overload;
  586. {$ENDIF}
  587. procedure DynArraySort(const Key: AnsiStringArray; const Data: IntegerArray); overload;
  588. procedure DynArraySort(const Key: AnsiStringArray; const Data: Int64Array); overload;
  589. procedure DynArraySort(const Key: AnsiStringArray; const Data: AnsiStringArray); overload;
  590. procedure DynArraySort(const Key: AnsiStringArray; const Data: ExtendedArray); overload;
  591. {$IFNDEF ManagedCode}
  592. procedure DynArraySort(const Key: AnsiStringArray; const Data: PointerArray); overload;
  593. {$ENDIF}
  594. procedure DynArraySort(const Key: ExtendedArray; const Data: IntegerArray); overload;
  595. procedure DynArraySort(const Key: ExtendedArray; const Data: Int64Array); overload;
  596. procedure DynArraySort(const Key: ExtendedArray; const Data: AnsiStringArray); overload;
  597. procedure DynArraySort(const Key: ExtendedArray; const Data: ExtendedArray); overload;
  598. {$IFNDEF ManagedCode}
  599. procedure DynArraySort(const Key: ExtendedArray; const Data: PointerArray); overload;
  600. {$ENDIF}
  601. { }
  602. { Test cases }
  603. { }
  604. {$IFDEF DYNARRAYS_SELFTEST}
  605. procedure SelfTest;
  606. {$ENDIF}
  607. implementation
  608. { }
  609. { DynArrayAppend }
  610. { }
  611. function DynArrayAppend(var V: ByteArray; const R: Byte): Integer;
  612. begin
  613. Result := Length(V);
  614. SetLength(V, Result + 1);
  615. V[Result] := R;
  616. end;
  617. function DynArrayAppend(var V: WordArray; const R: Word): Integer;
  618. begin
  619. Result := Length(V);
  620. SetLength(V, Result + 1);
  621. V[Result] := R;
  622. end;
  623. function DynArrayAppend(var V: LongWordArray; const R: LongWord): Integer;
  624. begin
  625. Result := Length(V);
  626. SetLength(V, Result + 1);
  627. V[Result] := R;
  628. end;
  629. function DynArrayAppend(var V: NativeUIntArray; const R: NativeUInt): Integer;
  630. begin
  631. Result := Length(V);
  632. SetLength(V, Result + 1);
  633. V[Result] := R;
  634. end;
  635. function DynArrayAppend(var V: ShortIntArray; const R: ShortInt): Integer;
  636. begin
  637. Result := Length(V);
  638. SetLength(V, Result + 1);
  639. V[Result] := R;
  640. end;
  641. function DynArrayAppend(var V: SmallIntArray; const R: SmallInt): Integer;
  642. begin
  643. Result := Length(V);
  644. SetLength(V, Result + 1);
  645. V[Result] := R;
  646. end;
  647. function DynArrayAppend(var V: LongIntArray; const R: LongInt): Integer;
  648. begin
  649. Result := Length(V);
  650. SetLength(V, Result + 1);
  651. V[Result] := R;
  652. end;
  653. function DynArrayAppend(var V: Int64Array; const R: Int64): Integer;
  654. begin
  655. Result := Length(V);
  656. SetLength(V, Result + 1);
  657. V[Result] := R;
  658. end;
  659. function DynArrayAppend(var V: NativeIntArray; const R: NativeInt): Integer;
  660. begin
  661. Result := Length(V);
  662. SetLength(V, Result + 1);
  663. V[Result] := R;
  664. end;
  665. function DynArrayAppend(var V: SingleArray; const R: Single): Integer;
  666. begin
  667. Result := Length(V);
  668. SetLength(V, Result + 1);
  669. V[Result] := R;
  670. end;
  671. function DynArrayAppend(var V: DoubleArray; const R: Double): Integer;
  672. begin
  673. Result := Length(V);
  674. SetLength(V, Result + 1);
  675. V[Result] := R;
  676. end;
  677. function DynArrayAppend(var V: ExtendedArray; const R: Extended): Integer;
  678. begin
  679. Result := Length(V);
  680. SetLength(V, Result + 1);
  681. V[Result] := R;
  682. end;
  683. function DynArrayAppend(var V: CurrencyArray; const R: Currency): Integer;
  684. begin
  685. Result := Length(V);
  686. SetLength(V, Result + 1);
  687. V[Result] := R;
  688. end;
  689. function DynArrayAppend(var V: BooleanArray; const R: Boolean): Integer;
  690. begin
  691. Result := Length(V);
  692. SetLength(V, Result + 1);
  693. V[Result] := R;
  694. end;
  695. function DynArrayAppendA(var V: AnsiStringArray; const R: AnsiString): Integer;
  696. begin
  697. Result := Length(V);
  698. SetLength(V, Result + 1);
  699. V[Result] := R;
  700. end;
  701. function DynArrayAppendW(var V: WideStringArray; const R: WideString): Integer;
  702. begin
  703. Result := Length(V);
  704. SetLength(V, Result + 1);
  705. V[Result] := R;
  706. end;
  707. function DynArrayAppendU(var V: UnicodeStringArray; const R: UnicodeString): Integer;
  708. begin
  709. Result := Length(V);
  710. SetLength(V, Result + 1);
  711. V[Result] := R;
  712. end;
  713. function DynArrayAppend(var V: StringArray; const R: String): Integer;
  714. begin
  715. Result := Length(V);
  716. SetLength(V, Result + 1);
  717. V[Result] := R;
  718. end;
  719. {$IFNDEF ManagedCode}
  720. function DynArrayAppend(var V: PointerArray; const R: Pointer): Integer;
  721. begin
  722. Result := Length(V);
  723. SetLength(V, Result + 1);
  724. V[Result] := R;
  725. end;
  726. {$ENDIF}
  727. function DynArrayAppend(var V: ObjectArray; const R: TObject): Integer;
  728. begin
  729. Result := Length(V);
  730. SetLength(V, Result + 1);
  731. V[Result] := R;
  732. end;
  733. function DynArrayAppend(var V: InterfaceArray; const R: IInterface): Integer;
  734. begin
  735. Result := Length(V);
  736. SetLength(V, Result + 1);
  737. V[Result] := R;
  738. end;
  739. function DynArrayAppend(var V: ByteSetArray; const R: ByteSet): Integer;
  740. begin
  741. Result := Length(V);
  742. SetLength(V, Result + 1);
  743. V[Result] := R;
  744. end;
  745. function DynArrayAppend(var V: CharSetArray; const R: CharSet): Integer;
  746. begin
  747. Result := Length(V);
  748. SetLength(V, Result + 1);
  749. V[Result] := R;
  750. end;
  751. {$IFDEF ManagedCode}
  752. function DynArrayAppendByteArray(var V: ByteArray; const R: array of Byte): Integer;
  753. var I, L : Integer;
  754. begin
  755. Result := Length(V);
  756. L := Length(R);
  757. if L > 0 then
  758. begin
  759. SetLength(V, Result + L);
  760. for I := 0 to L - 1 do
  761. V[Result + I] := R[I];
  762. end;
  763. end;
  764. {$ELSE}
  765. function DynArrayAppendByteArray(var V: ByteArray; const R: array of Byte): Integer;
  766. var L : Integer;
  767. begin
  768. Result := Length(V);
  769. L := Length(R);
  770. if L > 0 then
  771. begin
  772. SetLength(V, Result + L);
  773. Move(R[0], V[Result], Sizeof(Byte) * L);
  774. end;
  775. end;
  776. {$ENDIF}
  777. {$IFDEF ManagedCode}
  778. function DynArrayAppendWordArray(var V: WordArray; const R: array of Word): Integer;
  779. var I, L : Integer;
  780. begin
  781. Result := Length(V);
  782. L := Length(R);
  783. if L > 0 then
  784. begin
  785. SetLength(V, Result + L);
  786. for I := 0 to L - 1 do
  787. V[Result + I] := R[I];
  788. end;
  789. end;
  790. {$ELSE}
  791. function DynArrayAppendWordArray(var V: WordArray; const R: array of Word): Integer;
  792. var L : Integer;
  793. begin
  794. Result := Length(V);
  795. L := Length(R);
  796. if L > 0 then
  797. begin
  798. SetLength(V, Result + L);
  799. Move(R[0], V[Result], Sizeof(Word) * L);
  800. end;
  801. end;
  802. {$ENDIF}
  803. {$IFDEF ManagedCode}
  804. function DynArrayAppendCardinalArray(var V: CardinalArray; const R: array of LongWord): Integer;
  805. var I, L : Integer;
  806. begin
  807. Result := Length(V);
  808. L := Length(R);
  809. if L > 0 then
  810. begin
  811. SetLength(V, Result + L);
  812. for I := 0 to L - 1 do
  813. V[Result + I] := R[I];
  814. end;
  815. end;
  816. {$ELSE}
  817. function DynArrayAppendCardinalArray(var V: CardinalArray; const R: array of LongWord): Integer;
  818. var L : Integer;
  819. begin
  820. Result := Length(V);
  821. L := Length(R);
  822. if L > 0 then
  823. begin
  824. SetLength(V, Result + L);
  825. Move(R[0], V[Result], Sizeof(LongWord) * L);
  826. end;
  827. end;
  828. {$ENDIF}
  829. {$IFDEF ManagedCode}
  830. function DynArrayAppendNativeUIntArray(var V: NativeUIntArray; const R: array of NativeUInt): Integer;
  831. var I, L : Integer;
  832. begin
  833. Result := Length(V);
  834. L := Length(R);
  835. if L > 0 then
  836. begin
  837. SetLength(V, Result + L);
  838. for I := 0 to L - 1 do
  839. V[Result + I] := R[I];
  840. end;
  841. end;
  842. {$ELSE}
  843. function DynArrayAppendNativeUIntArray(var V: NativeUIntArray; const R: array of NativeUInt): Integer;
  844. var L : Integer;
  845. begin
  846. Result := Length(V);
  847. L := Length(R);
  848. if L > 0 then
  849. begin
  850. SetLength(V, Result + L);
  851. Move(R[0], V[Result], Sizeof(NativeUInt) * L);
  852. end;
  853. end;
  854. {$ENDIF}
  855. {$IFDEF ManagedCode}
  856. function DynArrayAppendShortIntArray(var V: ShortIntArray; const R: array of ShortInt): Integer;
  857. var I, L : Integer;
  858. begin
  859. Result := Length(V);
  860. L := Length(R);
  861. if L > 0 then
  862. begin
  863. SetLength(V, Result + L);
  864. for I := 0 to L - 1 do
  865. V[Result + I] := R[I];
  866. end;
  867. end;
  868. {$ELSE}
  869. function DynArrayAppendShortIntArray(var V: ShortIntArray; const R: array of ShortInt): Integer;
  870. var L : Integer;
  871. begin
  872. Result := Length(V);
  873. L := Length(R);
  874. if L > 0 then
  875. begin
  876. SetLength(V, Result + L);
  877. Move(R[0], V[Result], Sizeof(ShortInt) * L);
  878. end;
  879. end;
  880. {$ENDIF}
  881. {$IFDEF ManagedCode}
  882. function DynArrayAppendSmallIntArray(var V: SmallIntArray; const R: array of SmallInt): Integer;
  883. var I, L : Integer;
  884. begin
  885. Result := Length(V);
  886. L := Length(R);
  887. if L > 0 then
  888. begin
  889. SetLength(V, Result + L);
  890. for I := 0 to L - 1 do
  891. V[Result + I] := R[I];
  892. end;
  893. end;
  894. {$ELSE}
  895. function DynArrayAppendSmallIntArray(var V: SmallIntArray; const R: array of SmallInt): Integer;
  896. var L : Integer;
  897. begin
  898. Result := Length(V);
  899. L := Length(R);
  900. if L > 0 then
  901. begin
  902. SetLength(V, Result + L);
  903. Move(R[0], V[Result], Sizeof(SmallInt) * L);
  904. end;
  905. end;
  906. {$ENDIF}
  907. {$IFDEF ManagedCode}
  908. function DynArrayAppendIntegerArray(var V: IntegerArray; const R: array of LongInt): Integer;
  909. var I, L : Integer;
  910. begin
  911. Result := Length(V);
  912. L := Length(R);
  913. if L > 0 then
  914. begin
  915. SetLength(V, Result + L);
  916. for I := 0 to L - 1 do
  917. V[Result + I] := R[I];
  918. end;
  919. end;
  920. {$ELSE}
  921. function DynArrayAppendIntegerArray(var V: IntegerArray; const R: array of LongInt): Integer;
  922. var L : Integer;
  923. begin
  924. Result := Length(V);
  925. L := Length(R);
  926. if L > 0 then
  927. begin
  928. SetLength(V, Result + L);
  929. Move(R[0], V[Result], Sizeof(LongInt) * L);
  930. end;
  931. end;
  932. {$ENDIF}
  933. {$IFDEF ManagedCode}
  934. function DynArrayAppendInt64Array(var V: Int64Array; const R: array of Int64): Integer;
  935. var I, L : Integer;
  936. begin
  937. Result := Length(V);
  938. L := Length(R);
  939. if L > 0 then
  940. begin
  941. SetLength(V, Result + L);
  942. for I := 0 to L - 1 do
  943. V[Result + I] := R[I];
  944. end;
  945. end;
  946. {$ELSE}
  947. function DynArrayAppendInt64Array(var V: Int64Array; const R: array of Int64): Integer;
  948. var L : Integer;
  949. begin
  950. Result := Length(V);
  951. L := Length(R);
  952. if L > 0 then
  953. begin
  954. SetLength(V, Result + L);
  955. Move(R[0], V[Result], Sizeof(Int64) * L);
  956. end;
  957. end;
  958. {$ENDIF}
  959. {$IFDEF ManagedCode}
  960. function DynArrayAppendNativeIntArray(var V: NativeIntArray; const R: array of NativeInt): Integer;
  961. var I, L : Integer;
  962. begin
  963. Result := Length(V);
  964. L := Length(R);
  965. if L > 0 then
  966. begin
  967. SetLength(V, Result + L);
  968. for I := 0 to L - 1 do
  969. V[Result + I] := R[I];
  970. end;
  971. end;
  972. {$ELSE}
  973. function DynArrayAppendNativeIntArray(var V: NativeIntArray; const R: array of NativeInt): Integer;
  974. var L : Integer;
  975. begin
  976. Result := Length(V);
  977. L := Length(R);
  978. if L > 0 then
  979. begin
  980. SetLength(V, Result + L);
  981. Move(R[0], V[Result], Sizeof(NativeInt) * L);
  982. end;
  983. end;
  984. {$ENDIF}
  985. {$IFDEF ManagedCode}
  986. function DynArrayAppendSingleArray(var V: SingleArray; const R: array of Single): Integer;
  987. var I, L : Integer;
  988. begin
  989. Result := Length(V);
  990. L := Length(R);
  991. if L > 0 then
  992. begin
  993. SetLength(V, Result + L);
  994. for I := 0 to L - 1 do
  995. V[Result + I] := R[I];
  996. end;
  997. end;
  998. {$ELSE}
  999. function DynArrayAppendSingleArray(var V: SingleArray; const R: array of Single): Integer;
  1000. var L : Integer;
  1001. begin
  1002. Result := Length(V);
  1003. L := Length(R);
  1004. if L > 0 then
  1005. begin
  1006. SetLength(V, Result + L);
  1007. Move(R[0], V[Result], Sizeof(Single) * L);
  1008. end;
  1009. end;
  1010. {$ENDIF}
  1011. {$IFDEF ManagedCode}
  1012. function DynArrayAppendDoubleArray(var V: DoubleArray; const R: array of Double): Integer;
  1013. var I, L : Integer;
  1014. begin
  1015. Result := Length(V);
  1016. L := Length(R);
  1017. if L > 0 then
  1018. begin
  1019. SetLength(V, Result + L);
  1020. for I := 0 to L - 1 do
  1021. V[Result + I] := R[I];
  1022. end;
  1023. end;
  1024. {$ELSE}
  1025. function DynArrayAppendDoubleArray(var V: DoubleArray; const R: array of Double): Integer;
  1026. var L : Integer;
  1027. begin
  1028. Result := Length(V);
  1029. L := Length(R);
  1030. if L > 0 then
  1031. begin
  1032. SetLength(V, Result + L);
  1033. Move(R[0], V[Result], Sizeof(Double) * L);
  1034. end;
  1035. end;
  1036. {$ENDIF}
  1037. {$IFDEF ManagedCode}
  1038. function DynArrayAppendExtendedArray(var V: ExtendedArray; const R: array of Extended): Integer;
  1039. var I, L : Integer;
  1040. begin
  1041. Result := Length(V);
  1042. L := Length(R);
  1043. if L > 0 then
  1044. begin
  1045. SetLength(V, Result + L);
  1046. for I := 0 to L - 1 do
  1047. V[Result + I] := R[I];
  1048. end;
  1049. end;
  1050. {$ELSE}
  1051. function DynArrayAppendExtendedArray(var V: ExtendedArray; const R: array of Extended): Integer;
  1052. var L : Integer;
  1053. begin
  1054. Result := Length(V);
  1055. L := Length(R);
  1056. if L > 0 then
  1057. begin
  1058. SetLength(V, Result + L);
  1059. Move(R[0], V[Result], Sizeof(Extended) * L);
  1060. end;
  1061. end;
  1062. {$ENDIF}
  1063. {$IFNDEF CLR}
  1064. {$IFDEF ManagedCode}
  1065. function DynArrayAppendCurrencyArray(var V: CurrencyArray; const R: array of Currency): Integer;
  1066. var I, L : Integer;
  1067. begin
  1068. Result := Length(V);
  1069. L := Length(R);
  1070. if L > 0 then
  1071. begin
  1072. SetLength(V, Result + L);
  1073. for I := 0 to L - 1 do
  1074. V[Result + I] := R[I];
  1075. end;
  1076. end;
  1077. {$ELSE}
  1078. function DynArrayAppendCurrencyArray(var V: CurrencyArray; const R: array of Currency): Integer;
  1079. var L : Integer;
  1080. begin
  1081. Result := Length(V);
  1082. L := Length(R);
  1083. if L > 0 then
  1084. begin
  1085. SetLength(V, Result + L);
  1086. Move(R[0], V[Result], Sizeof(Currency) * L);
  1087. end;
  1088. end;
  1089. {$ENDIF}
  1090. {$IFDEF ManagedCode}
  1091. function DynArrayAppendPointerArray(var V: PointerArray; const R: array of Pointer): Integer;
  1092. var I, L : Integer;
  1093. begin
  1094. Result := Length(V);
  1095. L := Length(R);
  1096. if L > 0 then
  1097. begin
  1098. SetLength(V, Result + L);
  1099. for I := 0 to L - 1 do
  1100. V[Result + I] := R[I];
  1101. end;
  1102. end;
  1103. {$ELSE}
  1104. function DynArrayAppendPointerArray(var V: PointerArray; const R: array of Pointer): Integer;
  1105. var L : Integer;
  1106. begin
  1107. Result := Length(V);
  1108. L := Length(R);
  1109. if L > 0 then
  1110. begin
  1111. SetLength(V, Result + L);
  1112. Move(R[0], V[Result], Sizeof(Pointer) * L);
  1113. end;
  1114. end;
  1115. {$ENDIF}
  1116. {$IFDEF ManagedCode}
  1117. function DynArrayAppendCharSetArray(var V: CharSetArray; const R: array of CharSet): Integer;
  1118. var I, L : Integer;
  1119. begin
  1120. Result := Length(V);
  1121. L := Length(R);
  1122. if L > 0 then
  1123. begin
  1124. SetLength(V, Result + L);
  1125. for I := 0 to L - 1 do
  1126. V[Result + I] := R[I];
  1127. end;
  1128. end;
  1129. {$ELSE}
  1130. function DynArrayAppendCharSetArray(var V: CharSetArray; const R: array of CharSet): Integer;
  1131. var L : Integer;
  1132. begin
  1133. Result := Length(V);
  1134. L := Length(R);
  1135. if L > 0 then
  1136. begin
  1137. SetLength(V, Result + L);
  1138. Move(R[0], V[Result], Sizeof(CharSet) * L);
  1139. end;
  1140. end;
  1141. {$ENDIF}
  1142. {$IFDEF ManagedCode}
  1143. function DynArrayAppendByteSetArray(var V: ByteSetArray; const R: array of ByteSet): Integer;
  1144. var I, L : Integer;
  1145. begin
  1146. Result := Length(V);
  1147. L := Length(R);
  1148. if L > 0 then
  1149. begin
  1150. SetLength(V, Result + L);
  1151. for I := 0 to L - 1 do
  1152. V[Result + I] := R[I];
  1153. end;
  1154. end;
  1155. {$ELSE}
  1156. function DynArrayAppendByteSetArray(var V: ByteSetArray; const R: array of ByteSet): Integer;
  1157. var L : Integer;
  1158. begin
  1159. Result := Length(V);
  1160. L := Length(R);
  1161. if L > 0 then
  1162. begin
  1163. SetLength(V, Result + L);
  1164. Move(R[0], V[Result], Sizeof(ByteSet) * L);
  1165. end;
  1166. end;
  1167. {$ENDIF}
  1168. {$ENDIF}
  1169. function DynArrayAppendObjectArray(var V: ObjectArray; const R: ObjectArray): Integer;
  1170. var I, LR : Integer;
  1171. begin
  1172. Result := Length(V);
  1173. LR := Length(R);
  1174. if LR > 0 then
  1175. begin
  1176. SetLength(V, Result + LR);
  1177. for I := 0 to LR - 1 do
  1178. V[Result + I] := R[I];
  1179. end;
  1180. end;
  1181. function DynArrayAppendAnsiStringArray(var V: AnsiStringArray; const R: array of AnsiString): Integer;
  1182. var I, LR : Integer;
  1183. begin
  1184. Result := Length(V);
  1185. LR := Length(R);
  1186. if LR > 0 then
  1187. begin
  1188. SetLength(V, Result + LR);
  1189. for I := 0 to LR - 1 do
  1190. V[Result + I] := R[I];
  1191. end;
  1192. end;
  1193. function DynArrayAppendWideStringArray(var V: WideStringArray; const R: array of WideString): Integer;
  1194. var I, LR : Integer;
  1195. begin
  1196. Result := Length(V);
  1197. LR := Length(R);
  1198. if LR > 0 then
  1199. begin
  1200. SetLength(V, Result + LR);
  1201. for I := 0 to LR - 1 do
  1202. V[Result + I] := R[I];
  1203. end;
  1204. end;
  1205. function DynArrayAppendUnicodeStringArray(var V: UnicodeStringArray; const R: array of UnicodeString): Integer;
  1206. var I, LR : Integer;
  1207. begin
  1208. Result := Length(V);
  1209. LR := Length(R);
  1210. if LR > 0 then
  1211. begin
  1212. SetLength(V, Result + LR);
  1213. for I := 0 to LR - 1 do
  1214. V[Result + I] := R[I];
  1215. end;
  1216. end;
  1217. function DynArrayAppendStringArray(var V: StringArray; const R: array of String): Integer;
  1218. var I, LR : Integer;
  1219. begin
  1220. Result := Length(V);
  1221. LR := Length(R);
  1222. if LR > 0 then
  1223. begin
  1224. SetLength(V, Result + LR);
  1225. for I := 0 to LR - 1 do
  1226. V[Result + I] := R[I];
  1227. end;
  1228. end;
  1229. { }
  1230. { DynArrayRemove }
  1231. { }
  1232. function DynArrayRemove(var V: ByteArray; const Idx: Integer; const Count: Integer): Integer;
  1233. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1234. begin
  1235. L := Length(V);
  1236. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1237. begin
  1238. Result := 0;
  1239. exit;
  1240. end;
  1241. I := MaxI(Idx, 0);
  1242. J := MinI(Count, L - I);
  1243. M := L - J - I;
  1244. {$IFDEF CLR}
  1245. for F := 0 to M - 1 do
  1246. V[I + F] := V[I + J + F];
  1247. {$ELSE}
  1248. if M > 0 then
  1249. Move(V[I + J], V[I], M * SizeOf(Byte));
  1250. {$ENDIF}
  1251. SetLength(V, L - J);
  1252. Result := J;
  1253. end;
  1254. function DynArrayRemove(var V: WordArray; const Idx: Integer; const Count: Integer): Integer;
  1255. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1256. begin
  1257. L := Length(V);
  1258. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1259. begin
  1260. Result := 0;
  1261. exit;
  1262. end;
  1263. I := MaxI(Idx, 0);
  1264. J := MinI(Count, L - I);
  1265. M := L - J - I;
  1266. {$IFDEF CLR}
  1267. for F := 0 to M - 1 do
  1268. V[I + F] := V[I + J + F];
  1269. {$ELSE}
  1270. if M > 0 then
  1271. Move(V[I + J], V[I], M * SizeOf(Word));
  1272. {$ENDIF}
  1273. SetLength(V, L - J);
  1274. Result := J;
  1275. end;
  1276. function DynArrayRemove(var V: LongWordArray; const Idx: Integer; const Count: Integer): Integer;
  1277. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1278. begin
  1279. L := Length(V);
  1280. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1281. begin
  1282. Result := 0;
  1283. exit;
  1284. end;
  1285. I := MaxI(Idx, 0);
  1286. J := MinI(Count, L - I);
  1287. M := L - J - I;
  1288. {$IFDEF CLR}
  1289. for F := 0 to M - 1 do
  1290. V[I + F] := V[I + J + F];
  1291. {$ELSE}
  1292. if M > 0 then
  1293. Move(V[I + J], V[I], M * SizeOf(LongWord));
  1294. {$ENDIF}
  1295. SetLength(V, L - J);
  1296. Result := J;
  1297. end;
  1298. function DynArrayRemove(var V: NativeUIntArray; const Idx: Integer; const Count: Integer): Integer;
  1299. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1300. begin
  1301. L := Length(V);
  1302. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1303. begin
  1304. Result := 0;
  1305. exit;
  1306. end;
  1307. I := MaxI(Idx, 0);
  1308. J := MinI(Count, L - I);
  1309. M := L - J - I;
  1310. {$IFDEF CLR}
  1311. for F := 0 to M - 1 do
  1312. V[I + F] := V[I + J + F];
  1313. {$ELSE}
  1314. if M > 0 then
  1315. Move(V[I + J], V[I], M * SizeOf(NativeUInt));
  1316. {$ENDIF}
  1317. SetLength(V, L - J);
  1318. Result := J;
  1319. end;
  1320. function DynArrayRemove(var V: ShortIntArray; const Idx: Integer; const Count: Integer): Integer;
  1321. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1322. begin
  1323. L := Length(V);
  1324. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1325. begin
  1326. Result := 0;
  1327. exit;
  1328. end;
  1329. I := MaxI(Idx, 0);
  1330. J := MinI(Count, L - I);
  1331. M := L - J - I;
  1332. {$IFDEF CLR}
  1333. for F := 0 to M - 1 do
  1334. V[I + F] := V[I + J + F];
  1335. {$ELSE}
  1336. if M > 0 then
  1337. Move(V[I + J], V[I], M * SizeOf(ShortInt));
  1338. {$ENDIF}
  1339. SetLength(V, L - J);
  1340. Result := J;
  1341. end;
  1342. function DynArrayRemove(var V: SmallIntArray; const Idx: Integer; const Count: Integer): Integer;
  1343. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1344. begin
  1345. L := Length(V);
  1346. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1347. begin
  1348. Result := 0;
  1349. exit;
  1350. end;
  1351. I := MaxI(Idx, 0);
  1352. J := MinI(Count, L - I);
  1353. M := L - J - I;
  1354. {$IFDEF CLR}
  1355. for F := 0 to M - 1 do
  1356. V[I + F] := V[I + J + F];
  1357. {$ELSE}
  1358. if M > 0 then
  1359. Move(V[I + J], V[I], M * SizeOf(SmallInt));
  1360. {$ENDIF}
  1361. SetLength(V, L - J);
  1362. Result := J;
  1363. end;
  1364. function DynArrayRemove(var V: LongIntArray; const Idx: Integer; const Count: Integer): Integer;
  1365. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1366. begin
  1367. L := Length(V);
  1368. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1369. begin
  1370. Result := 0;
  1371. exit;
  1372. end;
  1373. I := MaxI(Idx, 0);
  1374. J := MinI(Count, L - I);
  1375. M := L - J - I;
  1376. {$IFDEF CLR}
  1377. for F := 0 to M - 1 do
  1378. V[I + F] := V[I + J + F];
  1379. {$ELSE}
  1380. if M > 0 then
  1381. Move(V[I + J], V[I], M * SizeOf(LongInt));
  1382. {$ENDIF}
  1383. SetLength(V, L - J);
  1384. Result := J;
  1385. end;
  1386. function DynArrayRemove(var V: Int64Array; const Idx: Integer; const Count: Integer): Integer;
  1387. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1388. begin
  1389. L := Length(V);
  1390. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1391. begin
  1392. Result := 0;
  1393. exit;
  1394. end;
  1395. I := MaxI(Idx, 0);
  1396. J := MinI(Count, L - I);
  1397. M := L - J - I;
  1398. {$IFDEF CLR}
  1399. for F := 0 to M - 1 do
  1400. V[I + F] := V[I + J + F];
  1401. {$ELSE}
  1402. if M > 0 then
  1403. Move(V[I + J], V[I], M * SizeOf(Int64));
  1404. {$ENDIF}
  1405. SetLength(V, L - J);
  1406. Result := J;
  1407. end;
  1408. function DynArrayRemove(var V: NativeIntArray; const Idx: Integer; const Count: Integer): Integer;
  1409. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1410. begin
  1411. L := Length(V);
  1412. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1413. begin
  1414. Result := 0;
  1415. exit;
  1416. end;
  1417. I := MaxI(Idx, 0);
  1418. J := MinI(Count, L - I);
  1419. M := L - J - I;
  1420. {$IFDEF CLR}
  1421. for F := 0 to M - 1 do
  1422. V[I + F] := V[I + J + F];
  1423. {$ELSE}
  1424. if M > 0 then
  1425. Move(V[I + J], V[I], M * SizeOf(NativeInt));
  1426. {$ENDIF}
  1427. SetLength(V, L - J);
  1428. Result := J;
  1429. end;
  1430. function DynArrayRemove(var V: SingleArray; const Idx: Integer; const Count: Integer): Integer;
  1431. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1432. begin
  1433. L := Length(V);
  1434. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1435. begin
  1436. Result := 0;
  1437. exit;
  1438. end;
  1439. I := MaxI(Idx, 0);
  1440. J := MinI(Count, L - I);
  1441. M := L - J - I;
  1442. {$IFDEF CLR}
  1443. for F := 0 to M - 1 do
  1444. V[I + F] := V[I + J + F];
  1445. {$ELSE}
  1446. if M > 0 then
  1447. Move(V[I + J], V[I], M * SizeOf(Single));
  1448. {$ENDIF}
  1449. SetLength(V, L - J);
  1450. Result := J;
  1451. end;
  1452. function DynArrayRemove(var V: DoubleArray; const Idx: Integer; const Count: Integer): Integer;
  1453. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1454. begin
  1455. L := Length(V);
  1456. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1457. begin
  1458. Result := 0;
  1459. exit;
  1460. end;
  1461. I := MaxI(Idx, 0);
  1462. J := MinI(Count, L - I);
  1463. M := L - J - I;
  1464. {$IFDEF CLR}
  1465. for F := 0 to M - 1 do
  1466. V[I + F] := V[I + J + F];
  1467. {$ELSE}
  1468. if M > 0 then
  1469. Move(V[I + J], V[I], M * SizeOf(Double));
  1470. {$ENDIF}
  1471. SetLength(V, L - J);
  1472. Result := J;
  1473. end;
  1474. function DynArrayRemove(var V: ExtendedArray; const Idx: Integer; const Count: Integer): Integer;
  1475. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1476. begin
  1477. L := Length(V);
  1478. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1479. begin
  1480. Result := 0;
  1481. exit;
  1482. end;
  1483. I := MaxI(Idx, 0);
  1484. J := MinI(Count, L - I);
  1485. M := L - J - I;
  1486. {$IFDEF CLR}
  1487. for F := 0 to M - 1 do
  1488. V[I + F] := V[I + J + F];
  1489. {$ELSE}
  1490. if M > 0 then
  1491. Move(V[I + J], V[I], M * SizeOf(Extended));
  1492. {$ENDIF}
  1493. SetLength(V, L - J);
  1494. Result := J;
  1495. end;
  1496. {$IFNDEF CLR}
  1497. function DynArrayRemove(var V: CurrencyArray; const Idx: Integer; const Count: Integer): Integer;
  1498. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1499. begin
  1500. L := Length(V);
  1501. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1502. begin
  1503. Result := 0;
  1504. exit;
  1505. end;
  1506. I := MaxI(Idx, 0);
  1507. J := MinI(Count, L - I);
  1508. M := L - J - I;
  1509. {$IFDEF CLR}
  1510. for F := 0 to M - 1 do
  1511. V[I + F] := V[I + J + F];
  1512. {$ELSE}
  1513. if M > 0 then
  1514. Move(V[I + J], V[I], M * SizeOf(Currency));
  1515. {$ENDIF}
  1516. SetLength(V, L - J);
  1517. Result := J;
  1518. end;
  1519. function DynArrayRemove(var V: PointerArray; const Idx: Integer; const Count: Integer): Integer;
  1520. var I, J, L, M{$IFDEF CLR}, F{$ENDIF}: Integer;
  1521. begin
  1522. L := Length(V);
  1523. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1524. begin
  1525. Result := 0;
  1526. exit;
  1527. end;
  1528. I := MaxI(Idx, 0);
  1529. J := MinI(Count, L - I);
  1530. M := L - J - I;
  1531. {$IFDEF CLR}
  1532. for F := 0 to M - 1 do
  1533. V[I + F] := V[I + J + F];
  1534. {$ELSE}
  1535. if M > 0 then
  1536. Move(V[I + J], V[I], M * SizeOf(Pointer));
  1537. {$ENDIF}
  1538. SetLength(V, L - J);
  1539. Result := J;
  1540. end;
  1541. {$ENDIF}
  1542. function DynArrayRemove(var V: ObjectArray; const Idx: Integer; const Count: Integer;
  1543. const FreeObjects: Boolean): Integer;
  1544. var I, J, K, L, M, F : Integer;
  1545. begin
  1546. L := Length(V);
  1547. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1548. begin
  1549. Result := 0;
  1550. exit;
  1551. end;
  1552. I := MaxI(Idx, 0);
  1553. J := MinI(Count, L - I);
  1554. if FreeObjects then
  1555. for K := I to I + J - 1 do
  1556. FreeAndNil(V[K]);
  1557. M := L - J - I;
  1558. for F := I to I + M - 1 do
  1559. V[F] := V[F + J];
  1560. SetLength(V, L - J);
  1561. Result := J;
  1562. end;
  1563. function DynArrayRemoveA(var V: AnsiStringArray; const Idx: Integer; const Count: Integer): Integer;
  1564. var I, J, K, L : Integer;
  1565. begin
  1566. L := Length(V);
  1567. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1568. begin
  1569. Result := 0;
  1570. exit;
  1571. end;
  1572. I := MaxI(Idx, 0);
  1573. J := MinI(Count, L - I);
  1574. for K := I to L - J - 1 do
  1575. V[K] := V[K + J];
  1576. SetLength(V, L - J);
  1577. Result := J;
  1578. end;
  1579. function DynArrayRemoveW(var V: WideStringArray; const Idx: Integer; const Count: Integer): Integer;
  1580. var I, J, K, L : Integer;
  1581. begin
  1582. L := Length(V);
  1583. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1584. begin
  1585. Result := 0;
  1586. exit;
  1587. end;
  1588. I := MaxI(Idx, 0);
  1589. J := MinI(Count, L - I);
  1590. for K := I to L - J - 1 do
  1591. V[K] := V[K + J];
  1592. SetLength(V, L - J);
  1593. Result := J;
  1594. end;
  1595. function DynArrayRemoveU(var V: UnicodeStringArray; const Idx: Integer; const Count: Integer): Integer;
  1596. var I, J, K, L : Integer;
  1597. begin
  1598. L := Length(V);
  1599. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1600. begin
  1601. Result := 0;
  1602. exit;
  1603. end;
  1604. I := MaxI(Idx, 0);
  1605. J := MinI(Count, L - I);
  1606. for K := I to L - J - 1 do
  1607. V[K] := V[K + J];
  1608. SetLength(V, L - J);
  1609. Result := J;
  1610. end;
  1611. function DynArrayRemove(var V: StringArray; const Idx: Integer; const Count: Integer): Integer;
  1612. var I, J, K, L : Integer;
  1613. begin
  1614. L := Length(V);
  1615. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1616. begin
  1617. Result := 0;
  1618. exit;
  1619. end;
  1620. I := MaxI(Idx, 0);
  1621. J := MinI(Count, L - I);
  1622. for K := I to L - J - 1 do
  1623. V[K] := V[K + J];
  1624. SetLength(V, L - J);
  1625. Result := J;
  1626. end;
  1627. {$IFDEF ManagedCode}
  1628. function DynArrayRemove(var V: InterfaceArray; const Idx: Integer; const Count: Integer): Integer;
  1629. var I, J, K, L, M, F : Integer;
  1630. begin
  1631. L := Length(V);
  1632. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1633. begin
  1634. Result := 0;
  1635. exit;
  1636. end;
  1637. I := MaxI(Idx, 0);
  1638. J := MinI(Count, L - I);
  1639. for K := I to I + J - 1 do
  1640. V[K] := nil;
  1641. M := L - J - I;
  1642. for F := 0 to M - 1 do
  1643. V[I + F] := V[I + J + F];
  1644. for F := 0 to J - 1 do
  1645. V[L - J + F] := nil;
  1646. SetLength(V, L - J);
  1647. Result := J;
  1648. end;
  1649. {$ELSE}
  1650. function DynArrayRemove(var V: InterfaceArray; const Idx: Integer; const Count: Integer): Integer;
  1651. var I, J, K, L, M : Integer;
  1652. begin
  1653. L := Length(V);
  1654. if (Idx >= L) or (Idx + Count <= 0) or (L = 0) or (Count = 0) then
  1655. begin
  1656. Result := 0;
  1657. exit;
  1658. end;
  1659. I := MaxI(Idx, 0);
  1660. J := MinI(Count, L - I);
  1661. for K := I to I + J - 1 do
  1662. V[K] := nil;
  1663. M := L - J - I;
  1664. if M > 0 then
  1665. Move(V[I + J], V[I], M * SizeOf(IInterface));
  1666. FillChar(V[L - J], J * SizeOf(IInterface), #0);
  1667. SetLength(V, L - J);
  1668. Result := J;
  1669. end;
  1670. {$ENDIF}
  1671. { }
  1672. { DynArrayRemoveDuplicates }
  1673. { }
  1674. procedure DynArrayRemoveDuplicates(var V: ByteArray; const IsSorted: Boolean);
  1675. var I, C, J, L : Integer;
  1676. F : Byte;
  1677. begin
  1678. L := Length(V);
  1679. if L = 0 then
  1680. exit;
  1681. if IsSorted then
  1682. begin
  1683. J := 0;
  1684. repeat
  1685. F := V[J];
  1686. I := J + 1;
  1687. while (I < L) and (V[I] = F) do
  1688. Inc(I);
  1689. C := I - J;
  1690. if C > 1 then
  1691. begin
  1692. DynArrayRemove(V, J + 1, C - 1);
  1693. Dec(L, C - 1);
  1694. Inc(J);
  1695. end
  1696. else
  1697. J := I;
  1698. until J >= L;
  1699. end else
  1700. begin
  1701. J := 0;
  1702. repeat
  1703. repeat
  1704. I := DynArrayPosNext(V[J], V, J);
  1705. if I >= 0 then
  1706. DynArrayRemove(V, I, 1);
  1707. until I < 0;
  1708. Inc(J);
  1709. until J >= Length(V);
  1710. end;
  1711. end;
  1712. procedure DynArrayRemoveDuplicates(var V: WordArray; const IsSorted: Boolean);
  1713. var I, C, J, L : Integer;
  1714. F : Word;
  1715. begin
  1716. L := Length(V);
  1717. if L = 0 then
  1718. exit;
  1719. if IsSorted then
  1720. begin
  1721. J := 0;
  1722. repeat
  1723. F := V[J];
  1724. I := J + 1;
  1725. while (I < L) and (V[I] = F) do
  1726. Inc(I);
  1727. C := I - J;
  1728. if C > 1 then
  1729. begin
  1730. DynArrayRemove(V, J + 1, C - 1);
  1731. Dec(L, C - 1);
  1732. Inc(J);
  1733. end
  1734. else
  1735. J := I;
  1736. until J >= L;
  1737. end else
  1738. begin
  1739. J := 0;
  1740. repeat
  1741. repeat
  1742. I := DynArrayPosNext(V[J], V, J);
  1743. if I >= 0 then
  1744. DynArrayRemove(V, I, 1);
  1745. until I < 0;
  1746. Inc(J);
  1747. until J >= Length(V);
  1748. end;
  1749. end;
  1750. procedure DynArrayRemoveDuplicates(var V: LongWordArray; const IsSorted: Boolean);
  1751. var I, C, J, L : Integer;
  1752. F : LongWord;
  1753. begin
  1754. L := Length(V);
  1755. if L = 0 then
  1756. exit;
  1757. if IsSorted then
  1758. begin
  1759. J := 0;
  1760. repeat
  1761. F := V[J];
  1762. I := J + 1;
  1763. while (I < L) and (V[I] = F) do
  1764. Inc(I);
  1765. C := I - J;
  1766. if C > 1 then
  1767. begin
  1768. DynArrayRemove(V, J + 1, C - 1);
  1769. Dec(L, C - 1);
  1770. Inc(J);
  1771. end
  1772. else
  1773. J := I;
  1774. until J >= L;
  1775. end else
  1776. begin
  1777. J := 0;
  1778. repeat
  1779. repeat
  1780. I := DynArrayPosNext(V[J], V, J);
  1781. if I >= 0 then
  1782. DynArrayRemove(V, I, 1);
  1783. until I < 0;
  1784. Inc(J);
  1785. until J >= Length(V);
  1786. end;
  1787. end;
  1788. procedure DynArrayRemoveDuplicates(var V: ShortIntArray; const IsSorted: Boolean);
  1789. var I, C, J, L : Integer;
  1790. F : ShortInt;
  1791. begin
  1792. L := Length(V);
  1793. if L = 0 then
  1794. exit;
  1795. if IsSorted then
  1796. begin
  1797. J := 0;
  1798. repeat
  1799. F := V[J];
  1800. I := J + 1;
  1801. while (I < L) and (V[I] = F) do
  1802. Inc(I);
  1803. C := I - J;
  1804. if C > 1 then
  1805. begin
  1806. DynArrayRemove(V, J + 1, C - 1);
  1807. Dec(L, C - 1);
  1808. Inc(J);
  1809. end
  1810. else
  1811. J := I;
  1812. until J >= L;
  1813. end else
  1814. begin
  1815. J := 0;
  1816. repeat
  1817. repeat
  1818. I := DynArrayPosNext(V[J], V, J);
  1819. if I >= 0 then
  1820. DynArrayRemove(V, I, 1);
  1821. until I < 0;
  1822. Inc(J);
  1823. until J >= Length(V);
  1824. end;
  1825. end;
  1826. procedure DynArrayRemoveDuplicates(var V: SmallIntArray; const IsSorted: Boolean);
  1827. var I, C, J, L : Integer;
  1828. F : SmallInt;
  1829. begin
  1830. L := Length(V);
  1831. if L = 0 then
  1832. exit;
  1833. if IsSorted then
  1834. begin
  1835. J := 0;
  1836. repeat
  1837. F := V[J];
  1838. I := J + 1;
  1839. while (I < L) and (V[I] = F) do
  1840. Inc(I);
  1841. C := I - J;
  1842. if C > 1 then
  1843. begin
  1844. DynArrayRemove(V, J + 1, C - 1);
  1845. Dec(L, C - 1);
  1846. Inc(J);
  1847. end
  1848. else
  1849. J := I;
  1850. until J >= L;
  1851. end else
  1852. begin
  1853. J := 0;
  1854. repeat
  1855. repeat
  1856. I := DynArrayPosNext(V[J], V, J);
  1857. if I >= 0 then
  1858. DynArrayRemove(V, I, 1);
  1859. until I < 0;
  1860. Inc(J);
  1861. until J >= Length(V);
  1862. end;
  1863. end;
  1864. procedure DynArrayRemoveDuplicates(var V: LongIntArray; const IsSorted: Boolean);
  1865. var I, C, J, L : Integer;
  1866. F : LongInt;
  1867. begin
  1868. L := Length(V);
  1869. if L = 0 then
  1870. exit;
  1871. if IsSorted then
  1872. begin
  1873. J := 0;
  1874. repeat
  1875. F := V[J];
  1876. I := J + 1;
  1877. while (I < L) and (V[I] = F) do
  1878. Inc(I);
  1879. C := I - J;
  1880. if C > 1 then
  1881. begin
  1882. DynArrayRemove(V, J + 1, C - 1);
  1883. Dec(L, C - 1);
  1884. Inc(J);
  1885. end
  1886. else
  1887. J := I;
  1888. until J >= L;
  1889. end else
  1890. begin
  1891. J := 0;
  1892. repeat
  1893. repeat
  1894. I := DynArrayPosNext(V[J], V, J);
  1895. if I >= 0 then
  1896. DynArrayRemove(V, I, 1);
  1897. until I < 0;
  1898. Inc(J);
  1899. until J >= Length(V);
  1900. end;
  1901. end;
  1902. procedure DynArrayRemoveDuplicates(var V: Int64Array; const IsSorted: Boolean);
  1903. var I, C, J, L : Integer;
  1904. F : Int64;
  1905. begin
  1906. L := Length(V);
  1907. if L = 0 then
  1908. exit;
  1909. if IsSorted then
  1910. begin
  1911. J := 0;
  1912. repeat
  1913. F := V[J];
  1914. I := J + 1;
  1915. while (I < L) and (V[I] = F) do
  1916. Inc(I);
  1917. C := I - J;
  1918. if C > 1 then
  1919. begin
  1920. DynArrayRemove(V, J + 1, C - 1);
  1921. Dec(L, C - 1);
  1922. Inc(J);
  1923. end
  1924. else
  1925. J := I;
  1926. until J >= L;
  1927. end else
  1928. begin
  1929. J := 0;
  1930. repeat
  1931. repeat
  1932. I := DynArrayPosNext(V[J], V, J);
  1933. if I >= 0 then
  1934. DynArrayRemove(V, I, 1);
  1935. until I < 0;
  1936. Inc(J);
  1937. until J >= Length(V);
  1938. end;
  1939. end;
  1940. procedure DynArrayRemoveDuplicates(var V: SingleArray; const IsSorted: Boolean);
  1941. var I, C, J, L : Integer;
  1942. F : Single;
  1943. begin
  1944. L := Length(V);
  1945. if L = 0 then
  1946. exit;
  1947. if IsSorted then
  1948. begin
  1949. J := 0;
  1950. repeat
  1951. F := V[J];
  1952. I := J + 1;
  1953. while (I < L) and (V[I] = F) do
  1954. Inc(I);
  1955. C := I - J;
  1956. if C > 1 then
  1957. begin
  1958. DynArrayRemove(V, J + 1, C - 1);
  1959. Dec(L, C - 1);
  1960. Inc(J);
  1961. end
  1962. else
  1963. J := I;
  1964. until J >= L;
  1965. end else
  1966. begin
  1967. J := 0;
  1968. repeat
  1969. repeat
  1970. I := DynArrayPosNext(V[J], V, J);
  1971. if I >= 0 then
  1972. DynArrayRemove(V, I, 1);
  1973. until I < 0;
  1974. Inc(J);
  1975. until J >= Length(V);
  1976. end;
  1977. end;
  1978. procedure DynArrayRemoveDuplicates(var V: DoubleArray; const IsSorted: Boolean);
  1979. var I, C, J, L : Integer;
  1980. F : Double;
  1981. begin
  1982. L := Length(V);
  1983. if L = 0 then
  1984. exit;
  1985. if IsSorted then
  1986. begin
  1987. J := 0;
  1988. repeat
  1989. F := V[J];
  1990. I := J + 1;
  1991. while (I < L) and (V[I] = F) do
  1992. Inc(I);
  1993. C := I - J;
  1994. if C > 1 then
  1995. begin
  1996. DynArrayRemove(V, J + 1, C - 1);
  1997. Dec(L, C - 1);
  1998. Inc(J);
  1999. end
  2000. else
  2001. J := I;
  2002. until J >= L;
  2003. end else
  2004. begin
  2005. J := 0;
  2006. repeat
  2007. repeat
  2008. I := DynArrayPosNext(V[J], V, J);
  2009. if I >= 0 then
  2010. DynArrayRemove(V, I, 1);
  2011. until I < 0;
  2012. Inc(J);
  2013. until J >= Length(V);
  2014. end;
  2015. end;
  2016. procedure DynArrayRemoveDuplicates(var V: ExtendedArray; const IsSorted: Boolean);
  2017. var I, C, J, L : Integer;
  2018. F : Extended;
  2019. begin
  2020. L := Length(V);
  2021. if L = 0 then
  2022. exit;
  2023. if IsSorted then
  2024. begin
  2025. J := 0;
  2026. repeat
  2027. F := V[J];
  2028. I := J + 1;
  2029. while (I < L) and (V[I] = F) do
  2030. Inc(I);
  2031. C := I - J;
  2032. if C > 1 then
  2033. begin
  2034. DynArrayRemove(V, J + 1, C - 1);
  2035. Dec(L, C - 1);
  2036. Inc(J);
  2037. end
  2038. else
  2039. J := I;
  2040. until J >= L;
  2041. end else
  2042. begin
  2043. J := 0;
  2044. repeat
  2045. repeat
  2046. I := DynArrayPosNext(V[J], V, J);
  2047. if I >= 0 then
  2048. DynArrayRemove(V, I, 1);
  2049. until I < 0;
  2050. Inc(J);
  2051. until J >= Length(V);
  2052. end;
  2053. end;
  2054. procedure DynArrayRemoveDuplicatesA(var V: AnsiStringArray; const IsSorted: Boolean);
  2055. var I, C, J, L : Integer;
  2056. F : AnsiString;
  2057. begin
  2058. L := Length(V);
  2059. if L = 0 then
  2060. exit;
  2061. if IsSorted then
  2062. begin
  2063. J := 0;
  2064. repeat
  2065. F := V[J];
  2066. I := J + 1;
  2067. while (I < L) and (V[I] = F) do
  2068. Inc(I);
  2069. C := I - J;
  2070. if C > 1 then
  2071. begin
  2072. DynArrayRemoveA(V, J + 1, C - 1);
  2073. Dec(L, C - 1);
  2074. Inc(J);
  2075. end
  2076. else
  2077. J := I;
  2078. until J >= L;
  2079. end else
  2080. begin
  2081. J := 0;
  2082. repeat
  2083. repeat
  2084. I := DynArrayPosNextA(V[J], V, J);
  2085. if I >= 0 then
  2086. DynArrayRemoveA(V, I, 1);
  2087. until I < 0;
  2088. Inc(J);
  2089. until J >= Length(V);
  2090. end;
  2091. end;
  2092. procedure DynArrayRemoveDuplicatesW(var V: WideStringArray; const IsSorted: Boolean);
  2093. var I, C, J, L : Integer;
  2094. F : WideString;
  2095. begin
  2096. L := Length(V);
  2097. if L = 0 then
  2098. exit;
  2099. if IsSorted then
  2100. begin
  2101. J := 0;
  2102. repeat
  2103. F := V[J];
  2104. I := J + 1;
  2105. while (I < L) and (V[I] = F) do
  2106. Inc(I);
  2107. C := I - J;
  2108. if C > 1 then
  2109. begin
  2110. DynArrayRemoveW(V, J + 1, C - 1);
  2111. Dec(L, C - 1);
  2112. Inc(J);
  2113. end
  2114. else
  2115. J := I;
  2116. until J >= L;
  2117. end else
  2118. begin
  2119. J := 0;
  2120. repeat
  2121. repeat
  2122. I := DynArrayPosNextW(V[J], V, J);
  2123. if I >= 0 then
  2124. DynArrayRemoveW(V, I, 1);
  2125. until I < 0;
  2126. Inc(J);
  2127. until J >= Length(V);
  2128. end;
  2129. end;
  2130. procedure DynArrayRemoveDuplicatesU(var V: UnicodeStringArray; const IsSorted: Boolean);
  2131. var I, C, J, L : Integer;
  2132. F : UnicodeString;
  2133. begin
  2134. L := Length(V);
  2135. if L = 0 then
  2136. exit;
  2137. if IsSorted then
  2138. begin
  2139. J := 0;
  2140. repeat
  2141. F := V[J];
  2142. I := J + 1;
  2143. while (I < L) and (V[I] = F) do
  2144. Inc(I);
  2145. C := I - J;
  2146. if C > 1 then
  2147. begin
  2148. DynArrayRemoveU(V, J + 1, C - 1);
  2149. Dec(L, C - 1);
  2150. Inc(J);
  2151. end
  2152. else
  2153. J := I;
  2154. until J >= L;
  2155. end else
  2156. begin
  2157. J := 0;
  2158. repeat
  2159. repeat
  2160. I := DynArrayPosNextU(V[J], V, J);
  2161. if I >= 0 then
  2162. DynArrayRemoveU(V, I, 1);
  2163. until I < 0;
  2164. Inc(J);
  2165. until J >= Length(V);
  2166. end;
  2167. end;
  2168. procedure DynArrayRemoveDuplicates(var V: StringArray; const IsSorted: Boolean);
  2169. var I, C, J, L : Integer;
  2170. F : String;
  2171. begin
  2172. L := Length(V);
  2173. if L = 0 then
  2174. exit;
  2175. if IsSorted then
  2176. begin
  2177. J := 0;
  2178. repeat
  2179. F := V[J];
  2180. I := J + 1;
  2181. while (I < L) and (V[I] = F) do
  2182. Inc(I);
  2183. C := I - J;
  2184. if C > 1 then
  2185. begin
  2186. DynArrayRemove(V, J + 1, C - 1);
  2187. Dec(L, C - 1);
  2188. Inc(J);
  2189. end
  2190. else
  2191. J := I;
  2192. until J >= L;
  2193. end else
  2194. begin
  2195. J := 0;
  2196. repeat
  2197. repeat
  2198. I := DynArrayPosNext(V[J], V, J);
  2199. if I >= 0 then
  2200. DynArrayRemove(V, I, 1);
  2201. until I < 0;
  2202. Inc(J);
  2203. until J >= Length(V);
  2204. end;
  2205. end;
  2206. {$IFNDEF ManagedCode}
  2207. procedure DynArrayRemoveDuplicates(var V: PointerArray; const IsSorted: Boolean);
  2208. var I, C, J, L : Integer;
  2209. F : Pointer;
  2210. begin
  2211. L := Length(V);
  2212. if L = 0 then
  2213. exit;
  2214. if IsSorted then
  2215. begin
  2216. J := 0;
  2217. repeat
  2218. F := V[J];
  2219. I := J + 1;
  2220. while (I < L) and (V[I] = F) do
  2221. Inc(I);
  2222. C := I - J;
  2223. if C > 1 then
  2224. begin
  2225. DynArrayRemove(V, J + 1, C - 1);
  2226. Dec(L, C - 1);
  2227. Inc(J);
  2228. end
  2229. else
  2230. J := I;
  2231. until J >= L;
  2232. end else
  2233. begin
  2234. J := 0;
  2235. repeat
  2236. repeat
  2237. I := DynArrayPosNext(V[J], V, J);
  2238. if I >= 0 then
  2239. DynArrayRemove(V, I, 1);
  2240. until I < 0;
  2241. Inc(J);
  2242. until J >= Length(V);
  2243. end;
  2244. end;
  2245. {$ENDIF}
  2246. procedure DynArrayTrimLeft(var S: ByteArray; const TrimList: array of Byte); overload;
  2247. var I, J : Integer;
  2248. R : Boolean;
  2249. begin
  2250. I := 0;
  2251. R := True;
  2252. while R and (I < Length(S)) do
  2253. begin
  2254. R := False;
  2255. for J := 0 to High(TrimList) do
  2256. if S[I] = TrimList[J] then
  2257. begin
  2258. R := True;
  2259. Inc(I);
  2260. break;
  2261. end;
  2262. end;
  2263. if I > 0 then
  2264. DynArrayRemove(S, 0, I - 1);
  2265. end;
  2266. procedure DynArrayTrimLeft(var S: WordArray; const TrimList: array of Word); overload;
  2267. var I, J : Integer;
  2268. R : Boolean;
  2269. begin
  2270. I := 0;
  2271. R := True;
  2272. while R and (I < Length(S)) do
  2273. begin
  2274. R := False;
  2275. for J := 0 to High(TrimList) do
  2276. if S[I] = TrimList[J] then
  2277. begin
  2278. R := True;
  2279. Inc(I);
  2280. break;
  2281. end;
  2282. end;
  2283. if I > 0 then
  2284. DynArrayRemove(S, 0, I - 1);
  2285. end;
  2286. procedure DynArrayTrimLeft(var S: LongWordArray; const TrimList: array of LongWord); overload;
  2287. var I, J : Integer;
  2288. R : Boolean;
  2289. begin
  2290. I := 0;
  2291. R := True;
  2292. while R and (I < Length(S)) do
  2293. begin
  2294. R := False;
  2295. for J := 0 to High(TrimList) do
  2296. if S[I] = TrimList[J] then
  2297. begin
  2298. R := True;
  2299. Inc(I);
  2300. break;
  2301. end;
  2302. end;
  2303. if I > 0 then
  2304. DynArrayRemove(S, 0, I - 1);
  2305. end;
  2306. procedure DynArrayTrimLeft(var S: ShortIntArray; const TrimList: array of ShortInt); overload;
  2307. var I, J : Integer;
  2308. R : Boolean;
  2309. begin
  2310. I := 0;
  2311. R := True;
  2312. while R and (I < Length(S)) do
  2313. begin
  2314. R := False;
  2315. for J := 0 to High(TrimList) do
  2316. if S[I] = TrimList[J] then
  2317. begin
  2318. R := True;
  2319. Inc(I);
  2320. break;
  2321. end;
  2322. end;
  2323. if I > 0 then
  2324. DynArrayRemove(S, 0, I - 1);
  2325. end;
  2326. procedure DynArrayTrimLeft(var S: SmallIntArray; const TrimList: array of SmallInt); overload;
  2327. var I, J : Integer;
  2328. R : Boolean;
  2329. begin
  2330. I := 0;
  2331. R := True;
  2332. while R and (I < Length(S)) do
  2333. begin
  2334. R := False;
  2335. for J := 0 to High(TrimList) do
  2336. if S[I] = TrimList[J] then
  2337. begin
  2338. R := True;
  2339. Inc(I);
  2340. break;
  2341. end;
  2342. end;
  2343. if I > 0 then
  2344. DynArrayRemove(S, 0, I - 1);
  2345. end;
  2346. procedure DynArrayTrimLeft(var S: LongIntArray; const TrimList: array of LongInt); overload;
  2347. var I, J : Integer;
  2348. R : Boolean;
  2349. begin
  2350. I := 0;
  2351. R := True;
  2352. while R and (I < Length(S)) do
  2353. begin
  2354. R := False;
  2355. for J := 0 to High(TrimList) do
  2356. if S[I] = TrimList[J] then
  2357. begin
  2358. R := True;
  2359. Inc(I);
  2360. break;
  2361. end;
  2362. end;
  2363. if I > 0 then
  2364. DynArrayRemove(S, 0, I - 1);
  2365. end;
  2366. procedure DynArrayTrimLeft(var S: Int64Array; const TrimList: array of Int64); overload;
  2367. var I, J : Integer;
  2368. R : Boolean;
  2369. begin
  2370. I := 0;
  2371. R := True;
  2372. while R and (I < Length(S)) do
  2373. begin
  2374. R := False;
  2375. for J := 0 to High(TrimList) do
  2376. if S[I] = TrimList[J] then
  2377. begin
  2378. R := True;
  2379. Inc(I);
  2380. break;
  2381. end;
  2382. end;
  2383. if I > 0 then
  2384. DynArrayRemove(S, 0, I - 1);
  2385. end;
  2386. procedure DynArrayTrimLeft(var S: SingleArray; const TrimList: array of Single); overload;
  2387. var I, J : Integer;
  2388. R : Boolean;
  2389. begin
  2390. I := 0;
  2391. R := True;
  2392. while R and (I < Length(S)) do
  2393. begin
  2394. R := False;
  2395. for J := 0 to High(TrimList) do
  2396. if S[I] = TrimList[J] then
  2397. begin
  2398. R := True;
  2399. Inc(I);
  2400. break;
  2401. end;
  2402. end;
  2403. if I > 0 then
  2404. DynArrayRemove(S, 0, I - 1);
  2405. end;
  2406. procedure DynArrayTrimLeft(var S: DoubleArray; const TrimList: array of Double); overload;
  2407. var I, J : Integer;
  2408. R : Boolean;
  2409. begin
  2410. I := 0;
  2411. R := True;
  2412. while R and (I < Length(S)) do
  2413. begin
  2414. R := False;
  2415. for J := 0 to High(TrimList) do
  2416. if S[I] = TrimList[J] then
  2417. begin
  2418. R := True;
  2419. Inc(I);
  2420. break;
  2421. end;
  2422. end;
  2423. if I > 0 then
  2424. DynArrayRemove(S, 0, I - 1);
  2425. end;
  2426. procedure DynArrayTrimLeft(var S: ExtendedArray; const TrimList: array of Extended); overload;
  2427. var I, J : Integer;
  2428. R : Boolean;
  2429. begin
  2430. I := 0;
  2431. R := True;
  2432. while R and (I < Length(S)) do
  2433. begin
  2434. R := False;
  2435. for J := 0 to High(TrimList) do
  2436. if S[I] = TrimList[J] then
  2437. begin
  2438. R := True;
  2439. Inc(I);
  2440. break;
  2441. end;
  2442. end;
  2443. if I > 0 then
  2444. DynArrayRemove(S, 0, I - 1);
  2445. end;
  2446. procedure DynArrayTrimLeftA(var S: AnsiStringArray; const TrimList: array of AnsiString); overload;
  2447. var I, J : Integer;
  2448. R : Boolean;
  2449. begin
  2450. I := 0;
  2451. R := True;
  2452. while R and (I < Length(S)) do
  2453. begin
  2454. R := False;
  2455. for J := 0 to High(TrimList) do
  2456. if S[I] = TrimList[J] then
  2457. begin
  2458. R := True;
  2459. Inc(I);
  2460. break;
  2461. end;
  2462. end;
  2463. if I > 0 then
  2464. DynArrayRemoveA(S, 0, I - 1);
  2465. end;
  2466. procedure DynArrayTrimLeftW(var S: WideStringArray; const TrimList: array of WideString); overload;
  2467. var I, J : Integer;
  2468. R : Boolean;
  2469. begin
  2470. I := 0;
  2471. R := True;
  2472. while R and (I < Length(S)) do
  2473. begin
  2474. R := False;
  2475. for J := 0 to High(TrimList) do
  2476. if S[I] = TrimList[J] then
  2477. begin
  2478. R := True;
  2479. Inc(I);
  2480. break;
  2481. end;
  2482. end;
  2483. if I > 0 then
  2484. DynArrayRemoveW(S, 0, I - 1);
  2485. end;
  2486. procedure DynArrayTrimLeftU(var S: UnicodeStringArray; const TrimList: array of UnicodeString); overload;
  2487. var I, J : Integer;
  2488. R : Boolean;
  2489. begin
  2490. I := 0;
  2491. R := True;
  2492. while R and (I < Length(S)) do
  2493. begin
  2494. R := False;
  2495. for J := 0 to High(TrimList) do
  2496. if S[I] = TrimList[J] then
  2497. begin
  2498. R := True;
  2499. Inc(I);
  2500. break;
  2501. end;
  2502. end;
  2503. if I > 0 then
  2504. DynArrayRemoveU(S, 0, I - 1);
  2505. end;
  2506. procedure DynArrayTrimLeft(var S: StringArray; const TrimList: array of String); overload;
  2507. var I, J : Integer;
  2508. R : Boolean;
  2509. begin
  2510. I := 0;
  2511. R := True;
  2512. while R and (I < Length(S)) do
  2513. begin
  2514. R := False;
  2515. for J := 0 to High(TrimList) do
  2516. if S[I] = TrimList[J] then
  2517. begin
  2518. R := True;
  2519. Inc(I);
  2520. break;
  2521. end;
  2522. end;
  2523. if I > 0 then
  2524. DynArrayRemove(S, 0, I - 1);
  2525. end;
  2526. {$IFNDEF ManagedCode}
  2527. procedure DynArrayTrimLeft(var S: PointerArray; const TrimList: array of Pointer); overload;
  2528. var I, J : Integer;
  2529. R : Boolean;
  2530. begin
  2531. I := 0;
  2532. R := True;
  2533. while R and (I < Length(S)) do
  2534. begin
  2535. R := False;
  2536. for J := 0 to High(TrimList) do
  2537. if S[I] = TrimList[J] then
  2538. begin
  2539. R := True;
  2540. Inc(I);
  2541. break;
  2542. end;
  2543. end;
  2544. if I > 0 then
  2545. DynArrayRemove(S, 0, I - 1);
  2546. end;
  2547. {$ENDIF}
  2548. procedure DynArrayTrimRight(var S: ByteArray; const TrimList: array of Byte); overload;
  2549. var I, J : Integer;
  2550. R : Boolean;
  2551. begin
  2552. I := Length(S) - 1;
  2553. R := True;
  2554. while R and (I >= 0) do
  2555. begin
  2556. R := False;
  2557. for J := 0 to High(TrimList) do
  2558. if S[I] = TrimList[J] then
  2559. begin
  2560. R := True;
  2561. Dec(I);
  2562. break;
  2563. end;
  2564. end;
  2565. if I < Length(S) - 1 then
  2566. SetLength(S, I + 1);
  2567. end;
  2568. procedure DynArrayTrimRight(var S: WordArray; const TrimList: array of Word); overload;
  2569. var I, J : Integer;
  2570. R : Boolean;
  2571. begin
  2572. I := Length(S) - 1;
  2573. R := True;
  2574. while R and (I >= 0) do
  2575. begin
  2576. R := False;
  2577. for J := 0 to High(TrimList) do
  2578. if S[I] = TrimList[J] then
  2579. begin
  2580. R := True;
  2581. Dec(I);
  2582. break;
  2583. end;
  2584. end;
  2585. if I < Length(S) - 1 then
  2586. SetLength(S, I + 1);
  2587. end;
  2588. procedure DynArrayTrimRight(var S: LongWordArray; const TrimList: array of LongWord); overload;
  2589. var I, J : Integer;
  2590. R : Boolean;
  2591. begin
  2592. I := Length(S) - 1;
  2593. R := True;
  2594. while R and (I >= 0) do
  2595. begin
  2596. R := False;
  2597. for J := 0 to High(TrimList) do
  2598. if S[I] = TrimList[J] then
  2599. begin
  2600. R := True;
  2601. Dec(I);
  2602. break;
  2603. end;
  2604. end;
  2605. if I < Length(S) - 1 then
  2606. SetLength(S, I + 1);
  2607. end;
  2608. procedure DynArrayTrimRight(var S: ShortIntArray; const TrimList: array of ShortInt); overload;
  2609. var I, J : Integer;
  2610. R : Boolean;
  2611. begin
  2612. I := Length(S) - 1;
  2613. R := True;
  2614. while R and (I >= 0) do
  2615. begin
  2616. R := False;
  2617. for J := 0 to High(TrimList) do
  2618. if S[I] = TrimList[J] then
  2619. begin
  2620. R := True;
  2621. Dec(I);
  2622. break;
  2623. end;
  2624. end;
  2625. if I < Length(S) - 1 then
  2626. SetLength(S, I + 1);
  2627. end;
  2628. procedure DynArrayTrimRight(var S: SmallIntArray; const TrimList: array of SmallInt); overload;
  2629. var I, J : Integer;
  2630. R : Boolean;
  2631. begin
  2632. I := Length(S) - 1;
  2633. R := True;
  2634. while R and (I >= 0) do
  2635. begin
  2636. R := False;
  2637. for J := 0 to High(TrimList) do
  2638. if S[I] = TrimList[J] then
  2639. begin
  2640. R := True;
  2641. Dec(I);
  2642. break;
  2643. end;
  2644. end;
  2645. if I < Length(S) - 1 then
  2646. SetLength(S, I + 1);
  2647. end;
  2648. procedure DynArrayTrimRight(var S: LongIntArray; const TrimList: array of LongInt); overload;
  2649. var I, J : Integer;
  2650. R : Boolean;
  2651. begin
  2652. I := Length(S) - 1;
  2653. R := True;
  2654. while R and (I >= 0) do
  2655. begin
  2656. R := False;
  2657. for J := 0 to High(TrimList) do
  2658. if S[I] = TrimList[J] then
  2659. begin
  2660. R := True;
  2661. Dec(I);
  2662. break;
  2663. end;
  2664. end;
  2665. if I < Length(S) - 1 then
  2666. SetLength(S, I + 1);
  2667. end;
  2668. procedure DynArrayTrimRight(var S: Int64Array; const TrimList: array of Int64); overload;
  2669. var I, J : Integer;
  2670. R : Boolean;
  2671. begin
  2672. I := Length(S) - 1;
  2673. R := True;
  2674. while R and (I >= 0) do
  2675. begin
  2676. R := False;
  2677. for J := 0 to High(TrimList) do
  2678. if S[I] = TrimList[J] then
  2679. begin
  2680. R := True;
  2681. Dec(I);
  2682. break;
  2683. end;
  2684. end;
  2685. if I < Length(S) - 1 then
  2686. SetLength(S, I + 1);
  2687. end;
  2688. procedure DynArrayTrimRight(var S: SingleArray; const TrimList: array of Single); overload;
  2689. var I, J : Integer;
  2690. R : Boolean;
  2691. begin
  2692. I := Length(S) - 1;
  2693. R := True;
  2694. while R and (I >= 0) do
  2695. begin
  2696. R := False;
  2697. for J := 0 to High(TrimList) do
  2698. if S[I] = TrimList[J] then
  2699. begin
  2700. R := True;
  2701. Dec(I);
  2702. break;
  2703. end;
  2704. end;
  2705. if I < Length(S) - 1 then
  2706. SetLength(S, I + 1);
  2707. end;
  2708. procedure DynArrayTrimRight(var S: DoubleArray; const TrimList: array of Double); overload;
  2709. var I, J : Integer;
  2710. R : Boolean;
  2711. begin
  2712. I := Length(S) - 1;
  2713. R := True;
  2714. while R and (I >= 0) do
  2715. begin
  2716. R := False;
  2717. for J := 0 to High(TrimList) do
  2718. if S[I] = TrimList[J] then
  2719. begin
  2720. R := True;
  2721. Dec(I);
  2722. break;
  2723. end;
  2724. end;
  2725. if I < Length(S) - 1 then
  2726. SetLength(S, I + 1);
  2727. end;
  2728. procedure DynArrayTrimRight(var S: ExtendedArray; const TrimList: array of Extended); overload;
  2729. var I, J : Integer;
  2730. R : Boolean;
  2731. begin
  2732. I := Length(S) - 1;
  2733. R := True;
  2734. while R and (I >= 0) do
  2735. begin
  2736. R := False;
  2737. for J := 0 to High(TrimList) do
  2738. if S[I] = TrimList[J] then
  2739. begin
  2740. R := True;
  2741. Dec(I);
  2742. break;
  2743. end;
  2744. end;
  2745. if I < Length(S) - 1 then
  2746. SetLength(S, I + 1);
  2747. end;
  2748. procedure DynArrayTrimRightA(var S: AnsiStringArray; const TrimList: array of AnsiString); overload;
  2749. var I, J : Integer;
  2750. R : Boolean;
  2751. begin
  2752. I := Length(S) - 1;
  2753. R := True;
  2754. while R and (I >= 0) do
  2755. begin
  2756. R := False;
  2757. for J := 0 to High(TrimList) do
  2758. if S[I] = TrimList[J] then
  2759. begin
  2760. R := True;
  2761. Dec(I);
  2762. break;
  2763. end;
  2764. end;
  2765. if I < Length(S) - 1 then
  2766. SetLength(S, I + 1);
  2767. end;
  2768. procedure DynArrayTrimRightW(var S: WideStringArray; const TrimList: array of WideString); overload;
  2769. var I, J : Integer;
  2770. R : Boolean;
  2771. begin
  2772. I := Length(S) - 1;
  2773. R := True;
  2774. while R and (I >= 0) do
  2775. begin
  2776. R := False;
  2777. for J := 0 to High(TrimList) do
  2778. if S[I] = TrimList[J] then
  2779. begin
  2780. R := True;
  2781. Dec(I);
  2782. break;
  2783. end;
  2784. end;
  2785. if I < Length(S) - 1 then
  2786. SetLength(S, I + 1);
  2787. end;
  2788. procedure DynArrayTrimRightU(var S: UnicodeStringArray; const TrimList: array of UnicodeString); overload;
  2789. var I, J : Integer;
  2790. R : Boolean;
  2791. begin
  2792. I := Length(S) - 1;
  2793. R := True;
  2794. while R and (I >= 0) do
  2795. begin
  2796. R := False;
  2797. for J := 0 to High(TrimList) do
  2798. if S[I] = TrimList[J] then
  2799. begin
  2800. R := True;
  2801. Dec(I);
  2802. break;
  2803. end;
  2804. end;
  2805. if I < Length(S) - 1 then
  2806. SetLength(S, I + 1);
  2807. end;
  2808. procedure DynArrayTrimRight(var S: StringArray; const TrimList: array of String); overload;
  2809. var I, J : Integer;
  2810. R : Boolean;
  2811. begin
  2812. I := Length(S) - 1;
  2813. R := True;
  2814. while R and (I >= 0) do
  2815. begin
  2816. R := False;
  2817. for J := 0 to High(TrimList) do
  2818. if S[I] = TrimList[J] then
  2819. begin
  2820. R := True;
  2821. Dec(I);
  2822. break;
  2823. end;
  2824. end;
  2825. if I < Length(S) - 1 then
  2826. SetLength(S, I + 1);
  2827. end;
  2828. {$IFNDEF ManagedCode}
  2829. procedure DynArrayTrimRight(var S: PointerArray; const TrimList: array of Pointer); overload;
  2830. var I, J : Integer;
  2831. R : Boolean;
  2832. begin
  2833. I := Length(S) - 1;
  2834. R := True;
  2835. while R and (I >= 0) do
  2836. begin
  2837. R := False;
  2838. for J := 0 to High(TrimList) do
  2839. if S[I] = TrimList[J] then
  2840. begin
  2841. R := True;
  2842. Dec(I);
  2843. break;
  2844. end;
  2845. end;
  2846. if I < Length(S) - 1 then
  2847. SetLength(S, I + 1);
  2848. end;
  2849. {$ENDIF}
  2850. { }
  2851. { DynArrayInsert }
  2852. { }
  2853. {$IFDEF ManagedCode}
  2854. function DynArrayInsert(var V: ByteArray; const Idx: Integer; const Count: Integer): Integer;
  2855. var I, L, J : Integer;
  2856. begin
  2857. L := Length(V);
  2858. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2859. begin
  2860. Result := -1;
  2861. exit;
  2862. end;
  2863. SetLength(V, L + Count);
  2864. I := Idx;
  2865. if I < 0 then
  2866. I := 0;
  2867. for J := 0 to L - I - 1 do
  2868. V[I + Count + J] := V[I + J];
  2869. for J := 0 to Count - 1 do
  2870. V[I + J] := 0;
  2871. Result := I;
  2872. end;
  2873. {$ELSE}
  2874. function DynArrayInsert(var V: ByteArray; const Idx: Integer; const Count: Integer): Integer;
  2875. var I, L : Integer;
  2876. P : Pointer;
  2877. begin
  2878. L := Length(V);
  2879. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2880. begin
  2881. Result := -1;
  2882. exit;
  2883. end;
  2884. SetLength(V, L + Count);
  2885. I := Idx;
  2886. if I < 0 then
  2887. I := 0;
  2888. P := @V[I];
  2889. if I < L then
  2890. Move(P^, V[I + Count], (L - I) * Sizeof(Byte));
  2891. FillChar(P^, Count * Sizeof(Byte), #0);
  2892. Result := I;
  2893. end;
  2894. {$ENDIF}
  2895. {$IFDEF ManagedCode}
  2896. function DynArrayInsert(var V: WordArray; const Idx: Integer; const Count: Integer): Integer;
  2897. var I, L, J : Integer;
  2898. begin
  2899. L := Length(V);
  2900. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2901. begin
  2902. Result := -1;
  2903. exit;
  2904. end;
  2905. SetLength(V, L + Count);
  2906. I := Idx;
  2907. if I < 0 then
  2908. I := 0;
  2909. for J := 0 to L - I - 1 do
  2910. V[I + Count + J] := V[I + J];
  2911. for J := 0 to Count - 1 do
  2912. V[I + J] := 0;
  2913. Result := I;
  2914. end;
  2915. {$ELSE}
  2916. function DynArrayInsert(var V: WordArray; const Idx: Integer; const Count: Integer): Integer;
  2917. var I, L : Integer;
  2918. P : Pointer;
  2919. begin
  2920. L := Length(V);
  2921. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2922. begin
  2923. Result := -1;
  2924. exit;
  2925. end;
  2926. SetLength(V, L + Count);
  2927. I := Idx;
  2928. if I < 0 then
  2929. I := 0;
  2930. P := @V[I];
  2931. if I < L then
  2932. Move(P^, V[I + Count], (L - I) * Sizeof(Word));
  2933. FillChar(P^, Count * Sizeof(Word), #0);
  2934. Result := I;
  2935. end;
  2936. {$ENDIF}
  2937. {$IFDEF ManagedCode}
  2938. function DynArrayInsert(var V: LongWordArray; const Idx: Integer; const Count: Integer): Integer;
  2939. var I, L, J : Integer;
  2940. begin
  2941. L := Length(V);
  2942. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2943. begin
  2944. Result := -1;
  2945. exit;
  2946. end;
  2947. SetLength(V, L + Count);
  2948. I := Idx;
  2949. if I < 0 then
  2950. I := 0;
  2951. for J := 0 to L - I - 1 do
  2952. V[I + Count + J] := V[I + J];
  2953. for J := 0 to Count - 1 do
  2954. V[I + J] := 0;
  2955. Result := I;
  2956. end;
  2957. {$ELSE}
  2958. function DynArrayInsert(var V: LongWordArray; const Idx: Integer; const Count: Integer): Integer;
  2959. var I, L : Integer;
  2960. P : Pointer;
  2961. begin
  2962. L := Length(V);
  2963. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2964. begin
  2965. Result := -1;
  2966. exit;
  2967. end;
  2968. SetLength(V, L + Count);
  2969. I := Idx;
  2970. if I < 0 then
  2971. I := 0;
  2972. P := @V[I];
  2973. if I < L then
  2974. Move(P^, V[I + Count], (L - I) * Sizeof(LongWord));
  2975. FillChar(P^, Count * Sizeof(LongWord), #0);
  2976. Result := I;
  2977. end;
  2978. {$ENDIF}
  2979. {$IFDEF ManagedCode}
  2980. function DynArrayInsert(var V: NativeUIntArray; const Idx: Integer; const Count: Integer): Integer;
  2981. var I, L, J : Integer;
  2982. begin
  2983. L := Length(V);
  2984. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  2985. begin
  2986. Result := -1;
  2987. exit;
  2988. end;
  2989. SetLength(V, L + Count);
  2990. I := Idx;
  2991. if I < 0 then
  2992. I := 0;
  2993. for J := 0 to L - I - 1 do
  2994. V[I + Count + J] := V[I + J];
  2995. for J := 0 to Count - 1 do
  2996. V[I + J] := 0;
  2997. Result := I;
  2998. end;
  2999. {$ELSE}
  3000. function DynArrayInsert(var V: NativeUIntArray; const Idx: Integer; const Count: Integer): Integer;
  3001. var I, L : Integer;
  3002. P : Pointer;
  3003. begin
  3004. L := Length(V);
  3005. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3006. begin
  3007. Result := -1;
  3008. exit;
  3009. end;
  3010. SetLength(V, L + Count);
  3011. I := Idx;
  3012. if I < 0 then
  3013. I := 0;
  3014. P := @V[I];
  3015. if I < L then
  3016. Move(P^, V[I + Count], (L - I) * Sizeof(NativeUInt));
  3017. FillChar(P^, Count * Sizeof(NativeUInt), #0);
  3018. Result := I;
  3019. end;
  3020. {$ENDIF}
  3021. {$IFDEF ManagedCode}
  3022. function DynArrayInsert(var V: ShortIntArray; const Idx: Integer; const Count: Integer): Integer;
  3023. var I, L, J : Integer;
  3024. begin
  3025. L := Length(V);
  3026. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3027. begin
  3028. Result := -1;
  3029. exit;
  3030. end;
  3031. SetLength(V, L + Count);
  3032. I := Idx;
  3033. if I < 0 then
  3034. I := 0;
  3035. for J := 0 to L - I - 1 do
  3036. V[I + Count + J] := V[I + J];
  3037. for J := 0 to Count - 1 do
  3038. V[I + J] := 0;
  3039. Result := I;
  3040. end;
  3041. {$ELSE}
  3042. function DynArrayInsert(var V: ShortIntArray; const Idx: Integer; const Count: Integer): Integer;
  3043. var I, L : Integer;
  3044. P : Pointer;
  3045. begin
  3046. L := Length(V);
  3047. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3048. begin
  3049. Result := -1;
  3050. exit;
  3051. end;
  3052. SetLength(V, L + Count);
  3053. I := Idx;
  3054. if I < 0 then
  3055. I := 0;
  3056. P := @V[I];
  3057. if I < L then
  3058. Move(P^, V[I + Count], (L - I) * Sizeof(ShortInt));
  3059. FillChar(P^, Count * Sizeof(ShortInt), #0);
  3060. Result := I;
  3061. end;
  3062. {$ENDIF}
  3063. {$IFDEF ManagedCode}
  3064. function DynArrayInsert(var V: SmallIntArray; const Idx: Integer; const Count: Integer): Integer;
  3065. var I, L, J : Integer;
  3066. begin
  3067. L := Length(V);
  3068. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3069. begin
  3070. Result := -1;
  3071. exit;
  3072. end;
  3073. SetLength(V, L + Count);
  3074. I := Idx;
  3075. if I < 0 then
  3076. I := 0;
  3077. for J := 0 to L - I - 1 do
  3078. V[I + Count + J] := V[I + J];
  3079. for J := 0 to Count - 1 do
  3080. V[I + J] := 0;
  3081. Result := I;
  3082. end;
  3083. {$ELSE}
  3084. function DynArrayInsert(var V: SmallIntArray; const Idx: Integer; const Count: Integer): Integer;
  3085. var I, L : Integer;
  3086. P : Pointer;
  3087. begin
  3088. L := Length(V);
  3089. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3090. begin
  3091. Result := -1;
  3092. exit;
  3093. end;
  3094. SetLength(V, L + Count);
  3095. I := Idx;
  3096. if I < 0 then
  3097. I := 0;
  3098. P := @V[I];
  3099. if I < L then
  3100. Move(P^, V[I + Count], (L - I) * Sizeof(SmallInt));
  3101. FillChar(P^, Count * Sizeof(SmallInt), #0);
  3102. Result := I;
  3103. end;
  3104. {$ENDIF}
  3105. {$IFDEF ManagedCode}
  3106. function DynArrayInsert(var V: LongIntArray; const Idx: Integer; const Count: Integer): Integer;
  3107. var I, L, J : Integer;
  3108. begin
  3109. L := Length(V);
  3110. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3111. begin
  3112. Result := -1;
  3113. exit;
  3114. end;
  3115. SetLength(V, L + Count);
  3116. I := Idx;
  3117. if I < 0 then
  3118. I := 0;
  3119. for J := 0 to L - I - 1 do
  3120. V[I + Count + J] := V[I + J];
  3121. for J := 0 to Count - 1 do
  3122. V[I + J] := 0;
  3123. Result := I;
  3124. end;
  3125. {$ELSE}
  3126. function DynArrayInsert(var V: LongIntArray; const Idx: Integer; const Count: Integer): Integer;
  3127. var I, L : Integer;
  3128. P : Pointer;
  3129. begin
  3130. L := Length(V);
  3131. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3132. begin
  3133. Result := -1;
  3134. exit;
  3135. end;
  3136. SetLength(V, L + Count);
  3137. I := Idx;
  3138. if I < 0 then
  3139. I := 0;
  3140. P := @V[I];
  3141. if I < L then
  3142. Move(P^, V[I + Count], (L - I) * Sizeof(LongInt));
  3143. FillChar(P^, Count * Sizeof(LongInt), #0);
  3144. Result := I;
  3145. end;
  3146. {$ENDIF}
  3147. {$IFDEF ManagedCode}
  3148. function DynArrayInsert(var V: Int64Array; const Idx: Integer; const Count: Integer): Integer;
  3149. var I, L, J : Integer;
  3150. begin
  3151. L := Length(V);
  3152. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3153. begin
  3154. Result := -1;
  3155. exit;
  3156. end;
  3157. SetLength(V, L + Count);
  3158. I := Idx;
  3159. if I < 0 then
  3160. I := 0;
  3161. for J := 0 to L - I - 1 do
  3162. V[I + Count + J] := V[I + J];
  3163. for J := 0 to Count - 1 do
  3164. V[I + J] := 0;
  3165. Result := I;
  3166. end;
  3167. {$ELSE}
  3168. function DynArrayInsert(var V: Int64Array; const Idx: Integer; const Count: Integer): Integer;
  3169. var I, L : Integer;
  3170. P : Pointer;
  3171. begin
  3172. L := Length(V);
  3173. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3174. begin
  3175. Result := -1;
  3176. exit;
  3177. end;
  3178. SetLength(V, L + Count);
  3179. I := Idx;
  3180. if I < 0 then
  3181. I := 0;
  3182. P := @V[I];
  3183. if I < L then
  3184. Move(P^, V[I + Count], (L - I) * Sizeof(Int64));
  3185. FillChar(P^, Count * Sizeof(Int64), #0);
  3186. Result := I;
  3187. end;
  3188. {$ENDIF}
  3189. {$IFDEF ManagedCode}
  3190. function DynArrayInsert(var V: NativeIntArray; const Idx: Integer; const Count: Integer): Integer;
  3191. var I, L, J : Integer;
  3192. begin
  3193. L := Length(V);
  3194. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3195. begin
  3196. Result := -1;
  3197. exit;
  3198. end;
  3199. SetLength(V, L + Count);
  3200. I := Idx;
  3201. if I < 0 then
  3202. I := 0;
  3203. for J := 0 to L - I - 1 do
  3204. V[I + Count + J] := V[I + J];
  3205. for J := 0 to Count - 1 do
  3206. V[I + J] := 0;
  3207. Result := I;
  3208. end;
  3209. {$ELSE}
  3210. function DynArrayInsert(var V: NativeIntArray; const Idx: Integer; const Count: Integer): Integer;
  3211. var I, L : Integer;
  3212. P : Pointer;
  3213. begin
  3214. L := Length(V);
  3215. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3216. begin
  3217. Result := -1;
  3218. exit;
  3219. end;
  3220. SetLength(V, L + Count);
  3221. I := Idx;
  3222. if I < 0 then
  3223. I := 0;
  3224. P := @V[I];
  3225. if I < L then
  3226. Move(P^, V[I + Count], (L - I) * Sizeof(NativeInt));
  3227. FillChar(P^, Count * Sizeof(NativeInt), #0);
  3228. Result := I;
  3229. end;
  3230. {$ENDIF}
  3231. {$IFDEF ManagedCode}
  3232. function DynArrayInsert(var V: SingleArray; const Idx: Integer; const Count: Integer): Integer;
  3233. var I, L, J : Integer;
  3234. begin
  3235. L := Length(V);
  3236. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3237. begin
  3238. Result := -1;
  3239. exit;
  3240. end;
  3241. SetLength(V, L + Count);
  3242. I := Idx;
  3243. if I < 0 then
  3244. I := 0;
  3245. for J := 0 to L - I - 1 do
  3246. V[I + Count + J] := V[I + J];
  3247. for J := 0 to Count - 1 do
  3248. V[I + J] := 0.0;
  3249. Result := I;
  3250. end;
  3251. {$ELSE}
  3252. function DynArrayInsert(var V: SingleArray; const Idx: Integer; const Count: Integer): Integer;
  3253. var I, L : Integer;
  3254. P : Pointer;
  3255. begin
  3256. L := Length(V);
  3257. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3258. begin
  3259. Result := -1;
  3260. exit;
  3261. end;
  3262. SetLength(V, L + Count);
  3263. I := Idx;
  3264. if I < 0 then
  3265. I := 0;
  3266. P := @V[I];
  3267. if I < L then
  3268. Move(P^, V[I + Count], (L - I) * Sizeof(Single));
  3269. FillChar(P^, Count * Sizeof(Single), #0);
  3270. Result := I;
  3271. end;
  3272. {$ENDIF}
  3273. {$IFDEF ManagedCode}
  3274. function DynArrayInsert(var V: DoubleArray; const Idx: Integer; const Count: Integer): Integer;
  3275. var I, L, J : Integer;
  3276. begin
  3277. L := Length(V);
  3278. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3279. begin
  3280. Result := -1;
  3281. exit;
  3282. end;
  3283. SetLength(V, L + Count);
  3284. I := Idx;
  3285. if I < 0 then
  3286. I := 0;
  3287. for J := 0 to L - I - 1 do
  3288. V[I + Count + J] := V[I + J];
  3289. for J := 0 to Count - 1 do
  3290. V[I + J] := 0.0;
  3291. Result := I;
  3292. end;
  3293. {$ELSE}
  3294. function DynArrayInsert(var V: DoubleArray; const Idx: Integer; const Count: Integer): Integer;
  3295. var I, L : Integer;
  3296. P : Pointer;
  3297. begin
  3298. L := Length(V);
  3299. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3300. begin
  3301. Result := -1;
  3302. exit;
  3303. end;
  3304. SetLength(V, L + Count);
  3305. I := Idx;
  3306. if I < 0 then
  3307. I := 0;
  3308. P := @V[I];
  3309. if I < L then
  3310. Move(P^, V[I + Count], (L - I) * Sizeof(Double));
  3311. FillChar(P^, Count * Sizeof(Double), #0);
  3312. Result := I;
  3313. end;
  3314. {$ENDIF}
  3315. {$IFDEF ManagedCode}
  3316. function DynArrayInsert(var V: ExtendedArray; const Idx: Integer; const Count: Integer): Integer;
  3317. var I, L, J : Integer;
  3318. begin
  3319. L := Length(V);
  3320. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3321. begin
  3322. Result := -1;
  3323. exit;
  3324. end;
  3325. SetLength(V, L + Count);
  3326. I := Idx;
  3327. if I < 0 then
  3328. I := 0;
  3329. for J := 0 to L - I - 1 do
  3330. V[I + Count + J] := V[I + J];
  3331. for J := 0 to Count - 1 do
  3332. V[I + J] := 0.0;
  3333. Result := I;
  3334. end;
  3335. {$ELSE}
  3336. function DynArrayInsert(var V: ExtendedArray; const Idx: Integer; const Count: Integer): Integer;
  3337. var I, L : Integer;
  3338. P : Pointer;
  3339. begin
  3340. L := Length(V);
  3341. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3342. begin
  3343. Result := -1;
  3344. exit;
  3345. end;
  3346. SetLength(V, L + Count);
  3347. I := Idx;
  3348. if I < 0 then
  3349. I := 0;
  3350. P := @V[I];
  3351. if I < L then
  3352. Move(P^, V[I + Count], (L - I) * Sizeof(Extended));
  3353. FillChar(P^, Count * Sizeof(Extended), #0);
  3354. Result := I;
  3355. end;
  3356. {$ENDIF}
  3357. {$IFDEF ManagedCode}
  3358. function DynArrayInsert(var V: CurrencyArray; const Idx: Integer; const Count: Integer): Integer;
  3359. var I, L, J : Integer;
  3360. begin
  3361. L := Length(V);
  3362. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3363. begin
  3364. Result := -1;
  3365. exit;
  3366. end;
  3367. SetLength(V, L + Count);
  3368. I := Idx;
  3369. if I < 0 then
  3370. I := 0;
  3371. for J := 0 to L - I - 1 do
  3372. V[I + Count + J] := V[I + J];
  3373. for J := 0 to Count - 1 do
  3374. V[I + J] := 0.0;
  3375. Result := I;
  3376. end;
  3377. {$ELSE}
  3378. function DynArrayInsert(var V: CurrencyArray; const Idx: Integer; const Count: Integer): Integer;
  3379. var I, L : Integer;
  3380. P : Pointer;
  3381. begin
  3382. L := Length(V);
  3383. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3384. begin
  3385. Result := -1;
  3386. exit;
  3387. end;
  3388. SetLength(V, L + Count);
  3389. I := Idx;
  3390. if I < 0 then
  3391. I := 0;
  3392. P := @V[I];
  3393. if I < L then
  3394. Move(P^, V[I + Count], (L - I) * Sizeof(Currency));
  3395. FillChar(P^, Count * Sizeof(Currency), #0);
  3396. Result := I;
  3397. end;
  3398. {$ENDIF}
  3399. {$IFDEF ManagedCode}
  3400. function DynArrayInsertA(var V: AnsiStringArray; const Idx: Integer; const Count: Integer): Integer;
  3401. var I, L, J : Integer;
  3402. begin
  3403. L := Length(V);
  3404. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3405. begin
  3406. Result := -1;
  3407. exit;
  3408. end;
  3409. SetLength(V, L + Count);
  3410. I := Idx;
  3411. if I < 0 then
  3412. I := 0;
  3413. for J := 0 to L - I - 1 do
  3414. V[I + Count + J] := V[I + J];
  3415. for J := 0 to Count - 1 do
  3416. V[I + J] := '';
  3417. Result := I;
  3418. end;
  3419. {$ELSE}
  3420. function DynArrayInsertA(var V: AnsiStringArray; const Idx: Integer; const Count: Integer): Integer;
  3421. var I, L : Integer;
  3422. P : Pointer;
  3423. begin
  3424. L := Length(V);
  3425. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3426. begin
  3427. Result := -1;
  3428. exit;
  3429. end;
  3430. SetLength(V, L + Count);
  3431. I := Idx;
  3432. if I < 0 then
  3433. I := 0;
  3434. P := @V[I];
  3435. if I < L then
  3436. Move(P^, V[I + Count], (L - I) * Sizeof(AnsiString));
  3437. FillChar(P^, Count * Sizeof(AnsiString), #0);
  3438. Result := I;
  3439. end;
  3440. {$ENDIF}
  3441. {$IFDEF ManagedCode}
  3442. function DynArrayInsertW(var V: WideStringArray; const Idx: Integer; const Count: Integer): Integer;
  3443. var I, L, J : Integer;
  3444. begin
  3445. L := Length(V);
  3446. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3447. begin
  3448. Result := -1;
  3449. exit;
  3450. end;
  3451. SetLength(V, L + Count);
  3452. I := Idx;
  3453. if I < 0 then
  3454. I := 0;
  3455. for J := 0 to L - I - 1 do
  3456. V[I + Count + J] := V[I + J];
  3457. for J := 0 to Count - 1 do
  3458. V[I + J] := '';
  3459. Result := I;
  3460. end;
  3461. {$ELSE}
  3462. function DynArrayInsertW(var V: WideStringArray; const Idx: Integer; const Count: Integer): Integer;
  3463. var I, L : Integer;
  3464. P : Pointer;
  3465. begin
  3466. L := Length(V);
  3467. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3468. begin
  3469. Result := -1;
  3470. exit;
  3471. end;
  3472. SetLength(V, L + Count);
  3473. I := Idx;
  3474. if I < 0 then
  3475. I := 0;
  3476. P := @V[I];
  3477. if I < L then
  3478. Move(P^, V[I + Count], (L - I) * Sizeof(WideString));
  3479. FillChar(P^, Count * Sizeof(WideString), #0);
  3480. Result := I;
  3481. end;
  3482. {$ENDIF}
  3483. {$IFDEF ManagedCode}
  3484. function DynArrayInsertU(var V: UnicodeStringArray; const Idx: Integer; const Count: Integer): Integer;
  3485. var I, L, J : Integer;
  3486. begin
  3487. L := Length(V);
  3488. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3489. begin
  3490. Result := -1;
  3491. exit;
  3492. end;
  3493. SetLength(V, L + Count);
  3494. I := Idx;
  3495. if I < 0 then
  3496. I := 0;
  3497. for J := 0 to L - I - 1 do
  3498. V[I + Count + J] := V[I + J];
  3499. for J := 0 to Count - 1 do
  3500. V[I + J] := '';
  3501. Result := I;
  3502. end;
  3503. {$ELSE}
  3504. function DynArrayInsertU(var V: UnicodeStringArray; const Idx: Integer; const Count: Integer): Integer;
  3505. var I, L : Integer;
  3506. P : Pointer;
  3507. begin
  3508. L := Length(V);
  3509. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3510. begin
  3511. Result := -1;
  3512. exit;
  3513. end;
  3514. SetLength(V, L + Count);
  3515. I := Idx;
  3516. if I < 0 then
  3517. I := 0;
  3518. P := @V[I];
  3519. if I < L then
  3520. Move(P^, V[I + Count], (L - I) * Sizeof(UnicodeString));
  3521. FillChar(P^, Count * Sizeof(UnicodeString), #0);
  3522. Result := I;
  3523. end;
  3524. {$ENDIF}
  3525. {$IFDEF ManagedCode}
  3526. function DynArrayInsert(var V: StringArray; const Idx: Integer; const Count: Integer): Integer;
  3527. var I, L, J : Integer;
  3528. begin
  3529. L := Length(V);
  3530. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3531. begin
  3532. Result := -1;
  3533. exit;
  3534. end;
  3535. SetLength(V, L + Count);
  3536. I := Idx;
  3537. if I < 0 then
  3538. I := 0;
  3539. for J := 0 to L - I - 1 do
  3540. V[I + Count + J] := V[I + J];
  3541. for J := 0 to Count - 1 do
  3542. V[I + J] := '';
  3543. Result := I;
  3544. end;
  3545. {$ELSE}
  3546. function DynArrayInsert(var V: StringArray; const Idx: Integer; const Count: Integer): Integer;
  3547. var I, L : Integer;
  3548. P : Pointer;
  3549. begin
  3550. L := Length(V);
  3551. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3552. begin
  3553. Result := -1;
  3554. exit;
  3555. end;
  3556. SetLength(V, L + Count);
  3557. I := Idx;
  3558. if I < 0 then
  3559. I := 0;
  3560. P := @V[I];
  3561. if I < L then
  3562. Move(P^, V[I + Count], (L - I) * Sizeof(String));
  3563. FillChar(P^, Count * Sizeof(String), #0);
  3564. Result := I;
  3565. end;
  3566. {$ENDIF}
  3567. {$IFNDEF ManagedCode}
  3568. {$IFDEF ManagedCode}
  3569. function DynArrayInsert(var V: PointerArray; const Idx: Integer; const Count: Integer): Integer;
  3570. var I, L, J : Integer;
  3571. begin
  3572. L := Length(V);
  3573. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3574. begin
  3575. Result := -1;
  3576. exit;
  3577. end;
  3578. SetLength(V, L + Count);
  3579. I := Idx;
  3580. if I < 0 then
  3581. I := 0;
  3582. for J := 0 to L - I - 1 do
  3583. V[I + Count + J] := V[I + J];
  3584. for J := 0 to Count - 1 do
  3585. V[I + J] := nil;
  3586. Result := I;
  3587. end;
  3588. {$ELSE}
  3589. function DynArrayInsert(var V: PointerArray; const Idx: Integer; const Count: Integer): Integer;
  3590. var I, L : Integer;
  3591. P : Pointer;
  3592. begin
  3593. L := Length(V);
  3594. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3595. begin
  3596. Result := -1;
  3597. exit;
  3598. end;
  3599. SetLength(V, L + Count);
  3600. I := Idx;
  3601. if I < 0 then
  3602. I := 0;
  3603. P := @V[I];
  3604. if I < L then
  3605. Move(P^, V[I + Count], (L - I) * Sizeof(Pointer));
  3606. FillChar(P^, Count * Sizeof(Pointer), #0);
  3607. Result := I;
  3608. end;
  3609. {$ENDIF}
  3610. {$IFDEF ManagedCode}
  3611. function DynArrayInsert(var V: ObjectArray; const Idx: Integer; const Count: Integer): Integer;
  3612. var I, L, J : Integer;
  3613. begin
  3614. L := Length(V);
  3615. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3616. begin
  3617. Result := -1;
  3618. exit;
  3619. end;
  3620. SetLength(V, L + Count);
  3621. I := Idx;
  3622. if I < 0 then
  3623. I := 0;
  3624. for J := 0 to L - I - 1 do
  3625. V[I + Count + J] := V[I + J];
  3626. for J := 0 to Count - 1 do
  3627. V[I + J] := nil;
  3628. Result := I;
  3629. end;
  3630. {$ELSE}
  3631. function DynArrayInsert(var V: ObjectArray; const Idx: Integer; const Count: Integer): Integer;
  3632. var I, L : Integer;
  3633. P : Pointer;
  3634. begin
  3635. L := Length(V);
  3636. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3637. begin
  3638. Result := -1;
  3639. exit;
  3640. end;
  3641. SetLength(V, L + Count);
  3642. I := Idx;
  3643. if I < 0 then
  3644. I := 0;
  3645. P := @V[I];
  3646. if I < L then
  3647. Move(P^, V[I + Count], (L - I) * Sizeof(Pointer));
  3648. FillChar(P^, Count * Sizeof(Pointer), #0);
  3649. Result := I;
  3650. end;
  3651. {$ENDIF}
  3652. {$ENDIF}
  3653. {$IFDEF ManagedCode}
  3654. function DynArrayInsert(var V: InterfaceArray; const Idx: Integer; const Count: Integer): Integer;
  3655. var I, L, J : Integer;
  3656. begin
  3657. L := Length(V);
  3658. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3659. begin
  3660. Result := -1;
  3661. exit;
  3662. end;
  3663. SetLength(V, L + Count);
  3664. I := Idx;
  3665. if I < 0 then
  3666. I := 0;
  3667. for J := 0 to L - I - 1 do
  3668. V[I + Count + J] := V[I + J];
  3669. for J := 0 to Count - 1 do
  3670. V[I + J] := nil;
  3671. Result := I;
  3672. end;
  3673. {$ELSE}
  3674. function DynArrayInsert(var V: InterfaceArray; const Idx: Integer; const Count: Integer): Integer;
  3675. var I, L : Integer;
  3676. P : Pointer;
  3677. begin
  3678. L := Length(V);
  3679. if (Idx > L) or (Idx + Count <= 0) or (Count <= 0) then
  3680. begin
  3681. Result := -1;
  3682. exit;
  3683. end;
  3684. SetLength(V, L + Count);
  3685. I := Idx;
  3686. if I < 0 then
  3687. I := 0;
  3688. P := @V[I];
  3689. if I < L then
  3690. Move(P^, V[I + Count], (L - I) * Sizeof(IInterface));
  3691. FillChar(P^, Count * Sizeof(IInterface), #0);
  3692. Result := I;
  3693. end;
  3694. {$ENDIF}
  3695. { }
  3696. { DynArrayPosNext }
  3697. { PosNext finds the next occurance of Find in V, -1 if it was not found. }
  3698. { Searches from Item[PrevPos + 1], ie PrevPos = -1 to find first }
  3699. { occurance. }
  3700. { }
  3701. function DynArrayPosNext(const Find: Byte; const V: ByteArray; const PrevPos: Integer;
  3702. const IsSortedAscending: Boolean): Integer;
  3703. var I, L, H : Integer;
  3704. D : Byte;
  3705. begin
  3706. if IsSortedAscending then // binary search
  3707. begin
  3708. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3709. begin
  3710. L := 0;
  3711. H := Length(V) - 1;
  3712. while L <= H do
  3713. begin
  3714. I := (L + H) div 2;
  3715. D := V[I];
  3716. if Find = D then
  3717. begin
  3718. while (I > 0) and (V[I - 1] = Find) do
  3719. Dec(I);
  3720. Result := I;
  3721. exit;
  3722. end else
  3723. if D > Find then
  3724. H := I - 1
  3725. else
  3726. L := I + 1;
  3727. end;
  3728. Result := -1;
  3729. end
  3730. else // find next
  3731. if PrevPos >= Length(V) - 1 then
  3732. Result := -1
  3733. else
  3734. if V[PrevPos + 1] = Find then
  3735. Result := PrevPos + 1
  3736. else
  3737. Result := -1;
  3738. end
  3739. else
  3740. begin // linear search
  3741. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3742. if V[I] = Find then
  3743. begin
  3744. Result := I;
  3745. exit;
  3746. end;
  3747. Result := -1;
  3748. end;
  3749. end;
  3750. function DynArrayPosNext(const Find: Word; const V: WordArray; const PrevPos: Integer;
  3751. const IsSortedAscending: Boolean): Integer;
  3752. var I, L, H : Integer;
  3753. D : Word;
  3754. begin
  3755. if IsSortedAscending then // binary search
  3756. begin
  3757. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3758. begin
  3759. L := 0;
  3760. H := Length(V) - 1;
  3761. while L <= H do
  3762. begin
  3763. I := (L + H) div 2;
  3764. D := V[I];
  3765. if Find = D then
  3766. begin
  3767. while (I > 0) and (V[I - 1] = Find) do
  3768. Dec(I);
  3769. Result := I;
  3770. exit;
  3771. end else
  3772. if D > Find then
  3773. H := I - 1
  3774. else
  3775. L := I + 1;
  3776. end;
  3777. Result := -1;
  3778. end
  3779. else // find next
  3780. if PrevPos >= Length(V) - 1 then
  3781. Result := -1
  3782. else
  3783. if V[PrevPos + 1] = Find then
  3784. Result := PrevPos + 1
  3785. else
  3786. Result := -1;
  3787. end
  3788. else
  3789. begin // linear search
  3790. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3791. if V[I] = Find then
  3792. begin
  3793. Result := I;
  3794. exit;
  3795. end;
  3796. Result := -1;
  3797. end;
  3798. end;
  3799. function DynArrayPosNext(const Find: LongWord; const V: LongWordArray; const PrevPos: Integer;
  3800. const IsSortedAscending: Boolean): Integer;
  3801. var I, L, H : Integer;
  3802. D : LongWord;
  3803. begin
  3804. if IsSortedAscending then // binary search
  3805. begin
  3806. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3807. begin
  3808. L := 0;
  3809. H := Length(V) - 1;
  3810. while L <= H do
  3811. begin
  3812. I := (L + H) div 2;
  3813. D := V[I];
  3814. if Find = D then
  3815. begin
  3816. while (I > 0) and (V[I - 1] = Find) do
  3817. Dec(I);
  3818. Result := I;
  3819. exit;
  3820. end else
  3821. if D > Find then
  3822. H := I - 1
  3823. else
  3824. L := I + 1;
  3825. end;
  3826. Result := -1;
  3827. end
  3828. else // find next
  3829. if PrevPos >= Length(V) - 1 then
  3830. Result := -1
  3831. else
  3832. if V[PrevPos + 1] = Find then
  3833. Result := PrevPos + 1
  3834. else
  3835. Result := -1;
  3836. end
  3837. else
  3838. begin // linear search
  3839. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3840. if V[I] = Find then
  3841. begin
  3842. Result := I;
  3843. exit;
  3844. end;
  3845. Result := -1;
  3846. end;
  3847. end;
  3848. function DynArrayPosNext(const Find: NativeUInt; const V: NativeUIntArray; const PrevPos: Integer;
  3849. const IsSortedAscending: Boolean): Integer;
  3850. var I, L, H : Integer;
  3851. D : NativeUInt;
  3852. begin
  3853. if IsSortedAscending then // binary search
  3854. begin
  3855. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3856. begin
  3857. L := 0;
  3858. H := Length(V) - 1;
  3859. while L <= H do
  3860. begin
  3861. I := (L + H) div 2;
  3862. D := V[I];
  3863. if Find = D then
  3864. begin
  3865. while (I > 0) and (V[I - 1] = Find) do
  3866. Dec(I);
  3867. Result := I;
  3868. exit;
  3869. end else
  3870. if D > Find then
  3871. H := I - 1
  3872. else
  3873. L := I + 1;
  3874. end;
  3875. Result := -1;
  3876. end
  3877. else // find next
  3878. if PrevPos >= Length(V) - 1 then
  3879. Result := -1
  3880. else
  3881. if V[PrevPos + 1] = Find then
  3882. Result := PrevPos + 1
  3883. else
  3884. Result := -1;
  3885. end
  3886. else
  3887. begin // linear search
  3888. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3889. if V[I] = Find then
  3890. begin
  3891. Result := I;
  3892. exit;
  3893. end;
  3894. Result := -1;
  3895. end;
  3896. end;
  3897. function DynArrayPosNext(const Find: ShortInt; const V: ShortIntArray; const PrevPos: Integer;
  3898. const IsSortedAscending: Boolean): Integer;
  3899. var I, L, H : Integer;
  3900. D : ShortInt;
  3901. begin
  3902. if IsSortedAscending then // binary search
  3903. begin
  3904. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3905. begin
  3906. L := 0;
  3907. H := Length(V) - 1;
  3908. while L <= H do
  3909. begin
  3910. I := (L + H) div 2;
  3911. D := V[I];
  3912. if Find = D then
  3913. begin
  3914. while (I > 0) and (V[I - 1] = Find) do
  3915. Dec(I);
  3916. Result := I;
  3917. exit;
  3918. end else
  3919. if D > Find then
  3920. H := I - 1
  3921. else
  3922. L := I + 1;
  3923. end;
  3924. Result := -1;
  3925. end
  3926. else // find next
  3927. if PrevPos >= Length(V) - 1 then
  3928. Result := -1
  3929. else
  3930. if V[PrevPos + 1] = Find then
  3931. Result := PrevPos + 1
  3932. else
  3933. Result := -1;
  3934. end
  3935. else
  3936. begin // linear search
  3937. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3938. if V[I] = Find then
  3939. begin
  3940. Result := I;
  3941. exit;
  3942. end;
  3943. Result := -1;
  3944. end;
  3945. end;
  3946. function DynArrayPosNext(const Find: SmallInt; const V: SmallIntArray; const PrevPos: Integer;
  3947. const IsSortedAscending: Boolean): Integer;
  3948. var I, L, H : Integer;
  3949. D : SmallInt;
  3950. begin
  3951. if IsSortedAscending then // binary search
  3952. begin
  3953. if MaxI(PrevPos + 1, 0) = 0 then // find first
  3954. begin
  3955. L := 0;
  3956. H := Length(V) - 1;
  3957. while L <= H do
  3958. begin
  3959. I := (L + H) div 2;
  3960. D := V[I];
  3961. if Find = D then
  3962. begin
  3963. while (I > 0) and (V[I - 1] = Find) do
  3964. Dec(I);
  3965. Result := I;
  3966. exit;
  3967. end else
  3968. if D > Find then
  3969. H := I - 1
  3970. else
  3971. L := I + 1;
  3972. end;
  3973. Result := -1;
  3974. end
  3975. else // find next
  3976. if PrevPos >= Length(V) - 1 then
  3977. Result := -1
  3978. else
  3979. if V[PrevPos + 1] = Find then
  3980. Result := PrevPos + 1
  3981. else
  3982. Result := -1;
  3983. end
  3984. else
  3985. begin // linear search
  3986. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  3987. if V[I] = Find then
  3988. begin
  3989. Result := I;
  3990. exit;
  3991. end;
  3992. Result := -1;
  3993. end;
  3994. end;
  3995. function DynArrayPosNext(const Find: LongInt; const V: LongIntArray; const PrevPos: Integer;
  3996. const IsSortedAscending: Boolean): Integer;
  3997. var I, L, H : Integer;
  3998. D : LongInt;
  3999. begin
  4000. if IsSortedAscending then // binary search
  4001. begin
  4002. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4003. begin
  4004. L := 0;
  4005. H := Length(V) - 1;
  4006. while L <= H do
  4007. begin
  4008. I := (L + H) div 2;
  4009. D := V[I];
  4010. if Find = D then
  4011. begin
  4012. while (I > 0) and (V[I - 1] = Find) do
  4013. Dec(I);
  4014. Result := I;
  4015. exit;
  4016. end else
  4017. if D > Find then
  4018. H := I - 1
  4019. else
  4020. L := I + 1;
  4021. end;
  4022. Result := -1;
  4023. end
  4024. else // find next
  4025. if PrevPos >= Length(V) - 1 then
  4026. Result := -1
  4027. else
  4028. if V[PrevPos + 1] = Find then
  4029. Result := PrevPos + 1
  4030. else
  4031. Result := -1;
  4032. end
  4033. else
  4034. begin // linear search
  4035. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4036. if V[I] = Find then
  4037. begin
  4038. Result := I;
  4039. exit;
  4040. end;
  4041. Result := -1;
  4042. end;
  4043. end;
  4044. function DynArrayPosNext(const Find: Int64; const V: Int64Array; const PrevPos: Integer;
  4045. const IsSortedAscending: Boolean): Integer;
  4046. var I, L, H : Integer;
  4047. D : Int64;
  4048. begin
  4049. if IsSortedAscending then // binary search
  4050. begin
  4051. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4052. begin
  4053. L := 0;
  4054. H := Length(V) - 1;
  4055. while L <= H do
  4056. begin
  4057. I := (L + H) div 2;
  4058. D := V[I];
  4059. if Find = D then
  4060. begin
  4061. while (I > 0) and (V[I - 1] = Find) do
  4062. Dec(I);
  4063. Result := I;
  4064. exit;
  4065. end else
  4066. if D > Find then
  4067. H := I - 1
  4068. else
  4069. L := I + 1;
  4070. end;
  4071. Result := -1;
  4072. end
  4073. else // find next
  4074. if PrevPos >= Length(V) - 1 then
  4075. Result := -1
  4076. else
  4077. if V[PrevPos + 1] = Find then
  4078. Result := PrevPos + 1
  4079. else
  4080. Result := -1;
  4081. end
  4082. else
  4083. begin // linear search
  4084. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4085. if V[I] = Find then
  4086. begin
  4087. Result := I;
  4088. exit;
  4089. end;
  4090. Result := -1;
  4091. end;
  4092. end;
  4093. function DynArrayPosNext(const Find: NativeInt; const V: NativeIntArray; const PrevPos: Integer;
  4094. const IsSortedAscending: Boolean): Integer;
  4095. var I, L, H : Integer;
  4096. D : NativeInt;
  4097. begin
  4098. if IsSortedAscending then // binary search
  4099. begin
  4100. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4101. begin
  4102. L := 0;
  4103. H := Length(V) - 1;
  4104. while L <= H do
  4105. begin
  4106. I := (L + H) div 2;
  4107. D := V[I];
  4108. if Find = D then
  4109. begin
  4110. while (I > 0) and (V[I - 1] = Find) do
  4111. Dec(I);
  4112. Result := I;
  4113. exit;
  4114. end else
  4115. if D > Find then
  4116. H := I - 1
  4117. else
  4118. L := I + 1;
  4119. end;
  4120. Result := -1;
  4121. end
  4122. else // find next
  4123. if PrevPos >= Length(V) - 1 then
  4124. Result := -1
  4125. else
  4126. if V[PrevPos + 1] = Find then
  4127. Result := PrevPos + 1
  4128. else
  4129. Result := -1;
  4130. end
  4131. else
  4132. begin // linear search
  4133. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4134. if V[I] = Find then
  4135. begin
  4136. Result := I;
  4137. exit;
  4138. end;
  4139. Result := -1;
  4140. end;
  4141. end;
  4142. function DynArrayPosNext(const Find: Single; const V: SingleArray; const PrevPos: Integer;
  4143. const IsSortedAscending: Boolean): Integer;
  4144. var I, L, H : Integer;
  4145. D : Single;
  4146. begin
  4147. if IsSortedAscending then // binary search
  4148. begin
  4149. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4150. begin
  4151. L := 0;
  4152. H := Length(V) - 1;
  4153. while L <= H do
  4154. begin
  4155. I := (L + H) div 2;
  4156. D := V[I];
  4157. if Find = D then
  4158. begin
  4159. while (I > 0) and (V[I - 1] = Find) do
  4160. Dec(I);
  4161. Result := I;
  4162. exit;
  4163. end else
  4164. if D > Find then
  4165. H := I - 1
  4166. else
  4167. L := I + 1;
  4168. end;
  4169. Result := -1;
  4170. end
  4171. else // find next
  4172. if PrevPos >= Length(V) - 1 then
  4173. Result := -1
  4174. else
  4175. if V[PrevPos + 1] = Find then
  4176. Result := PrevPos + 1
  4177. else
  4178. Result := -1;
  4179. end
  4180. else
  4181. begin // linear search
  4182. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4183. if V[I] = Find then
  4184. begin
  4185. Result := I;
  4186. exit;
  4187. end;
  4188. Result := -1;
  4189. end;
  4190. end;
  4191. function DynArrayPosNext(const Find: Double; const V: DoubleArray; const PrevPos: Integer;
  4192. const IsSortedAscending: Boolean): Integer;
  4193. var I, L, H : Integer;
  4194. D : Double;
  4195. begin
  4196. if IsSortedAscending then // binary search
  4197. begin
  4198. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4199. begin
  4200. L := 0;
  4201. H := Length(V) - 1;
  4202. while L <= H do
  4203. begin
  4204. I := (L + H) div 2;
  4205. D := V[I];
  4206. if Find = D then
  4207. begin
  4208. while (I > 0) and (V[I - 1] = Find) do
  4209. Dec(I);
  4210. Result := I;
  4211. exit;
  4212. end else
  4213. if D > Find then
  4214. H := I - 1
  4215. else
  4216. L := I + 1;
  4217. end;
  4218. Result := -1;
  4219. end
  4220. else // find next
  4221. if PrevPos >= Length(V) - 1 then
  4222. Result := -1
  4223. else
  4224. if V[PrevPos + 1] = Find then
  4225. Result := PrevPos + 1
  4226. else
  4227. Result := -1;
  4228. end
  4229. else
  4230. begin // linear search
  4231. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4232. if V[I] = Find then
  4233. begin
  4234. Result := I;
  4235. exit;
  4236. end;
  4237. Result := -1;
  4238. end;
  4239. end;
  4240. function DynArrayPosNext(const Find: Extended; const V: ExtendedArray; const PrevPos: Integer;
  4241. const IsSortedAscending: Boolean): Integer;
  4242. var I, L, H : Integer;
  4243. D : Extended;
  4244. begin
  4245. if IsSortedAscending then // binary search
  4246. begin
  4247. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4248. begin
  4249. L := 0;
  4250. H := Length(V) - 1;
  4251. while L <= H do
  4252. begin
  4253. I := (L + H) div 2;
  4254. D := V[I];
  4255. if Find = D then
  4256. begin
  4257. while (I > 0) and (V[I - 1] = Find) do
  4258. Dec(I);
  4259. Result := I;
  4260. exit;
  4261. end else
  4262. if D > Find then
  4263. H := I - 1
  4264. else
  4265. L := I + 1;
  4266. end;
  4267. Result := -1;
  4268. end
  4269. else // find next
  4270. if PrevPos >= Length(V) - 1 then
  4271. Result := -1
  4272. else
  4273. if V[PrevPos + 1] = Find then
  4274. Result := PrevPos + 1
  4275. else
  4276. Result := -1;
  4277. end
  4278. else
  4279. begin // linear search
  4280. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4281. if V[I] = Find then
  4282. begin
  4283. Result := I;
  4284. exit;
  4285. end;
  4286. Result := -1;
  4287. end;
  4288. end;
  4289. function DynArrayPosNext(const Find: Boolean; const V: BooleanArray; const PrevPos: Integer;
  4290. const IsSortedAscending: Boolean): Integer;
  4291. var I, L, H : Integer;
  4292. D : Boolean;
  4293. begin
  4294. if IsSortedAscending then // binary search
  4295. begin
  4296. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4297. begin
  4298. L := 0;
  4299. H := Length(V) - 1;
  4300. while L <= H do
  4301. begin
  4302. I := (L + H) div 2;
  4303. D := V[I];
  4304. if Find = D then
  4305. begin
  4306. while (I > 0) and (V[I - 1] = Find) do
  4307. Dec(I);
  4308. Result := I;
  4309. exit;
  4310. end else
  4311. if D > Find then
  4312. H := I - 1
  4313. else
  4314. L := I + 1;
  4315. end;
  4316. Result := -1;
  4317. end
  4318. else // find next
  4319. if PrevPos >= Length(V) - 1 then
  4320. Result := -1
  4321. else
  4322. if V[PrevPos + 1] = Find then
  4323. Result := PrevPos + 1
  4324. else
  4325. Result := -1;
  4326. end
  4327. else
  4328. begin // linear search
  4329. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4330. if V[I] = Find then
  4331. begin
  4332. Result := I;
  4333. exit;
  4334. end;
  4335. Result := -1;
  4336. end;
  4337. end;
  4338. function DynArrayPosNextA(const Find: AnsiString; const V: AnsiStringArray; const PrevPos: Integer;
  4339. const IsSortedAscending: Boolean): Integer;
  4340. var I, L, H : Integer;
  4341. D : AnsiString;
  4342. begin
  4343. if IsSortedAscending then // binary search
  4344. begin
  4345. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4346. begin
  4347. L := 0;
  4348. H := Length(V) - 1;
  4349. while L <= H do
  4350. begin
  4351. I := (L + H) div 2;
  4352. D := V[I];
  4353. if Find = D then
  4354. begin
  4355. while (I > 0) and (V[I - 1] = Find) do
  4356. Dec(I);
  4357. Result := I;
  4358. exit;
  4359. end else
  4360. if D > Find then
  4361. H := I - 1
  4362. else
  4363. L := I + 1;
  4364. end;
  4365. Result := -1;
  4366. end
  4367. else // find next
  4368. if PrevPos >= Length(V) - 1 then
  4369. Result := -1
  4370. else
  4371. if V[PrevPos + 1] = Find then
  4372. Result := PrevPos + 1
  4373. else
  4374. Result := -1;
  4375. end
  4376. else
  4377. begin // linear search
  4378. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4379. if V[I] = Find then
  4380. begin
  4381. Result := I;
  4382. exit;
  4383. end;
  4384. Result := -1;
  4385. end;
  4386. end;
  4387. function DynArrayPosNextW(const Find: WideString; const V: WideStringArray; const PrevPos: Integer;
  4388. const IsSortedAscending: Boolean): Integer;
  4389. var I, L, H : Integer;
  4390. D : WideString;
  4391. begin
  4392. if IsSortedAscending then // binary search
  4393. begin
  4394. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4395. begin
  4396. L := 0;
  4397. H := Length(V) - 1;
  4398. while L <= H do
  4399. begin
  4400. I := (L + H) div 2;
  4401. D := V[I];
  4402. if Find = D then
  4403. begin
  4404. while (I > 0) and (V[I - 1] = Find) do
  4405. Dec(I);
  4406. Result := I;
  4407. exit;
  4408. end else
  4409. if D > Find then
  4410. H := I - 1
  4411. else
  4412. L := I + 1;
  4413. end;
  4414. Result := -1;
  4415. end
  4416. else // find next
  4417. if PrevPos >= Length(V) - 1 then
  4418. Result := -1
  4419. else
  4420. if V[PrevPos + 1] = Find then
  4421. Result := PrevPos + 1
  4422. else
  4423. Result := -1;
  4424. end
  4425. else
  4426. begin // linear search
  4427. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4428. if V[I] = Find then
  4429. begin
  4430. Result := I;
  4431. exit;
  4432. end;
  4433. Result := -1;
  4434. end;
  4435. end;
  4436. function DynArrayPosNextU(const Find: UnicodeString; const V: UnicodeStringArray; const PrevPos: Integer;
  4437. const IsSortedAscending: Boolean): Integer;
  4438. var I, L, H : Integer;
  4439. D : UnicodeString;
  4440. begin
  4441. if IsSortedAscending then // binary search
  4442. begin
  4443. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4444. begin
  4445. L := 0;
  4446. H := Length(V) - 1;
  4447. while L <= H do
  4448. begin
  4449. I := (L + H) div 2;
  4450. D := V[I];
  4451. if Find = D then
  4452. begin
  4453. while (I > 0) and (V[I - 1] = Find) do
  4454. Dec(I);
  4455. Result := I;
  4456. exit;
  4457. end else
  4458. if D > Find then
  4459. H := I - 1
  4460. else
  4461. L := I + 1;
  4462. end;
  4463. Result := -1;
  4464. end
  4465. else // find next
  4466. if PrevPos >= Length(V) - 1 then
  4467. Result := -1
  4468. else
  4469. if V[PrevPos + 1] = Find then
  4470. Result := PrevPos + 1
  4471. else
  4472. Result := -1;
  4473. end
  4474. else
  4475. begin // linear search
  4476. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4477. if V[I] = Find then
  4478. begin
  4479. Result := I;
  4480. exit;
  4481. end;
  4482. Result := -1;
  4483. end;
  4484. end;
  4485. function DynArrayPosNext(const Find: String; const V: StringArray; const PrevPos: Integer;
  4486. const IsSortedAscending: Boolean): Integer;
  4487. var I, L, H : Integer;
  4488. D : String;
  4489. begin
  4490. if IsSortedAscending then // binary search
  4491. begin
  4492. if MaxI(PrevPos + 1, 0) = 0 then // find first
  4493. begin
  4494. L := 0;
  4495. H := Length(V) - 1;
  4496. while L <= H do
  4497. begin
  4498. I := (L + H) div 2;
  4499. D := V[I];
  4500. if Find = D then
  4501. begin
  4502. while (I > 0) and (V[I - 1] = Find) do
  4503. Dec(I);
  4504. Result := I;
  4505. exit;
  4506. end else
  4507. if D > Find then
  4508. H := I - 1
  4509. else
  4510. L := I + 1;
  4511. end;
  4512. Result := -1;
  4513. end
  4514. else // find next
  4515. if PrevPos >= Length(V) - 1 then
  4516. Result := -1
  4517. else
  4518. if V[PrevPos + 1] = Find then
  4519. Result := PrevPos + 1
  4520. else
  4521. Result := -1;
  4522. end
  4523. else
  4524. begin // linear search
  4525. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4526. if V[I] = Find then
  4527. begin
  4528. Result := I;
  4529. exit;
  4530. end;
  4531. Result := -1;
  4532. end;
  4533. end;
  4534. function DynArrayPosNext(const Find: TObject; const V: ObjectArray; const PrevPos: Integer): Integer;
  4535. var I : Integer;
  4536. begin
  4537. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4538. if V[I] = Find then
  4539. begin
  4540. Result := I;
  4541. exit;
  4542. end;
  4543. Result := -1;
  4544. end;
  4545. function DynArrayPosNext(const ClassType: TClass; const V: ObjectArray; const PrevPos: Integer): Integer;
  4546. var I : Integer;
  4547. begin
  4548. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4549. if V[I] is ClassType then
  4550. begin
  4551. Result := I;
  4552. exit;
  4553. end;
  4554. Result := -1;
  4555. end;
  4556. function DynArrayPosNext(const ClassName: String; const V: ObjectArray; const PrevPos: Integer): Integer;
  4557. var I : Integer;
  4558. T : TObject;
  4559. begin
  4560. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4561. begin
  4562. T := V[I];
  4563. if Assigned(T) and (T.ClassName = ClassName) then
  4564. begin
  4565. Result := I;
  4566. exit;
  4567. end;
  4568. end;
  4569. Result := -1;
  4570. end;
  4571. {$IFNDEF ManagedCode}
  4572. function DynArrayPosNext(const Find: Pointer; const V: PointerArray; const PrevPos: Integer): Integer;
  4573. var I : Integer;
  4574. begin
  4575. for I := MaxI(PrevPos + 1, 0) to Length(V) - 1 do
  4576. if V[I] = Find then
  4577. begin
  4578. Result := I;
  4579. exit;
  4580. end;
  4581. Result := -1;
  4582. end;
  4583. {$ENDIF}
  4584. { }
  4585. { DynArrayCount }
  4586. { }
  4587. function DynArrayCount(const Find: Byte; const V: ByteArray; const IsSortedAscending: Boolean = False): Integer;
  4588. var I, J : Integer;
  4589. begin
  4590. if IsSortedAscending then
  4591. begin
  4592. I := DynArrayPosNext(Find, V, -1, True);
  4593. if I = -1 then
  4594. Result := 0 else
  4595. begin
  4596. Result := 1;
  4597. J := Length(V);
  4598. while (I + Result < J) and (V[I + Result] = Find) do
  4599. Inc(Result);
  4600. end;
  4601. end
  4602. else
  4603. begin
  4604. J := -1;
  4605. Result := 0;
  4606. repeat
  4607. I := DynArrayPosNext(Find, V, J, False);
  4608. if I >= 0 then
  4609. begin
  4610. Inc(Result);
  4611. J := I;
  4612. end;
  4613. until I < 0;
  4614. end;
  4615. end;
  4616. function DynArrayCount(const Find: Word; const V: WordArray; const IsSortedAscending: Boolean = False): Integer;
  4617. var I, J : Integer;
  4618. begin
  4619. if IsSortedAscending then
  4620. begin
  4621. I := DynArrayPosNext(Find, V, -1, True);
  4622. if I = -1 then
  4623. Result := 0 else
  4624. begin
  4625. Result := 1;
  4626. J := Length(V);
  4627. while (I + Result < J) and (V[I + Result] = Find) do
  4628. Inc(Result);
  4629. end;
  4630. end
  4631. else
  4632. begin
  4633. J := -1;
  4634. Result := 0;
  4635. repeat
  4636. I := DynArrayPosNext(Find, V, J, False);
  4637. if I >= 0 then
  4638. begin
  4639. Inc(Result);
  4640. J := I;
  4641. end;
  4642. until I < 0;
  4643. end;
  4644. end;
  4645. function DynArrayCount(const Find: LongWord; const V: LongWordArray; const IsSortedAscending: Boolean = False): Integer;
  4646. var I, J : Integer;
  4647. begin
  4648. if IsSortedAscending then
  4649. begin
  4650. I := DynArrayPosNext(Find, V, -1, True);
  4651. if I = -1 then
  4652. Result := 0 else
  4653. begin
  4654. Result := 1;
  4655. J := Length(V);
  4656. while (I + Result < J) and (V[I + Result] = Find) do
  4657. Inc(Result);
  4658. end;
  4659. end
  4660. else
  4661. begin
  4662. J := -1;
  4663. Result := 0;
  4664. repeat
  4665. I := DynArrayPosNext(Find, V, J, False);
  4666. if I >= 0 then
  4667. begin
  4668. Inc(Result);
  4669. J := I;
  4670. end;
  4671. until I < 0;
  4672. end;
  4673. end;
  4674. function DynArrayCount(const Find: ShortInt; const V: ShortIntArray; const IsSortedAscending: Boolean = False): Integer;
  4675. var I, J : Integer;
  4676. begin
  4677. if IsSortedAscending then
  4678. begin
  4679. I := DynArrayPosNext(Find, V, -1, True);
  4680. if I = -1 then
  4681. Result := 0 else
  4682. begin
  4683. Result := 1;
  4684. J := Length(V);
  4685. while (I + Result < J) and (V[I + Result] = Find) do
  4686. Inc(Result);
  4687. end;
  4688. end
  4689. else
  4690. begin
  4691. J := -1;
  4692. Result := 0;
  4693. repeat
  4694. I := DynArrayPosNext(Find, V, J, False);
  4695. if I >= 0 then
  4696. begin
  4697. Inc(Result);
  4698. J := I;
  4699. end;
  4700. until I < 0;
  4701. end;
  4702. end;
  4703. function DynArrayCount(const Find: SmallInt; const V: SmallIntArray; const IsSortedAscending: Boolean = False): Integer;
  4704. var I, J : Integer;
  4705. begin
  4706. if IsSortedAscending then
  4707. begin
  4708. I := DynArrayPosNext(Find, V, -1, True);
  4709. if I = -1 then
  4710. Result := 0 else
  4711. begin
  4712. Result := 1;
  4713. J := Length(V);
  4714. while (I + Result < J) and (V[I + Result] = Find) do
  4715. Inc(Result);
  4716. end;
  4717. end
  4718. else
  4719. begin
  4720. J := -1;
  4721. Result := 0;
  4722. repeat
  4723. I := DynArrayPosNext(Find, V, J, False);
  4724. if I >= 0 then
  4725. begin
  4726. Inc(Result);
  4727. J := I;
  4728. end;
  4729. until I < 0;
  4730. end;
  4731. end;
  4732. function DynArrayCount(const Find: LongInt; const V: LongIntArray; const IsSortedAscending: Boolean = False): Integer;
  4733. var I, J : Integer;
  4734. begin
  4735. if IsSortedAscending then
  4736. begin
  4737. I := DynArrayPosNext(Find, V, -1, True);
  4738. if I = -1 then
  4739. Result := 0 else
  4740. begin
  4741. Result := 1;
  4742. J := Length(V);
  4743. while (I + Result < J) and (V[I + Result] = Find) do
  4744. Inc(Result);
  4745. end;
  4746. end
  4747. else
  4748. begin
  4749. J := -1;
  4750. Result := 0;
  4751. repeat
  4752. I := DynArrayPosNext(Find, V, J, False);
  4753. if I >= 0 then
  4754. begin
  4755. Inc(Result);
  4756. J := I;
  4757. end;
  4758. until I < 0;
  4759. end;
  4760. end;
  4761. function DynArrayCount(const Find: Int64; const V: Int64Array; const IsSortedAscending: Boolean = False): Integer;
  4762. var I, J : Integer;
  4763. begin
  4764. if IsSortedAscending then
  4765. begin
  4766. I := DynArrayPosNext(Find, V, -1, True);
  4767. if I = -1 then
  4768. Result := 0 else
  4769. begin
  4770. Result := 1;
  4771. J := Length(V);
  4772. while (I + Result < J) and (V[I + Result] = Find) do
  4773. Inc(Result);
  4774. end;
  4775. end
  4776. else
  4777. begin
  4778. J := -1;
  4779. Result := 0;
  4780. repeat
  4781. I := DynArrayPosNext(Find, V, J, False);
  4782. if I >= 0 then
  4783. begin
  4784. Inc(Result);
  4785. J := I;
  4786. end;
  4787. until I < 0;
  4788. end;
  4789. end;
  4790. function DynArrayCount(const Find: Single; const V: SingleArray; const IsSortedAscending: Boolean = False): Integer;
  4791. var I, J : Integer;
  4792. begin
  4793. if IsSortedAscending then
  4794. begin
  4795. I := DynArrayPosNext(Find, V, -1, True);
  4796. if I = -1 then
  4797. Result := 0 else
  4798. begin
  4799. Result := 1;
  4800. J := Length(V);
  4801. while (I + Result < J) and (V[I + Result] = Find) do
  4802. Inc(Result);
  4803. end;
  4804. end
  4805. else
  4806. begin
  4807. J := -1;
  4808. Result := 0;
  4809. repeat
  4810. I := DynArrayPosNext(Find, V, J, False);
  4811. if I >= 0 then
  4812. begin
  4813. Inc(Result);
  4814. J := I;
  4815. end;
  4816. until I < 0;
  4817. end;
  4818. end;
  4819. function DynArrayCount(const Find: Double; const V: DoubleArray; const IsSortedAscending: Boolean = False): Integer;
  4820. var I, J : Integer;
  4821. begin
  4822. if IsSortedAscending then
  4823. begin
  4824. I := DynArrayPosNext(Find, V, -1, True);
  4825. if I = -1 then
  4826. Result := 0 else
  4827. begin
  4828. Result := 1;
  4829. J := Length(V);
  4830. while (I + Result < J) and (V[I + Result] = Find) do
  4831. Inc(Result);
  4832. end;
  4833. end
  4834. else
  4835. begin
  4836. J := -1;
  4837. Result := 0;
  4838. repeat
  4839. I := DynArrayPosNext(Find, V, J, False);
  4840. if I >= 0 then
  4841. begin
  4842. Inc(Result);
  4843. J := I;
  4844. end;
  4845. until I < 0;
  4846. end;
  4847. end;
  4848. function DynArrayCount(const Find: Extended; const V: ExtendedArray; const IsSortedAscending: Boolean = False): Integer;
  4849. var I, J : Integer;
  4850. begin
  4851. if IsSortedAscending then
  4852. begin
  4853. I := DynArrayPosNext(Find, V, -1, True);
  4854. if I = -1 then
  4855. Result := 0 else
  4856. begin
  4857. Result := 1;
  4858. J := Length(V);
  4859. while (I + Result < J) and (V[I + Result] = Find) do
  4860. Inc(Result);
  4861. end;
  4862. end
  4863. else
  4864. begin
  4865. J := -1;
  4866. Result := 0;
  4867. repeat
  4868. I := DynArrayPosNext(Find, V, J, False);
  4869. if I >= 0 then
  4870. begin
  4871. Inc(Result);
  4872. J := I;
  4873. end;
  4874. until I < 0;
  4875. end;
  4876. end;
  4877. function DynArrayCountA(const Find: AnsiString; const V: AnsiStringArray; const IsSortedAscending: Boolean = False): Integer;
  4878. var I, J : Integer;
  4879. begin
  4880. if IsSortedAscending then
  4881. begin
  4882. I := DynArrayPosNextA(Find, V, -1, True);
  4883. if I = -1 then
  4884. Result := 0 else
  4885. begin
  4886. Result := 1;
  4887. J := Length(V);
  4888. while (I + Result < J) and (V[I + Result] = Find) do
  4889. Inc(Result);
  4890. end;
  4891. end
  4892. else
  4893. begin
  4894. J := -1;
  4895. Result := 0;
  4896. repeat
  4897. I := DynArrayPosNextA(Find, V, J, False);
  4898. if I >= 0 then
  4899. begin
  4900. Inc(Result);
  4901. J := I;
  4902. end;
  4903. until I < 0;
  4904. end;
  4905. end;
  4906. function DynArrayCountW(const Find: WideString; const V: WideStringArray; const IsSortedAscending: Boolean = False): Integer;
  4907. var I, J : Integer;
  4908. begin
  4909. if IsSortedAscending then
  4910. begin
  4911. I := DynArrayPosNextW(Find, V, -1, True);
  4912. if I = -1 then
  4913. Result := 0 else
  4914. begin
  4915. Result := 1;
  4916. J := Length(V);
  4917. while (I + Result < J) and (V[I + Result] = Find) do
  4918. Inc(Result);
  4919. end;
  4920. end
  4921. else
  4922. begin
  4923. J := -1;
  4924. Result := 0;
  4925. repeat
  4926. I := DynArrayPosNextW(Find, V, J, False);
  4927. if I >= 0 then
  4928. begin
  4929. Inc(Result);
  4930. J := I;
  4931. end;
  4932. until I < 0;
  4933. end;
  4934. end;
  4935. function DynArrayCountU(const Find: UnicodeString; const V: UnicodeStringArray; const IsSortedAscending: Boolean = False): Integer;
  4936. var I, J : Integer;
  4937. begin
  4938. if IsSortedAscending then
  4939. begin
  4940. I := DynArrayPosNextU(Find, V, -1, True);
  4941. if I = -1 then
  4942. Result := 0 else
  4943. begin
  4944. Result := 1;
  4945. J := Length(V);
  4946. while (I + Result < J) and (V[I + Result] = Find) do
  4947. Inc(Result);
  4948. end;
  4949. end
  4950. else
  4951. begin
  4952. J := -1;
  4953. Result := 0;
  4954. repeat
  4955. I := DynArrayPosNextU(Find, V, J, False);
  4956. if I >= 0 then
  4957. begin
  4958. Inc(Result);
  4959. J := I;
  4960. end;
  4961. until I < 0;
  4962. end;
  4963. end;
  4964. function DynArrayCount(const Find: String; const V: StringArray; const IsSortedAscending: Boolean = False): Integer;
  4965. var I, J : Integer;
  4966. begin
  4967. if IsSortedAscending then
  4968. begin
  4969. I := DynArrayPosNext(Find, V, -1, True);
  4970. if I = -1 then
  4971. Result := 0 else
  4972. begin
  4973. Result := 1;
  4974. J := Length(V);
  4975. while (I + Result < J) and (V[I + Result] = Find) do
  4976. Inc(Result);
  4977. end;
  4978. end
  4979. else
  4980. begin
  4981. J := -1;
  4982. Result := 0;
  4983. repeat
  4984. I := DynArrayPosNext(Find, V, J, False);
  4985. if I >= 0 then
  4986. begin
  4987. Inc(Result);
  4988. J := I;
  4989. end;
  4990. until I < 0;
  4991. end;
  4992. end;
  4993. function DynArrayCount(const Find: Boolean; const V: BooleanArray; const IsSortedAscending: Boolean = False): Integer;
  4994. var I, J : Integer;
  4995. begin
  4996. if IsSortedAscending then
  4997. begin
  4998. I := DynArrayPosNext(Find, V, -1, True);
  4999. if I = -1 then
  5000. Result := 0 else
  5001. begin
  5002. Result := 1;
  5003. J := Length(V);
  5004. while (I + Result < J) and (V[I + Result] = Find) do
  5005. Inc(Result);
  5006. end;
  5007. end
  5008. else
  5009. begin
  5010. J := -1;
  5011. Result := 0;
  5012. repeat
  5013. I := DynArrayPosNext(Find, V, J, False);
  5014. if I >= 0 then
  5015. begin
  5016. Inc(Result);
  5017. J := I;
  5018. end;
  5019. until I < 0;
  5020. end;
  5021. end;
  5022. { }
  5023. { DynArrayRemoveAll }
  5024. { }
  5025. procedure DynArrayRemoveAll(const Find: Byte; var V: ByteArray; const IsSortedAscending: Boolean = False);
  5026. var I, J : Integer;
  5027. begin
  5028. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5029. while I >= 0 do
  5030. begin
  5031. J := 1;
  5032. while (I + J < Length(V)) and (V[I + J] = Find) do
  5033. Inc(J);
  5034. DynArrayRemove(V, I, J);
  5035. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5036. end;
  5037. end;
  5038. procedure DynArrayRemoveAll(const Find: Word; var V: WordArray; const IsSortedAscending: Boolean = False);
  5039. var I, J : Integer;
  5040. begin
  5041. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5042. while I >= 0 do
  5043. begin
  5044. J := 1;
  5045. while (I + J < Length(V)) and (V[I + J] = Find) do
  5046. Inc(J);
  5047. DynArrayRemove(V, I, J);
  5048. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5049. end;
  5050. end;
  5051. procedure DynArrayRemoveAll(const Find: LongWord; var V: LongWordArray; const IsSortedAscending: Boolean = False);
  5052. var I, J : Integer;
  5053. begin
  5054. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5055. while I >= 0 do
  5056. begin
  5057. J := 1;
  5058. while (I + J < Length(V)) and (V[I + J] = Find) do
  5059. Inc(J);
  5060. DynArrayRemove(V, I, J);
  5061. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5062. end;
  5063. end;
  5064. procedure DynArrayRemoveAll(const Find: ShortInt; var V: ShortIntArray; const IsSortedAscending: Boolean = False);
  5065. var I, J : Integer;
  5066. begin
  5067. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5068. while I >= 0 do
  5069. begin
  5070. J := 1;
  5071. while (I + J < Length(V)) and (V[I + J] = Find) do
  5072. Inc(J);
  5073. DynArrayRemove(V, I, J);
  5074. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5075. end;
  5076. end;
  5077. procedure DynArrayRemoveAll(const Find: SmallInt; var V: SmallIntArray; const IsSortedAscending: Boolean = False);
  5078. var I, J : Integer;
  5079. begin
  5080. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5081. while I >= 0 do
  5082. begin
  5083. J := 1;
  5084. while (I + J < Length(V)) and (V[I + J] = Find) do
  5085. Inc(J);
  5086. DynArrayRemove(V, I, J);
  5087. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5088. end;
  5089. end;
  5090. procedure DynArrayRemoveAll(const Find: LongInt; var V: LongIntArray; const IsSortedAscending: Boolean = False);
  5091. var I, J : Integer;
  5092. begin
  5093. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5094. while I >= 0 do
  5095. begin
  5096. J := 1;
  5097. while (I + J < Length(V)) and (V[I + J] = Find) do
  5098. Inc(J);
  5099. DynArrayRemove(V, I, J);
  5100. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5101. end;
  5102. end;
  5103. procedure DynArrayRemoveAll(const Find: Int64; var V: Int64Array; const IsSortedAscending: Boolean = False);
  5104. var I, J : Integer;
  5105. begin
  5106. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5107. while I >= 0 do
  5108. begin
  5109. J := 1;
  5110. while (I + J < Length(V)) and (V[I + J] = Find) do
  5111. Inc(J);
  5112. DynArrayRemove(V, I, J);
  5113. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5114. end;
  5115. end;
  5116. procedure DynArrayRemoveAll(const Find: Single; var V: SingleArray; const IsSortedAscending: Boolean = False);
  5117. var I, J : Integer;
  5118. begin
  5119. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5120. while I >= 0 do
  5121. begin
  5122. J := 1;
  5123. while (I + J < Length(V)) and (V[I + J] = Find) do
  5124. Inc(J);
  5125. DynArrayRemove(V, I, J);
  5126. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5127. end;
  5128. end;
  5129. procedure DynArrayRemoveAll(const Find: Double; var V: DoubleArray; const IsSortedAscending: Boolean = False);
  5130. var I, J : Integer;
  5131. begin
  5132. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5133. while I >= 0 do
  5134. begin
  5135. J := 1;
  5136. while (I + J < Length(V)) and (V[I + J] = Find) do
  5137. Inc(J);
  5138. DynArrayRemove(V, I, J);
  5139. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5140. end;
  5141. end;
  5142. procedure DynArrayRemoveAll(const Find: Extended; var V: ExtendedArray; const IsSortedAscending: Boolean = False);
  5143. var I, J : Integer;
  5144. begin
  5145. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5146. while I >= 0 do
  5147. begin
  5148. J := 1;
  5149. while (I + J < Length(V)) and (V[I + J] = Find) do
  5150. Inc(J);
  5151. DynArrayRemove(V, I, J);
  5152. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5153. end;
  5154. end;
  5155. procedure DynArrayRemoveAllA(const Find: AnsiString; var V: AnsiStringArray; const IsSortedAscending: Boolean = False);
  5156. var I, J : Integer;
  5157. begin
  5158. I := DynArrayPosNextA(Find, V, -1, IsSortedAscending);
  5159. while I >= 0 do
  5160. begin
  5161. J := 1;
  5162. while (I + J < Length(V)) and (V[I + J] = Find) do
  5163. Inc(J);
  5164. DynArrayRemoveA(V, I, J);
  5165. I := DynArrayPosNextA(Find, V, I, IsSortedAscending);
  5166. end;
  5167. end;
  5168. procedure DynArrayRemoveAllW(const Find: WideString; var V: WideStringArray; const IsSortedAscending: Boolean = False);
  5169. var I, J : Integer;
  5170. begin
  5171. I := DynArrayPosNextW(Find, V, -1, IsSortedAscending);
  5172. while I >= 0 do
  5173. begin
  5174. J := 1;
  5175. while (I + J < Length(V)) and (V[I + J] = Find) do
  5176. Inc(J);
  5177. DynArrayRemoveW(V, I, J);
  5178. I := DynArrayPosNextW(Find, V, I, IsSortedAscending);
  5179. end;
  5180. end;
  5181. procedure DynArrayRemoveAllU(const Find: UnicodeString; var V: UnicodeStringArray; const IsSortedAscending: Boolean = False);
  5182. var I, J : Integer;
  5183. begin
  5184. I := DynArrayPosNextU(Find, V, -1, IsSortedAscending);
  5185. while I >= 0 do
  5186. begin
  5187. J := 1;
  5188. while (I + J < Length(V)) and (V[I + J] = Find) do
  5189. Inc(J);
  5190. DynArrayRemoveU(V, I, J);
  5191. I := DynArrayPosNextU(Find, V, I, IsSortedAscending);
  5192. end;
  5193. end;
  5194. procedure DynArrayRemoveAll(const Find: String; var V: StringArray; const IsSortedAscending: Boolean = False);
  5195. var I, J : Integer;
  5196. begin
  5197. I := DynArrayPosNext(Find, V, -1, IsSortedAscending);
  5198. while I >= 0 do
  5199. begin
  5200. J := 1;
  5201. while (I + J < Length(V)) and (V[I + J] = Find) do
  5202. Inc(J);
  5203. DynArrayRemove(V, I, J);
  5204. I := DynArrayPosNext(Find, V, I, IsSortedAscending);
  5205. end;
  5206. end;
  5207. { }
  5208. { DynArrayIntersection }
  5209. { If both arrays are sorted ascending then time is o(n) instead of o(n^2). }
  5210. { }
  5211. function DynArrayIntersection(const V1, V2: SingleArray; const IsSortedAscending: Boolean): SingleArray;
  5212. var I, J, L, LV : Integer;
  5213. begin
  5214. SetLength(Result, 0);
  5215. if IsSortedAscending then
  5216. begin
  5217. I := 0;
  5218. J := 0;
  5219. L := Length(V1);
  5220. LV := Length(V2);
  5221. while (I < L) and (J < LV) do
  5222. begin
  5223. while (I < L) and (V1[I] < V2[J]) do
  5224. Inc(I);
  5225. if I < L then
  5226. begin
  5227. if V1[I] = V2[J] then
  5228. DynArrayAppend(Result, V1[I]);
  5229. while (J < LV) and (V2[J] <= V1[I]) do
  5230. Inc(J);
  5231. end;
  5232. end;
  5233. end
  5234. else
  5235. for I := 0 to Length(V1) - 1 do
  5236. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5237. DynArrayAppend(Result, V1[I]);
  5238. end;
  5239. function DynArrayIntersection(const V1, V2: DoubleArray; const IsSortedAscending: Boolean): DoubleArray;
  5240. var I, J, L, LV : Integer;
  5241. begin
  5242. SetLength(Result, 0);
  5243. if IsSortedAscending then
  5244. begin
  5245. I := 0;
  5246. J := 0;
  5247. L := Length(V1);
  5248. LV := Length(V2);
  5249. while (I < L) and (J < LV) do
  5250. begin
  5251. while (I < L) and (V1[I] < V2[J]) do
  5252. Inc(I);
  5253. if I < L then
  5254. begin
  5255. if V1[I] = V2[J] then
  5256. DynArrayAppend(Result, V1[I]);
  5257. while (J < LV) and (V2[J] <= V1[I]) do
  5258. Inc(J);
  5259. end;
  5260. end;
  5261. end
  5262. else
  5263. for I := 0 to Length(V1) - 1 do
  5264. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5265. DynArrayAppend(Result, V1[I]);
  5266. end;
  5267. function DynArrayIntersection(const V1, V2: ExtendedArray; const IsSortedAscending: Boolean): ExtendedArray;
  5268. var I, J, L, LV : Integer;
  5269. begin
  5270. SetLength(Result, 0);
  5271. if IsSortedAscending then
  5272. begin
  5273. I := 0;
  5274. J := 0;
  5275. L := Length(V1);
  5276. LV := Length(V2);
  5277. while (I < L) and (J < LV) do
  5278. begin
  5279. while (I < L) and (V1[I] < V2[J]) do
  5280. Inc(I);
  5281. if I < L then
  5282. begin
  5283. if V1[I] = V2[J] then
  5284. DynArrayAppend(Result, V1[I]);
  5285. while (J < LV) and (V2[J] <= V1[I]) do
  5286. Inc(J);
  5287. end;
  5288. end;
  5289. end
  5290. else
  5291. for I := 0 to Length(V1) - 1 do
  5292. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5293. DynArrayAppend(Result, V1[I]);
  5294. end;
  5295. function DynArrayIntersection(const V1, V2: ByteArray; const IsSortedAscending: Boolean): ByteArray;
  5296. var I, J, L, LV : Integer;
  5297. begin
  5298. SetLength(Result, 0);
  5299. if IsSortedAscending then
  5300. begin
  5301. I := 0;
  5302. J := 0;
  5303. L := Length(V1);
  5304. LV := Length(V2);
  5305. while (I < L) and (J < LV) do
  5306. begin
  5307. while (I < L) and (V1[I] < V2[J]) do
  5308. Inc(I);
  5309. if I < L then
  5310. begin
  5311. if V1[I] = V2[J] then
  5312. DynArrayAppend(Result, V1[I]);
  5313. while (J < LV) and (V2[J] <= V1[I]) do
  5314. Inc(J);
  5315. end;
  5316. end;
  5317. end
  5318. else
  5319. for I := 0 to Length(V1) - 1 do
  5320. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5321. DynArrayAppend(Result, V1[I]);
  5322. end;
  5323. function DynArrayIntersection(const V1, V2: WordArray; const IsSortedAscending: Boolean): WordArray;
  5324. var I, J, L, LV : Integer;
  5325. begin
  5326. SetLength(Result, 0);
  5327. if IsSortedAscending then
  5328. begin
  5329. I := 0;
  5330. J := 0;
  5331. L := Length(V1);
  5332. LV := Length(V2);
  5333. while (I < L) and (J < LV) do
  5334. begin
  5335. while (I < L) and (V1[I] < V2[J]) do
  5336. Inc(I);
  5337. if I < L then
  5338. begin
  5339. if V1[I] = V2[J] then
  5340. DynArrayAppend(Result, V1[I]);
  5341. while (J < LV) and (V2[J] <= V1[I]) do
  5342. Inc(J);
  5343. end;
  5344. end;
  5345. end
  5346. else
  5347. for I := 0 to Length(V1) - 1 do
  5348. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5349. DynArrayAppend(Result, V1[I]);
  5350. end;
  5351. function DynArrayIntersection(const V1, V2: LongWordArray; const IsSortedAscending: Boolean): LongWordArray;
  5352. var I, J, L, LV : Integer;
  5353. begin
  5354. SetLength(Result, 0);
  5355. if IsSortedAscending then
  5356. begin
  5357. I := 0;
  5358. J := 0;
  5359. L := Length(V1);
  5360. LV := Length(V2);
  5361. while (I < L) and (J < LV) do
  5362. begin
  5363. while (I < L) and (V1[I] < V2[J]) do
  5364. Inc(I);
  5365. if I < L then
  5366. begin
  5367. if V1[I] = V2[J] then
  5368. DynArrayAppend(Result, V1[I]);
  5369. while (J < LV) and (V2[J] <= V1[I]) do
  5370. Inc(J);
  5371. end;
  5372. end;
  5373. end
  5374. else
  5375. for I := 0 to Length(V1) - 1 do
  5376. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5377. DynArrayAppend(Result, V1[I]);
  5378. end;
  5379. function DynArrayIntersection(const V1, V2: ShortIntArray; const IsSortedAscending: Boolean): ShortIntArray;
  5380. var I, J, L, LV : Integer;
  5381. begin
  5382. SetLength(Result, 0);
  5383. if IsSortedAscending then
  5384. begin
  5385. I := 0;
  5386. J := 0;
  5387. L := Length(V1);
  5388. LV := Length(V2);
  5389. while (I < L) and (J < LV) do
  5390. begin
  5391. while (I < L) and (V1[I] < V2[J]) do
  5392. Inc(I);
  5393. if I < L then
  5394. begin
  5395. if V1[I] = V2[J] then
  5396. DynArrayAppend(Result, V1[I]);
  5397. while (J < LV) and (V2[J] <= V1[I]) do
  5398. Inc(J);
  5399. end;
  5400. end;
  5401. end
  5402. else
  5403. for I := 0 to Length(V1) - 1 do
  5404. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5405. DynArrayAppend(Result, V1[I]);
  5406. end;
  5407. function DynArrayIntersection(const V1, V2: SmallIntArray; const IsSortedAscending: Boolean): SmallIntArray;
  5408. var I, J, L, LV : Integer;
  5409. begin
  5410. SetLength(Result, 0);
  5411. if IsSortedAscending then
  5412. begin
  5413. I := 0;
  5414. J := 0;
  5415. L := Length(V1);
  5416. LV := Length(V2);
  5417. while (I < L) and (J < LV) do
  5418. begin
  5419. while (I < L) and (V1[I] < V2[J]) do
  5420. Inc(I);
  5421. if I < L then
  5422. begin
  5423. if V1[I] = V2[J] then
  5424. DynArrayAppend(Result, V1[I]);
  5425. while (J < LV) and (V2[J] <= V1[I]) do
  5426. Inc(J);
  5427. end;
  5428. end;
  5429. end
  5430. else
  5431. for I := 0 to Length(V1) - 1 do
  5432. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5433. DynArrayAppend(Result, V1[I]);
  5434. end;
  5435. function DynArrayIntersection(const V1, V2: LongIntArray; const IsSortedAscending: Boolean): LongIntArray;
  5436. var I, J, L, LV : Integer;
  5437. begin
  5438. SetLength(Result, 0);
  5439. if IsSortedAscending then
  5440. begin
  5441. I := 0;
  5442. J := 0;
  5443. L := Length(V1);
  5444. LV := Length(V2);
  5445. while (I < L) and (J < LV) do
  5446. begin
  5447. while (I < L) and (V1[I] < V2[J]) do
  5448. Inc(I);
  5449. if I < L then
  5450. begin
  5451. if V1[I] = V2[J] then
  5452. DynArrayAppend(Result, V1[I]);
  5453. while (J < LV) and (V2[J] <= V1[I]) do
  5454. Inc(J);
  5455. end;
  5456. end;
  5457. end
  5458. else
  5459. for I := 0 to Length(V1) - 1 do
  5460. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5461. DynArrayAppend(Result, V1[I]);
  5462. end;
  5463. function DynArrayIntersection(const V1, V2: Int64Array; const IsSortedAscending: Boolean): Int64Array;
  5464. var I, J, L, LV : Integer;
  5465. begin
  5466. SetLength(Result, 0);
  5467. if IsSortedAscending then
  5468. begin
  5469. I := 0;
  5470. J := 0;
  5471. L := Length(V1);
  5472. LV := Length(V2);
  5473. while (I < L) and (J < LV) do
  5474. begin
  5475. while (I < L) and (V1[I] < V2[J]) do
  5476. Inc(I);
  5477. if I < L then
  5478. begin
  5479. if V1[I] = V2[J] then
  5480. DynArrayAppend(Result, V1[I]);
  5481. while (J < LV) and (V2[J] <= V1[I]) do
  5482. Inc(J);
  5483. end;
  5484. end;
  5485. end
  5486. else
  5487. for I := 0 to Length(V1) - 1 do
  5488. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5489. DynArrayAppend(Result, V1[I]);
  5490. end;
  5491. function DynArrayIntersectionA(const V1, V2: AnsiStringArray; const IsSortedAscending: Boolean): AnsiStringArray;
  5492. var I, J, L, LV : Integer;
  5493. begin
  5494. SetLength(Result, 0);
  5495. if IsSortedAscending then
  5496. begin
  5497. I := 0;
  5498. J := 0;
  5499. L := Length(V1);
  5500. LV := Length(V2);
  5501. while (I < L) and (J < LV) do
  5502. begin
  5503. while (I < L) and (V1[I] < V2[J]) do
  5504. Inc(I);
  5505. if I < L then
  5506. begin
  5507. if V1[I] = V2[J] then
  5508. DynArrayAppendA(Result, V1[I]);
  5509. while (J < LV) and (V2[J] <= V1[I]) do
  5510. Inc(J);
  5511. end;
  5512. end;
  5513. end
  5514. else
  5515. for I := 0 to Length(V1) - 1 do
  5516. if (DynArrayPosNextA(V1[I], V2) >= 0) and (DynArrayPosNextA(V1[I], Result) = -1) then
  5517. DynArrayAppendA(Result, V1[I]);
  5518. end;
  5519. function DynArrayIntersectionW(const V1, V2: WideStringArray; const IsSortedAscending: Boolean): WideStringArray;
  5520. var I, J, L, LV : Integer;
  5521. begin
  5522. SetLength(Result, 0);
  5523. if IsSortedAscending then
  5524. begin
  5525. I := 0;
  5526. J := 0;
  5527. L := Length(V1);
  5528. LV := Length(V2);
  5529. while (I < L) and (J < LV) do
  5530. begin
  5531. while (I < L) and (V1[I] < V2[J]) do
  5532. Inc(I);
  5533. if I < L then
  5534. begin
  5535. if V1[I] = V2[J] then
  5536. DynArrayAppendW(Result, V1[I]);
  5537. while (J < LV) and (V2[J] <= V1[I]) do
  5538. Inc(J);
  5539. end;
  5540. end;
  5541. end
  5542. else
  5543. for I := 0 to Length(V1) - 1 do
  5544. if (DynArrayPosNextW(V1[I], V2) >= 0) and (DynArrayPosNextW(V1[I], Result) = -1) then
  5545. DynArrayAppendW(Result, V1[I]);
  5546. end;
  5547. function DynArrayIntersectionU(const V1, V2: UnicodeStringArray; const IsSortedAscending: Boolean): UnicodeStringArray;
  5548. var I, J, L, LV : Integer;
  5549. begin
  5550. SetLength(Result, 0);
  5551. if IsSortedAscending then
  5552. begin
  5553. I := 0;
  5554. J := 0;
  5555. L := Length(V1);
  5556. LV := Length(V2);
  5557. while (I < L) and (J < LV) do
  5558. begin
  5559. while (I < L) and (V1[I] < V2[J]) do
  5560. Inc(I);
  5561. if I < L then
  5562. begin
  5563. if V1[I] = V2[J] then
  5564. DynArrayAppendU(Result, V1[I]);
  5565. while (J < LV) and (V2[J] <= V1[I]) do
  5566. Inc(J);
  5567. end;
  5568. end;
  5569. end
  5570. else
  5571. for I := 0 to Length(V1) - 1 do
  5572. if (DynArrayPosNextU(V1[I], V2) >= 0) and (DynArrayPosNextU(V1[I], Result) = -1) then
  5573. DynArrayAppendU(Result, V1[I]);
  5574. end;
  5575. function DynArrayIntersection(const V1, V2: StringArray; const IsSortedAscending: Boolean): StringArray;
  5576. var I, J, L, LV : Integer;
  5577. begin
  5578. SetLength(Result, 0);
  5579. if IsSortedAscending then
  5580. begin
  5581. I := 0;
  5582. J := 0;
  5583. L := Length(V1);
  5584. LV := Length(V2);
  5585. while (I < L) and (J < LV) do
  5586. begin
  5587. while (I < L) and (V1[I] < V2[J]) do
  5588. Inc(I);
  5589. if I < L then
  5590. begin
  5591. if V1[I] = V2[J] then
  5592. DynArrayAppend(Result, V1[I]);
  5593. while (J < LV) and (V2[J] <= V1[I]) do
  5594. Inc(J);
  5595. end;
  5596. end;
  5597. end
  5598. else
  5599. for I := 0 to Length(V1) - 1 do
  5600. if (DynArrayPosNext(V1[I], V2) >= 0) and (DynArrayPosNext(V1[I], Result) = -1) then
  5601. DynArrayAppend(Result, V1[I]);
  5602. end;
  5603. { }
  5604. { DynArrayDifference }
  5605. { Returns elements in V1 but not in V2. }
  5606. { If both arrays are sorted ascending then time is o(n) instead of o(n^2). }
  5607. { }
  5608. function DynArrayDifference(const V1, V2: SingleArray; const IsSortedAscending: Boolean): SingleArray;
  5609. var I, J, L, LV : Integer;
  5610. begin
  5611. SetLength(Result, 0);
  5612. if IsSortedAscending then
  5613. begin
  5614. I := 0;
  5615. J := 0;
  5616. L := Length(V1);
  5617. LV := Length(V2);
  5618. while (I < L) and (J < LV) do
  5619. begin
  5620. while (I < L) and (V1[I] < V2[J]) do
  5621. Inc(I);
  5622. if I < L then
  5623. begin
  5624. if V1[I] <> V2[J] then
  5625. DynArrayAppend(Result, V1[I]);
  5626. while (J < LV) and (V2[J] <= V1[I]) do
  5627. Inc(J);
  5628. end;
  5629. end;
  5630. end
  5631. else
  5632. for I := 0 to Length(V1) - 1 do
  5633. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5634. DynArrayAppend(Result, V1[I]);
  5635. end;
  5636. function DynArrayDifference(const V1, V2: DoubleArray; const IsSortedAscending: Boolean): DoubleArray;
  5637. var I, J, L, LV : Integer;
  5638. begin
  5639. SetLength(Result, 0);
  5640. if IsSortedAscending then
  5641. begin
  5642. I := 0;
  5643. J := 0;
  5644. L := Length(V1);
  5645. LV := Length(V2);
  5646. while (I < L) and (J < LV) do
  5647. begin
  5648. while (I < L) and (V1[I] < V2[J]) do
  5649. Inc(I);
  5650. if I < L then
  5651. begin
  5652. if V1[I] <> V2[J] then
  5653. DynArrayAppend(Result, V1[I]);
  5654. while (J < LV) and (V2[J] <= V1[I]) do
  5655. Inc(J);
  5656. end;
  5657. end;
  5658. end
  5659. else
  5660. for I := 0 to Length(V1) - 1 do
  5661. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5662. DynArrayAppend(Result, V1[I]);
  5663. end;
  5664. function DynArrayDifference(const V1, V2: ExtendedArray; const IsSortedAscending: Boolean): ExtendedArray;
  5665. var I, J, L, LV : Integer;
  5666. begin
  5667. SetLength(Result, 0);
  5668. if IsSortedAscending then
  5669. begin
  5670. I := 0;
  5671. J := 0;
  5672. L := Length(V1);
  5673. LV := Length(V2);
  5674. while (I < L) and (J < LV) do
  5675. begin
  5676. while (I < L) and (V1[I] < V2[J]) do
  5677. Inc(I);
  5678. if I < L then
  5679. begin
  5680. if V1[I] <> V2[J] then
  5681. DynArrayAppend(Result, V1[I]);
  5682. while (J < LV) and (V2[J] <= V1[I]) do
  5683. Inc(J);
  5684. end;
  5685. end;
  5686. end
  5687. else
  5688. for I := 0 to Length(V1) - 1 do
  5689. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5690. DynArrayAppend(Result, V1[I]);
  5691. end;
  5692. function DynArrayDifference(const V1, V2: ByteArray; const IsSortedAscending: Boolean): ByteArray;
  5693. var I, J, L, LV : Integer;
  5694. begin
  5695. SetLength(Result, 0);
  5696. if IsSortedAscending then
  5697. begin
  5698. I := 0;
  5699. J := 0;
  5700. L := Length(V1);
  5701. LV := Length(V2);
  5702. while (I < L) and (J < LV) do
  5703. begin
  5704. while (I < L) and (V1[I] < V2[J]) do
  5705. Inc(I);
  5706. if I < L then
  5707. begin
  5708. if V1[I] <> V2[J] then
  5709. DynArrayAppend(Result, V1[I]);
  5710. while (J < LV) and (V2[J] <= V1[I]) do
  5711. Inc(J);
  5712. end;
  5713. end;
  5714. end
  5715. else
  5716. for I := 0 to Length(V1) - 1 do
  5717. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5718. DynArrayAppend(Result, V1[I]);
  5719. end;
  5720. function DynArrayDifference(const V1, V2: WordArray; const IsSortedAscending: Boolean): WordArray;
  5721. var I, J, L, LV : Integer;
  5722. begin
  5723. SetLength(Result, 0);
  5724. if IsSortedAscending then
  5725. begin
  5726. I := 0;
  5727. J := 0;
  5728. L := Length(V1);
  5729. LV := Length(V2);
  5730. while (I < L) and (J < LV) do
  5731. begin
  5732. while (I < L) and (V1[I] < V2[J]) do
  5733. Inc(I);
  5734. if I < L then
  5735. begin
  5736. if V1[I] <> V2[J] then
  5737. DynArrayAppend(Result, V1[I]);
  5738. while (J < LV) and (V2[J] <= V1[I]) do
  5739. Inc(J);
  5740. end;
  5741. end;
  5742. end
  5743. else
  5744. for I := 0 to Length(V1) - 1 do
  5745. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5746. DynArrayAppend(Result, V1[I]);
  5747. end;
  5748. function DynArrayDifference(const V1, V2: LongWordArray; const IsSortedAscending: Boolean): LongWordArray;
  5749. var I, J, L, LV : Integer;
  5750. begin
  5751. SetLength(Result, 0);
  5752. if IsSortedAscending then
  5753. begin
  5754. I := 0;
  5755. J := 0;
  5756. L := Length(V1);
  5757. LV := Length(V2);
  5758. while (I < L) and (J < LV) do
  5759. begin
  5760. while (I < L) and (V1[I] < V2[J]) do
  5761. Inc(I);
  5762. if I < L then
  5763. begin
  5764. if V1[I] <> V2[J] then
  5765. DynArrayAppend(Result, V1[I]);
  5766. while (J < LV) and (V2[J] <= V1[I]) do
  5767. Inc(J);
  5768. end;
  5769. end;
  5770. end
  5771. else
  5772. for I := 0 to Length(V1) - 1 do
  5773. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5774. DynArrayAppend(Result, V1[I]);
  5775. end;
  5776. function DynArrayDifference(const V1, V2: ShortIntArray; const IsSortedAscending: Boolean): ShortIntArray;
  5777. var I, J, L, LV : Integer;
  5778. begin
  5779. SetLength(Result, 0);
  5780. if IsSortedAscending then
  5781. begin
  5782. I := 0;
  5783. J := 0;
  5784. L := Length(V1);
  5785. LV := Length(V2);
  5786. while (I < L) and (J < LV) do
  5787. begin
  5788. while (I < L) and (V1[I] < V2[J]) do
  5789. Inc(I);
  5790. if I < L then
  5791. begin
  5792. if V1[I] <> V2[J] then
  5793. DynArrayAppend(Result, V1[I]);
  5794. while (J < LV) and (V2[J] <= V1[I]) do
  5795. Inc(J);
  5796. end;
  5797. end;
  5798. end
  5799. else
  5800. for I := 0 to Length(V1) - 1 do
  5801. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5802. DynArrayAppend(Result, V1[I]);
  5803. end;
  5804. function DynArrayDifference(const V1, V2: SmallIntArray; const IsSortedAscending: Boolean): SmallIntArray;
  5805. var I, J, L, LV : Integer;
  5806. begin
  5807. SetLength(Result, 0);
  5808. if IsSortedAscending then
  5809. begin
  5810. I := 0;
  5811. J := 0;
  5812. L := Length(V1);
  5813. LV := Length(V2);
  5814. while (I < L) and (J < LV) do
  5815. begin
  5816. while (I < L) and (V1[I] < V2[J]) do
  5817. Inc(I);
  5818. if I < L then
  5819. begin
  5820. if V1[I] <> V2[J] then
  5821. DynArrayAppend(Result, V1[I]);
  5822. while (J < LV) and (V2[J] <= V1[I]) do
  5823. Inc(J);
  5824. end;
  5825. end;
  5826. end
  5827. else
  5828. for I := 0 to Length(V1) - 1 do
  5829. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5830. DynArrayAppend(Result, V1[I]);
  5831. end;
  5832. function DynArrayDifference(const V1, V2: LongIntArray; const IsSortedAscending: Boolean): LongIntArray;
  5833. var I, J, L, LV : Integer;
  5834. begin
  5835. SetLength(Result, 0);
  5836. if IsSortedAscending then
  5837. begin
  5838. I := 0;
  5839. J := 0;
  5840. L := Length(V1);
  5841. LV := Length(V2);
  5842. while (I < L) and (J < LV) do
  5843. begin
  5844. while (I < L) and (V1[I] < V2[J]) do
  5845. Inc(I);
  5846. if I < L then
  5847. begin
  5848. if V1[I] <> V2[J] then
  5849. DynArrayAppend(Result, V1[I]);
  5850. while (J < LV) and (V2[J] <= V1[I]) do
  5851. Inc(J);
  5852. end;
  5853. end;
  5854. end
  5855. else
  5856. for I := 0 to Length(V1) - 1 do
  5857. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5858. DynArrayAppend(Result, V1[I]);
  5859. end;
  5860. function DynArrayDifference(const V1, V2: Int64Array; const IsSortedAscending: Boolean): Int64Array;
  5861. var I, J, L, LV : Integer;
  5862. begin
  5863. SetLength(Result, 0);
  5864. if IsSortedAscending then
  5865. begin
  5866. I := 0;
  5867. J := 0;
  5868. L := Length(V1);
  5869. LV := Length(V2);
  5870. while (I < L) and (J < LV) do
  5871. begin
  5872. while (I < L) and (V1[I] < V2[J]) do
  5873. Inc(I);
  5874. if I < L then
  5875. begin
  5876. if V1[I] <> V2[J] then
  5877. DynArrayAppend(Result, V1[I]);
  5878. while (J < LV) and (V2[J] <= V1[I]) do
  5879. Inc(J);
  5880. end;
  5881. end;
  5882. end
  5883. else
  5884. for I := 0 to Length(V1) - 1 do
  5885. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5886. DynArrayAppend(Result, V1[I]);
  5887. end;
  5888. function DynArrayDifferenceA(const V1, V2: AnsiStringArray; const IsSortedAscending: Boolean): AnsiStringArray;
  5889. var I, J, L, LV : Integer;
  5890. begin
  5891. SetLength(Result, 0);
  5892. if IsSortedAscending then
  5893. begin
  5894. I := 0;
  5895. J := 0;
  5896. L := Length(V1);
  5897. LV := Length(V2);
  5898. while (I < L) and (J < LV) do
  5899. begin
  5900. while (I < L) and (V1[I] < V2[J]) do
  5901. Inc(I);
  5902. if I < L then
  5903. begin
  5904. if V1[I] <> V2[J] then
  5905. DynArrayAppendA(Result, V1[I]);
  5906. while (J < LV) and (V2[J] <= V1[I]) do
  5907. Inc(J);
  5908. end;
  5909. end;
  5910. end
  5911. else
  5912. for I := 0 to Length(V1) - 1 do
  5913. if (DynArrayPosNextA(V1[I], V2) = -1) and (DynArrayPosNextA(V1[I], Result) = -1) then
  5914. DynArrayAppendA(Result, V1[I]);
  5915. end;
  5916. function DynArrayDifferenceW(const V1, V2: WideStringArray; const IsSortedAscending: Boolean): WideStringArray;
  5917. var I, J, L, LV : Integer;
  5918. begin
  5919. SetLength(Result, 0);
  5920. if IsSortedAscending then
  5921. begin
  5922. I := 0;
  5923. J := 0;
  5924. L := Length(V1);
  5925. LV := Length(V2);
  5926. while (I < L) and (J < LV) do
  5927. begin
  5928. while (I < L) and (V1[I] < V2[J]) do
  5929. Inc(I);
  5930. if I < L then
  5931. begin
  5932. if V1[I] <> V2[J] then
  5933. DynArrayAppendW(Result, V1[I]);
  5934. while (J < LV) and (V2[J] <= V1[I]) do
  5935. Inc(J);
  5936. end;
  5937. end;
  5938. end
  5939. else
  5940. for I := 0 to Length(V1) - 1 do
  5941. if (DynArrayPosNextW(V1[I], V2) = -1) and (DynArrayPosNextW(V1[I], Result) = -1) then
  5942. DynArrayAppendW(Result, V1[I]);
  5943. end;
  5944. function DynArrayDifferenceU(const V1, V2: UnicodeStringArray; const IsSortedAscending: Boolean): UnicodeStringArray;
  5945. var I, J, L, LV : Integer;
  5946. begin
  5947. SetLength(Result, 0);
  5948. if IsSortedAscending then
  5949. begin
  5950. I := 0;
  5951. J := 0;
  5952. L := Length(V1);
  5953. LV := Length(V2);
  5954. while (I < L) and (J < LV) do
  5955. begin
  5956. while (I < L) and (V1[I] < V2[J]) do
  5957. Inc(I);
  5958. if I < L then
  5959. begin
  5960. if V1[I] <> V2[J] then
  5961. DynArrayAppendU(Result, V1[I]);
  5962. while (J < LV) and (V2[J] <= V1[I]) do
  5963. Inc(J);
  5964. end;
  5965. end;
  5966. end
  5967. else
  5968. for I := 0 to Length(V1) - 1 do
  5969. if (DynArrayPosNextU(V1[I], V2) = -1) and (DynArrayPosNextU(V1[I], Result) = -1) then
  5970. DynArrayAppendU(Result, V1[I]);
  5971. end;
  5972. function DynArrayDifference(const V1, V2: StringArray; const IsSortedAscending: Boolean): StringArray;
  5973. var I, J, L, LV : Integer;
  5974. begin
  5975. SetLength(Result, 0);
  5976. if IsSortedAscending then
  5977. begin
  5978. I := 0;
  5979. J := 0;
  5980. L := Length(V1);
  5981. LV := Length(V2);
  5982. while (I < L) and (J < LV) do
  5983. begin
  5984. while (I < L) and (V1[I] < V2[J]) do
  5985. Inc(I);
  5986. if I < L then
  5987. begin
  5988. if V1[I] <> V2[J] then
  5989. DynArrayAppend(Result, V1[I]);
  5990. while (J < LV) and (V2[J] <= V1[I]) do
  5991. Inc(J);
  5992. end;
  5993. end;
  5994. end
  5995. else
  5996. for I := 0 to Length(V1) - 1 do
  5997. if (DynArrayPosNext(V1[I], V2) = -1) and (DynArrayPosNext(V1[I], Result) = -1) then
  5998. DynArrayAppend(Result, V1[I]);
  5999. end;
  6000. { }
  6001. { DynArrayReverse }
  6002. { }
  6003. procedure DynArrayReverse(var V: ByteArray);
  6004. var I, L : Integer;
  6005. begin
  6006. L := Length(V);
  6007. for I := 1 to L div 2 do
  6008. Swap(V[I - 1], V[L - I]);
  6009. end;
  6010. procedure DynArrayReverse(var V: WordArray);
  6011. var I, L : Integer;
  6012. begin
  6013. L := Length(V);
  6014. for I := 1 to L div 2 do
  6015. Swap(V[I - 1], V[L - I]);
  6016. end;
  6017. procedure DynArrayReverse(var V: LongWordArray);
  6018. var I, L : Integer;
  6019. begin
  6020. L := Length(V);
  6021. for I := 1 to L div 2 do
  6022. Swap(V[I - 1], V[L - I]);
  6023. end;
  6024. procedure DynArrayReverse(var V: ShortIntArray);
  6025. var I, L : Integer;
  6026. begin
  6027. L := Length(V);
  6028. for I := 1 to L div 2 do
  6029. Swap(V[I - 1], V[L - I]);
  6030. end;
  6031. procedure DynArrayReverse(var V: SmallIntArray);
  6032. var I, L : Integer;
  6033. begin
  6034. L := Length(V);
  6035. for I := 1 to L div 2 do
  6036. Swap(V[I - 1], V[L - I]);
  6037. end;
  6038. procedure DynArrayReverse(var V: LongIntArray);
  6039. var I, L : Integer;
  6040. begin
  6041. L := Length(V);
  6042. for I := 1 to L div 2 do
  6043. Swap(V[I - 1], V[L - I]);
  6044. end;
  6045. procedure DynArrayReverse(var V: Int64Array);
  6046. var I, L : Integer;
  6047. begin
  6048. L := Length(V);
  6049. for I := 1 to L div 2 do
  6050. Swap(V[I - 1], V[L - I]);
  6051. end;
  6052. procedure DynArrayReverseA(var V: AnsiStringArray);
  6053. var I, L : Integer;
  6054. begin
  6055. L := Length(V);
  6056. for I := 1 to L div 2 do
  6057. SwapA(V[I - 1], V[L - I]);
  6058. end;
  6059. procedure DynArrayReverseW(var V: WideStringArray);
  6060. var I, L : Integer;
  6061. begin
  6062. L := Length(V);
  6063. for I := 1 to L div 2 do
  6064. SwapW(V[I - 1], V[L - I]);
  6065. end;
  6066. procedure DynArrayReverseU(var V: UnicodeStringArray);
  6067. var I, L : Integer;
  6068. begin
  6069. L := Length(V);
  6070. for I := 1 to L div 2 do
  6071. SwapU(V[I - 1], V[L - I]);
  6072. end;
  6073. procedure DynArrayReverse(var V: StringArray);
  6074. var I, L : Integer;
  6075. begin
  6076. L := Length(V);
  6077. for I := 1 to L div 2 do
  6078. Swap(V[I - 1], V[L - I]);
  6079. end;
  6080. {$IFNDEF ManagedCode}
  6081. procedure DynArrayReverse(var V: PointerArray);
  6082. var I, L : Integer;
  6083. begin
  6084. L := Length(V);
  6085. for I := 1 to L div 2 do
  6086. Swap(V[I - 1], V[L - I]);
  6087. end;
  6088. {$ENDIF}
  6089. procedure DynArrayReverse(var V: ObjectArray);
  6090. var I, L : Integer;
  6091. begin
  6092. L := Length(V);
  6093. for I := 1 to L div 2 do
  6094. Swap(V[I - 1], V[L - I]);
  6095. end;
  6096. procedure DynArrayReverse(var V: SingleArray);
  6097. var I, L : Integer;
  6098. begin
  6099. L := Length(V);
  6100. for I := 1 to L div 2 do
  6101. Swap(V[I - 1], V[L - I]);
  6102. end;
  6103. procedure DynArrayReverse(var V: DoubleArray);
  6104. var I, L : Integer;
  6105. begin
  6106. L := Length(V);
  6107. for I := 1 to L div 2 do
  6108. Swap(V[I - 1], V[L - I]);
  6109. end;
  6110. procedure DynArrayReverse(var V: ExtendedArray);
  6111. var I, L : Integer;
  6112. begin
  6113. L := Length(V);
  6114. for I := 1 to L div 2 do
  6115. Swap(V[I - 1], V[L - I]);
  6116. end;
  6117. { }
  6118. { Returns an open array (V) as a dynamic array. }
  6119. { }
  6120. function AsBooleanArray(const V: array of Boolean): BooleanArray;
  6121. var I : Integer;
  6122. begin
  6123. SetLength(Result, High(V) + 1);
  6124. for I := 0 to High(V) do
  6125. Result[I] := V[I];
  6126. end;
  6127. function AsByteArray(const V: array of Byte): ByteArray;
  6128. var I : Integer;
  6129. begin
  6130. SetLength(Result, High(V) + 1);
  6131. for I := 0 to High(V) do
  6132. Result[I] := V[I];
  6133. end;
  6134. function AsWordArray(const V: array of Word): WordArray;
  6135. var I : Integer;
  6136. begin
  6137. SetLength(Result, High(V) + 1);
  6138. for I := 0 to High(V) do
  6139. Result[I] := V[I];
  6140. end;
  6141. function AsLongWordArray(const V: array of LongWord): LongWordArray;
  6142. var I : Integer;
  6143. begin
  6144. SetLength(Result, High(V) + 1);
  6145. for I := 0 to High(V) do
  6146. Result[I] := V[I];
  6147. end;
  6148. function AsCardinalArray(const V: array of Cardinal): CardinalArray;
  6149. var I : Integer;
  6150. begin
  6151. SetLength(Result, High(V) + 1);
  6152. for I := 0 to High(V) do
  6153. Result[I] := V[I];
  6154. end;
  6155. function AsNativeUIntArray(const V: array of NativeUInt): NativeUIntArray;
  6156. var I : Integer;
  6157. begin
  6158. SetLength(Result, High(V) + 1);
  6159. for I := 0 to High(V) do
  6160. Result[I] := V[I];
  6161. end;
  6162. function AsShortIntArray(const V: array of ShortInt): ShortIntArray;
  6163. var I : Integer;
  6164. begin
  6165. SetLength(Result, High(V) + 1);
  6166. for I := 0 to High(V) do
  6167. Result[I] := V[I];
  6168. end;
  6169. function AsSmallIntArray(const V: array of SmallInt): SmallIntArray;
  6170. var I : Integer;
  6171. begin
  6172. SetLength(Result, High(V) + 1);
  6173. for I := 0 to High(V) do
  6174. Result[I] := V[I];
  6175. end;
  6176. function AsLongIntArray(const V: array of LongInt): LongIntArray;
  6177. var I : Integer;
  6178. begin
  6179. SetLength(Result, High(V) + 1);
  6180. for I := 0 to High(V) do
  6181. Result[I] := V[I];
  6182. end;
  6183. function AsIntegerArray(const V: array of Integer): IntegerArray;
  6184. var I : Integer;
  6185. begin
  6186. SetLength(Result, High(V) + 1);
  6187. for I := 0 to High(V) do
  6188. Result[I] := V[I];
  6189. end;
  6190. function AsInt64Array(const V: array of Int64): Int64Array;
  6191. var I : Integer;
  6192. begin
  6193. SetLength(Result, High(V) + 1);
  6194. for I := 0 to High(V) do
  6195. Result[I] := V[I];
  6196. end;
  6197. function AsNativeIntArray(const V: array of NativeInt): NativeIntArray;
  6198. var I : Integer;
  6199. begin
  6200. SetLength(Result, High(V) + 1);
  6201. for I := 0 to High(V) do
  6202. Result[I] := V[I];
  6203. end;
  6204. function AsSingleArray(const V: array of Single): SingleArray;
  6205. var I : Integer;
  6206. begin
  6207. SetLength(Result, High(V) + 1);
  6208. for I := 0 to High(V) do
  6209. Result[I] := V[I];
  6210. end;
  6211. function AsDoubleArray(const V: array of Double): DoubleArray;
  6212. var I : Integer;
  6213. begin
  6214. SetLength(Result, High(V) + 1);
  6215. for I := 0 to High(V) do
  6216. Result[I] := V[I];
  6217. end;
  6218. function AsExtendedArray(const V: array of Extended): ExtendedArray;
  6219. var I : Integer;
  6220. begin
  6221. SetLength(Result, High(V) + 1);
  6222. for I := 0 to High(V) do
  6223. Result[I] := V[I];
  6224. end;
  6225. function AsCurrencyArray(const V: array of Currency): CurrencyArray;
  6226. var I : Integer;
  6227. begin
  6228. SetLength(Result, High(V) + 1);
  6229. for I := 0 to High(V) do
  6230. Result[I] := V[I];
  6231. end;
  6232. function AsAnsiStringArray(const V: array of AnsiString): AnsiStringArray;
  6233. var I : Integer;
  6234. begin
  6235. SetLength(Result, High(V) + 1);
  6236. for I := 0 to High(V) do
  6237. Result[I] := V[I];
  6238. end;
  6239. function AsWideStringArray(const V: array of WideString): WideStringArray;
  6240. var I : Integer;
  6241. begin
  6242. SetLength(Result, High(V) + 1);
  6243. for I := 0 to High(V) do
  6244. Result[I] := V[I];
  6245. end;
  6246. function AsUnicodeStringArray(const V: array of UnicodeString): UnicodeStringArray;
  6247. var I : Integer;
  6248. begin
  6249. SetLength(Result, High(V) + 1);
  6250. for I := 0 to High(V) do
  6251. Result[I] := V[I];
  6252. end;
  6253. function AsStringArray(const V: array of String): StringArray;
  6254. var I : Integer;
  6255. begin
  6256. SetLength(Result, High(V) + 1);
  6257. for I := 0 to High(V) do
  6258. Result[I] := V[I];
  6259. end;
  6260. {$IFNDEF ManagedCode}
  6261. function AsPointerArray(const V: array of Pointer): PointerArray;
  6262. var I : Integer;
  6263. begin
  6264. SetLength(Result, High(V) + 1);
  6265. for I := 0 to High(V) do
  6266. Result[I] := V[I];
  6267. end;
  6268. {$ENDIF}
  6269. function AsCharSetArray(const V: array of CharSet): CharSetArray;
  6270. var I : Integer;
  6271. begin
  6272. SetLength(Result, High(V) + 1);
  6273. for I := 0 to High(V) do
  6274. Result[I] := V[I];
  6275. end;
  6276. function AsObjectArray(const V: array of TObject): ObjectArray;
  6277. var I : Integer;
  6278. begin
  6279. SetLength(Result, High(V) + 1);
  6280. for I := 0 to High(V) do
  6281. Result[I] := V[I];
  6282. end;
  6283. function AsInterfaceArray(const V: array of IInterface): InterfaceArray;
  6284. var I : Integer;
  6285. begin
  6286. SetLength(Result, High(V) + 1);
  6287. for I := 0 to High(V) do
  6288. Result[I] := V[I];
  6289. end;
  6290. function DynArrayRangeByte(const First: Byte; const Count: Integer; const Increment: Byte): ByteArray;
  6291. var I : Integer;
  6292. J : Byte;
  6293. begin
  6294. SetLength(Result, Count);
  6295. J := First;
  6296. for I := 0 to Count - 1 do
  6297. begin
  6298. Result[I] := J;
  6299. J := J + Increment;
  6300. end;
  6301. end;
  6302. function DynArrayRangeWord(const First: Word; const Count: Integer; const Increment: Word): WordArray;
  6303. var I : Integer;
  6304. J : Word;
  6305. begin
  6306. SetLength(Result, Count);
  6307. J := First;
  6308. for I := 0 to Count - 1 do
  6309. begin
  6310. Result[I] := J;
  6311. J := J + Increment;
  6312. end;
  6313. end;
  6314. function DynArrayRangeLongWord(const First: LongWord; const Count: Integer; const Increment: LongWord): LongWordArray;
  6315. var I : Integer;
  6316. J : LongWord;
  6317. begin
  6318. SetLength(Result, Count);
  6319. J := First;
  6320. for I := 0 to Count - 1 do
  6321. begin
  6322. Result[I] := J;
  6323. J := J + Increment;
  6324. end;
  6325. end;
  6326. function DynArrayRangeCardinal(const First: Cardinal; const Count: Integer; const Increment: Cardinal): CardinalArray;
  6327. var I : Integer;
  6328. J : Cardinal;
  6329. begin
  6330. SetLength(Result, Count);
  6331. J := First;
  6332. for I := 0 to Count - 1 do
  6333. begin
  6334. Result[I] := J;
  6335. J := J + Increment;
  6336. end;
  6337. end;
  6338. function DynArrayRangeShortInt(const First: ShortInt; const Count: Integer; const Increment: ShortInt): ShortIntArray;
  6339. var I : Integer;
  6340. J : ShortInt;
  6341. begin
  6342. SetLength(Result, Count);
  6343. J := First;
  6344. for I := 0 to Count - 1 do
  6345. begin
  6346. Result[I] := J;
  6347. J := J + Increment;
  6348. end;
  6349. end;
  6350. function DynArrayRangeSmallInt(const First: SmallInt; const Count: Integer; const Increment: SmallInt): SmallIntArray;
  6351. var I : Integer;
  6352. J : SmallInt;
  6353. begin
  6354. SetLength(Result, Count);
  6355. J := First;
  6356. for I := 0 to Count - 1 do
  6357. begin
  6358. Result[I] := J;
  6359. J := J + Increment;
  6360. end;
  6361. end;
  6362. function DynArrayRangeLongInt(const First: LongInt; const Count: Integer; const Increment: LongInt): LongIntArray;
  6363. var I : Integer;
  6364. J : LongInt;
  6365. begin
  6366. SetLength(Result, Count);
  6367. J := First;
  6368. for I := 0 to Count - 1 do
  6369. begin
  6370. Result[I] := J;
  6371. J := J + Increment;
  6372. end;
  6373. end;
  6374. function DynArrayRangeInteger(const First: Integer; const Count: Integer; const Increment: Integer): IntegerArray;
  6375. var I : Integer;
  6376. J : Integer;
  6377. begin
  6378. SetLength(Result, Count);
  6379. J := First;
  6380. for I := 0 to Count - 1 do
  6381. begin
  6382. Result[I] := J;
  6383. J := J + Increment;
  6384. end;
  6385. end;
  6386. function DynArrayRangeInt64(const First: Int64; const Count: Integer; const Increment: Int64): Int64Array;
  6387. var I : Integer;
  6388. J : Int64;
  6389. begin
  6390. SetLength(Result, Count);
  6391. J := First;
  6392. for I := 0 to Count - 1 do
  6393. begin
  6394. Result[I] := J;
  6395. J := J + Increment;
  6396. end;
  6397. end;
  6398. function DynArrayRangeSingle(const First: Single; const Count: Integer; const Increment: Single): SingleArray;
  6399. var I : Integer;
  6400. J : Single;
  6401. begin
  6402. SetLength(Result, Count);
  6403. J := First;
  6404. for I := 0 to Count - 1 do
  6405. begin
  6406. Result[I] := J;
  6407. J := J + Increment;
  6408. end;
  6409. end;
  6410. function DynArrayRangeDouble(const First: Double; const Count: Integer; const Increment: Double): DoubleArray;
  6411. var I : Integer;
  6412. J : Double;
  6413. begin
  6414. SetLength(Result, Count);
  6415. J := First;
  6416. for I := 0 to Count - 1 do
  6417. begin
  6418. Result[I] := J;
  6419. J := J + Increment;
  6420. end;
  6421. end;
  6422. function DynArrayRangeExtended(const First: Extended; const Count: Integer; const Increment: Extended): ExtendedArray;
  6423. var I : Integer;
  6424. J : Extended;
  6425. begin
  6426. SetLength(Result, Count);
  6427. J := First;
  6428. for I := 0 to Count - 1 do
  6429. begin
  6430. Result[I] := J;
  6431. J := J + Increment;
  6432. end;
  6433. end;
  6434. { }
  6435. { DynArrayDup }
  6436. { }
  6437. {$IFDEF ManagedCode}
  6438. function DynArrayDupByte(const V: Byte; const Count: Integer): ByteArray;
  6439. var I : Integer;
  6440. begin
  6441. if Count <= 0 then
  6442. begin
  6443. SetLength(Result, 0);
  6444. exit;
  6445. end;
  6446. SetLength(Result, Count);
  6447. for I := 0 to Count - 1 do
  6448. Result[I] := 0;
  6449. end;
  6450. {$ELSE}
  6451. function DynArrayDupByte(const V: Byte; const Count: Integer): ByteArray;
  6452. begin
  6453. if Count <= 0 then
  6454. begin
  6455. SetLength(Result, 0);
  6456. exit;
  6457. end;
  6458. SetLength(Result, Count);
  6459. FillChar(Result[0], Count, V);
  6460. end;
  6461. {$ENDIF}
  6462. function DynArrayDupWord(const V: Word; const Count: Integer): WordArray;
  6463. var I : Integer;
  6464. begin
  6465. if Count <= 0 then
  6466. begin
  6467. SetLength(Result, 0);
  6468. exit;
  6469. end;
  6470. SetLength(Result, Count);
  6471. for I := 0 to Count - 1 do
  6472. Result[I] := V;
  6473. end;
  6474. function DynArrayDupLongWord(const V: LongWord; const Count: Integer): LongWordArray;
  6475. var I : Integer;
  6476. begin
  6477. if Count <= 0 then
  6478. begin
  6479. SetLength(Result, 0);
  6480. exit;
  6481. end;
  6482. SetLength(Result, Count);
  6483. for I := 0 to Count - 1 do
  6484. Result[I] := V;
  6485. end;
  6486. function DynArrayDupCardinal(const V: Cardinal; const Count: Integer): CardinalArray;
  6487. var I : Integer;
  6488. begin
  6489. if Count <= 0 then
  6490. begin
  6491. SetLength(Result, 0);
  6492. exit;
  6493. end;
  6494. SetLength(Result, Count);
  6495. for I := 0 to Count - 1 do
  6496. Result[I] := V;
  6497. end;
  6498. function DynArrayDupNativeUInt(const V: NativeUInt; const Count: Integer): NativeUIntArray;
  6499. var I : Integer;
  6500. begin
  6501. if Count <= 0 then
  6502. begin
  6503. SetLength(Result, 0);
  6504. exit;
  6505. end;
  6506. SetLength(Result, Count);
  6507. for I := 0 to Count - 1 do
  6508. Result[I] := V;
  6509. end;
  6510. function DynArrayDupShortInt(const V: ShortInt; const Count: Integer): ShortIntArray;
  6511. var I : Integer;
  6512. begin
  6513. if Count <= 0 then
  6514. begin
  6515. SetLength(Result, 0);
  6516. exit;
  6517. end;
  6518. SetLength(Result, Count);
  6519. for I := 0 to Count - 1 do
  6520. Result[I] := V;
  6521. end;
  6522. function DynArrayDupSmallInt(const V: SmallInt; const Count: Integer): SmallIntArray;
  6523. var I : Integer;
  6524. begin
  6525. if Count <= 0 then
  6526. begin
  6527. SetLength(Result, 0);
  6528. exit;
  6529. end;
  6530. SetLength(Result, Count);
  6531. for I := 0 to Count - 1 do
  6532. Result[I] := V;
  6533. end;
  6534. function DynArrayDupLongInt(const V: LongInt; const Count: Integer): LongIntArray;
  6535. var I : Integer;
  6536. begin
  6537. if Count <= 0 then
  6538. begin
  6539. SetLength(Result, 0);
  6540. exit;
  6541. end;
  6542. SetLength(Result, Count);
  6543. for I := 0 to Count - 1 do
  6544. Result[I] := V;
  6545. end;
  6546. function DynArrayDupInteger(const V: Integer; const Count: Integer): IntegerArray;
  6547. var I : Integer;
  6548. begin
  6549. if Count <= 0 then
  6550. begin
  6551. SetLength(Result, 0);
  6552. exit;
  6553. end;
  6554. SetLength(Result, Count);
  6555. for I := 0 to Count - 1 do
  6556. Result[I] := V;
  6557. end;
  6558. function DynArrayDupInt64(const V: Int64; const Count: Integer): Int64Array;
  6559. var I : Integer;
  6560. begin
  6561. if Count <= 0 then
  6562. begin
  6563. SetLength(Result, 0);
  6564. exit;
  6565. end;
  6566. SetLength(Result, Count);
  6567. for I := 0 to Count - 1 do
  6568. Result[I] := V;
  6569. end;
  6570. function DynArrayDupNativeInt(const V: NativeInt; const Count: Integer): NativeIntArray;
  6571. var I : Integer;
  6572. begin
  6573. if Count <= 0 then
  6574. begin
  6575. SetLength(Result, 0);
  6576. exit;
  6577. end;
  6578. SetLength(Result, Count);
  6579. for I := 0 to Count - 1 do
  6580. Result[I] := V;
  6581. end;
  6582. function DynArrayDupSingle(const V: Single; const Count: Integer): SingleArray;
  6583. var I : Integer;
  6584. begin
  6585. if Count <= 0 then
  6586. begin
  6587. SetLength(Result, 0);
  6588. exit;
  6589. end;
  6590. SetLength(Result, Count);
  6591. for I := 0 to Count - 1 do
  6592. Result[I] := V;
  6593. end;
  6594. function DynArrayDupDouble(const V: Double; const Count: Integer): DoubleArray;
  6595. var I : Integer;
  6596. begin
  6597. if Count <= 0 then
  6598. begin
  6599. SetLength(Result, 0);
  6600. exit;
  6601. end;
  6602. SetLength(Result, Count);
  6603. for I := 0 to Count - 1 do
  6604. Result[I] := V;
  6605. end;
  6606. function DynArrayDupExtended(const V: Extended; const Count: Integer): ExtendedArray;
  6607. var I : Integer;
  6608. begin
  6609. if Count <= 0 then
  6610. begin
  6611. SetLength(Result, 0);
  6612. exit;
  6613. end;
  6614. SetLength(Result, Count);
  6615. for I := 0 to Count - 1 do
  6616. Result[I] := V;
  6617. end;
  6618. function DynArrayDupCurrency(const V: Currency; const Count: Integer): CurrencyArray;
  6619. var I : Integer;
  6620. begin
  6621. if Count <= 0 then
  6622. begin
  6623. SetLength(Result, 0);
  6624. exit;
  6625. end;
  6626. SetLength(Result, Count);
  6627. for I := 0 to Count - 1 do
  6628. Result[I] := V;
  6629. end;
  6630. function DynArrayDupAnsiString(const V: AnsiString; const Count: Integer): AnsiStringArray;
  6631. var I : Integer;
  6632. begin
  6633. if Count <= 0 then
  6634. begin
  6635. SetLength(Result, 0);
  6636. exit;
  6637. end;
  6638. SetLength(Result, Count);
  6639. for I := 0 to Count - 1 do
  6640. Result[I] := V;
  6641. end;
  6642. function DynArrayDupWideString(const V: WideString; const Count: Integer): WideStringArray;
  6643. var I : Integer;
  6644. begin
  6645. if Count <= 0 then
  6646. begin
  6647. SetLength(Result, 0);
  6648. exit;
  6649. end;
  6650. SetLength(Result, Count);
  6651. for I := 0 to Count - 1 do
  6652. Result[I] := V;
  6653. end;
  6654. function DynArrayDupUnicodeString(const V: UnicodeString; const Count: Integer): UnicodeStringArray;
  6655. var I : Integer;
  6656. begin
  6657. if Count <= 0 then
  6658. begin
  6659. SetLength(Result, 0);
  6660. exit;
  6661. end;
  6662. SetLength(Result, Count);
  6663. for I := 0 to Count - 1 do
  6664. Result[I] := V;
  6665. end;
  6666. function DynArrayDupString(const V: String; const Count: Integer): StringArray;
  6667. var I : Integer;
  6668. begin
  6669. if Count <= 0 then
  6670. begin
  6671. SetLength(Result, 0);
  6672. exit;
  6673. end;
  6674. SetLength(Result, Count);
  6675. for I := 0 to Count - 1 do
  6676. Result[I] := V;
  6677. end;
  6678. function DynArrayDupCharSet(const V: CharSet; const Count: Integer): CharSetArray;
  6679. var I : Integer;
  6680. begin
  6681. if Count <= 0 then
  6682. begin
  6683. SetLength(Result, 0);
  6684. exit;
  6685. end;
  6686. SetLength(Result, Count);
  6687. for I := 0 to Count - 1 do
  6688. Result[I] := V;
  6689. end;
  6690. function DynArrayDupObject(const V: TObject; const Count: Integer): ObjectArray;
  6691. var I : Integer;
  6692. begin
  6693. if Count <= 0 then
  6694. begin
  6695. SetLength(Result, 0);
  6696. exit;
  6697. end;
  6698. SetLength(Result, Count);
  6699. for I := 0 to Count - 1 do
  6700. Result[I] := V;
  6701. end;
  6702. { }
  6703. { SetLengthAndZero }
  6704. { }
  6705. {$IFDEF ManagedCode}
  6706. procedure SetLengthAndZero(var V: ByteArray; const NewLength: Integer);
  6707. var OldLen, NewLen, I : Integer;
  6708. begin
  6709. NewLen := NewLength;
  6710. if NewLen < 0 then
  6711. NewLen := 0;
  6712. OldLen := Length(V);
  6713. if OldLen = NewLen then
  6714. exit;
  6715. SetLength(V, NewLen);
  6716. if OldLen > NewLen then
  6717. exit;
  6718. for I := 0 to NewLen - OldLen - 1 do
  6719. V[OldLen + I] := 0;
  6720. end;
  6721. {$ELSE}
  6722. procedure SetLengthAndZero(var V: ByteArray; const NewLength: Integer);
  6723. var OldLen, NewLen : Integer;
  6724. begin
  6725. NewLen := NewLength;
  6726. if NewLen < 0 then
  6727. NewLen := 0;
  6728. OldLen := Length(V);
  6729. if OldLen = NewLen then
  6730. exit;
  6731. SetLength(V, NewLen);
  6732. if OldLen > NewLen then
  6733. exit;
  6734. FillChar(Pointer(@V[OldLen])^, Sizeof(Byte) * (NewLen - OldLen), #0);
  6735. end;
  6736. {$ENDIF}
  6737. {$IFDEF ManagedCode}
  6738. procedure SetLengthAndZero(var V: WordArray; const NewLength: Integer);
  6739. var OldLen, NewLen, I : Integer;
  6740. begin
  6741. NewLen := NewLength;
  6742. if NewLen < 0 then
  6743. NewLen := 0;
  6744. OldLen := Length(V);
  6745. if OldLen = NewLen then
  6746. exit;
  6747. SetLength(V, NewLen);
  6748. if OldLen > NewLen then
  6749. exit;
  6750. for I := 0 to NewLen - OldLen - 1 do
  6751. V[OldLen + I] := 0;
  6752. end;
  6753. {$ELSE}
  6754. procedure SetLengthAndZero(var V: WordArray; const NewLength: Integer);
  6755. var OldLen, NewLen : Integer;
  6756. begin
  6757. NewLen := NewLength;
  6758. if NewLen < 0 then
  6759. NewLen := 0;
  6760. OldLen := Length(V);
  6761. if OldLen = NewLen then
  6762. exit;
  6763. SetLength(V, NewLen);
  6764. if OldLen > NewLen then
  6765. exit;
  6766. FillChar(Pointer(@V[OldLen])^, Sizeof(Word) * (NewLen - OldLen), #0);
  6767. end;
  6768. {$ENDIF}
  6769. {$IFDEF ManagedCode}
  6770. procedure SetLengthAndZero(var V: LongWordArray; const NewLength: Integer);
  6771. var OldLen, NewLen, I : Integer;
  6772. begin
  6773. NewLen := NewLength;
  6774. if NewLen < 0 then
  6775. NewLen := 0;
  6776. OldLen := Length(V);
  6777. if OldLen = NewLen then
  6778. exit;
  6779. SetLength(V, NewLen);
  6780. if OldLen > NewLen then
  6781. exit;
  6782. for I := 0 to NewLen - OldLen - 1 do
  6783. V[OldLen + I] := 0;
  6784. end;
  6785. {$ELSE}
  6786. procedure SetLengthAndZero(var V: LongWordArray; const NewLength: Integer);
  6787. var OldLen, NewLen : Integer;
  6788. begin
  6789. NewLen := NewLength;
  6790. if NewLen < 0 then
  6791. NewLen := 0;
  6792. OldLen := Length(V);
  6793. if OldLen = NewLen then
  6794. exit;
  6795. SetLength(V, NewLen);
  6796. if OldLen > NewLen then
  6797. exit;
  6798. FillChar(Pointer(@V[OldLen])^, Sizeof(LongWord) * (NewLen - OldLen), #0);
  6799. end;
  6800. {$ENDIF}
  6801. {$IFDEF ManagedCode}
  6802. procedure SetLengthAndZero(var V: NativeUIntArray; const NewLength: Integer);
  6803. var OldLen, NewLen, I : Integer;
  6804. begin
  6805. NewLen := NewLength;
  6806. if NewLen < 0 then
  6807. NewLen := 0;
  6808. OldLen := Length(V);
  6809. if OldLen = NewLen then
  6810. exit;
  6811. SetLength(V, NewLen);
  6812. if OldLen > NewLen then
  6813. exit;
  6814. for I := 0 to NewLen - OldLen - 1 do
  6815. V[OldLen + I] := 0;
  6816. end;
  6817. {$ELSE}
  6818. procedure SetLengthAndZero(var V: NativeUIntArray; const NewLength: Integer);
  6819. var OldLen, NewLen : Integer;
  6820. begin
  6821. NewLen := NewLength;
  6822. if NewLen < 0 then
  6823. NewLen := 0;
  6824. OldLen := Length(V);
  6825. if OldLen = NewLen then
  6826. exit;
  6827. SetLength(V, NewLen);
  6828. if OldLen > NewLen then
  6829. exit;
  6830. FillChar(Pointer(@V[OldLen])^, Sizeof(NativeUInt) * (NewLen - OldLen), #0);
  6831. end;
  6832. {$ENDIF}
  6833. {$IFDEF ManagedCode}
  6834. procedure SetLengthAndZero(var V: ShortIntArray; const NewLength: Integer);
  6835. var OldLen, NewLen, I : Integer;
  6836. begin
  6837. NewLen := NewLength;
  6838. if NewLen < 0 then
  6839. NewLen := 0;
  6840. OldLen := Length(V);
  6841. if OldLen = NewLen then
  6842. exit;
  6843. SetLength(V, NewLen);
  6844. if OldLen > NewLen then
  6845. exit;
  6846. for I := 0 to NewLen - OldLen - 1 do
  6847. V[OldLen + I] := 0;
  6848. end;
  6849. {$ELSE}
  6850. procedure SetLengthAndZero(var V: ShortIntArray; const NewLength: Integer);
  6851. var OldLen, NewLen : Integer;
  6852. begin
  6853. NewLen := NewLength;
  6854. if NewLen < 0 then
  6855. NewLen := 0;
  6856. OldLen := Length(V);
  6857. if OldLen = NewLen then
  6858. exit;
  6859. SetLength(V, NewLen);
  6860. if OldLen > NewLen then
  6861. exit;
  6862. FillChar(Pointer(@V[OldLen])^, Sizeof(ShortInt) * (NewLen - OldLen), #0);
  6863. end;
  6864. {$ENDIF}
  6865. {$IFDEF ManagedCode}
  6866. procedure SetLengthAndZero(var V: SmallIntArray; const NewLength: Integer);
  6867. var OldLen, NewLen, I : Integer;
  6868. begin
  6869. NewLen := NewLength;
  6870. if NewLen < 0 then
  6871. NewLen := 0;
  6872. OldLen := Length(V);
  6873. if OldLen = NewLen then
  6874. exit;
  6875. SetLength(V, NewLen);
  6876. if OldLen > NewLen then
  6877. exit;
  6878. for I := 0 to NewLen - OldLen - 1 do
  6879. V[OldLen + I] := 0;
  6880. end;
  6881. {$ELSE}
  6882. procedure SetLengthAndZero(var V: SmallIntArray; const NewLength: Integer);
  6883. var OldLen, NewLen : Integer;
  6884. begin
  6885. NewLen := NewLength;
  6886. if NewLen < 0 then
  6887. NewLen := 0;
  6888. OldLen := Length(V);
  6889. if OldLen = NewLen then
  6890. exit;
  6891. SetLength(V, NewLen);
  6892. if OldLen > NewLen then
  6893. exit;
  6894. FillChar(Pointer(@V[OldLen])^, Sizeof(SmallInt) * (NewLen - OldLen), #0);
  6895. end;
  6896. {$ENDIF}
  6897. {$IFDEF ManagedCode}
  6898. procedure SetLengthAndZero(var V: LongIntArray; const NewLength: Integer);
  6899. var OldLen, NewLen, I : Integer;
  6900. begin
  6901. NewLen := NewLength;
  6902. if NewLen < 0 then
  6903. NewLen := 0;
  6904. OldLen := Length(V);
  6905. if OldLen = NewLen then
  6906. exit;
  6907. SetLength(V, NewLen);
  6908. if OldLen > NewLen then
  6909. exit;
  6910. for I := 0 to NewLen - OldLen - 1 do
  6911. V[OldLen + I] := 0;
  6912. end;
  6913. {$ELSE}
  6914. procedure SetLengthAndZero(var V: LongIntArray; const NewLength: Integer);
  6915. var OldLen, NewLen : Integer;
  6916. begin
  6917. NewLen := NewLength;
  6918. if NewLen < 0 then
  6919. NewLen := 0;
  6920. OldLen := Length(V);
  6921. if OldLen = NewLen then
  6922. exit;
  6923. SetLength(V, NewLen);
  6924. if OldLen > NewLen then
  6925. exit;
  6926. FillChar(Pointer(@V[OldLen])^, Sizeof(LongInt) * (NewLen - OldLen), #0);
  6927. end;
  6928. {$ENDIF}
  6929. {$IFDEF ManagedCode}
  6930. procedure SetLengthAndZero(var V: Int64Array; const NewLength: Integer);
  6931. var OldLen, NewLen, I : Integer;
  6932. begin
  6933. NewLen := NewLength;
  6934. if NewLen < 0 then
  6935. NewLen := 0;
  6936. OldLen := Length(V);
  6937. if OldLen = NewLen then
  6938. exit;
  6939. SetLength(V, NewLen);
  6940. if OldLen > NewLen then
  6941. exit;
  6942. for I := 0 to NewLen - OldLen - 1 do
  6943. V[OldLen + I] := 0;
  6944. end;
  6945. {$ELSE}
  6946. procedure SetLengthAndZero(var V: Int64Array; const NewLength: Integer);
  6947. var OldLen, NewLen : Integer;
  6948. begin
  6949. NewLen := NewLength;
  6950. if NewLen < 0 then
  6951. NewLen := 0;
  6952. OldLen := Length(V);
  6953. if OldLen = NewLen then
  6954. exit;
  6955. SetLength(V, NewLen);
  6956. if OldLen > NewLen then
  6957. exit;
  6958. FillChar(Pointer(@V[OldLen])^, Sizeof(Int64) * (NewLen - OldLen), #0);
  6959. end;
  6960. {$ENDIF}
  6961. {$IFDEF ManagedCode}
  6962. procedure SetLengthAndZero(var V: NativeIntArray; const NewLength: Integer);
  6963. var OldLen, NewLen, I : Integer;
  6964. begin
  6965. NewLen := NewLength;
  6966. if NewLen < 0 then
  6967. NewLen := 0;
  6968. OldLen := Length(V);
  6969. if OldLen = NewLen then
  6970. exit;
  6971. SetLength(V, NewLen);
  6972. if OldLen > NewLen then
  6973. exit;
  6974. for I := 0 to NewLen - OldLen - 1 do
  6975. V[OldLen + I] := 0;
  6976. end;
  6977. {$ELSE}
  6978. procedure SetLengthAndZero(var V: NativeIntArray; const NewLength: Integer);
  6979. var OldLen, NewLen : Integer;
  6980. begin
  6981. NewLen := NewLength;
  6982. if NewLen < 0 then
  6983. NewLen := 0;
  6984. OldLen := Length(V);
  6985. if OldLen = NewLen then
  6986. exit;
  6987. SetLength(V, NewLen);
  6988. if OldLen > NewLen then
  6989. exit;
  6990. FillChar(Pointer(@V[OldLen])^, Sizeof(NativeInt) * (NewLen - OldLen), #0);
  6991. end;
  6992. {$ENDIF}
  6993. {$IFDEF ManagedCode}
  6994. procedure SetLengthAndZero(var V: SingleArray; const NewLength: Integer);
  6995. var OldLen, NewLen, I : Integer;
  6996. begin
  6997. NewLen := NewLength;
  6998. if NewLen < 0 then
  6999. NewLen := 0;
  7000. OldLen := Length(V);
  7001. if OldLen = NewLen then
  7002. exit;
  7003. SetLength(V, NewLen);
  7004. if OldLen > NewLen then
  7005. exit;
  7006. for I := 0 to NewLen - OldLen - 1 do
  7007. V[OldLen + I] := 0.0;
  7008. end;
  7009. {$ELSE}
  7010. procedure SetLengthAndZero(var V: SingleArray; const NewLength: Integer);
  7011. var OldLen, NewLen : Integer;
  7012. begin
  7013. NewLen := NewLength;
  7014. if NewLen < 0 then
  7015. NewLen := 0;
  7016. OldLen := Length(V);
  7017. if OldLen = NewLen then
  7018. exit;
  7019. SetLength(V, NewLen);
  7020. if OldLen > NewLen then
  7021. exit;
  7022. FillChar(Pointer(@V[OldLen])^, Sizeof(Single) * (NewLen - OldLen), #0);
  7023. end;
  7024. {$ENDIF}
  7025. {$IFDEF ManagedCode}
  7026. procedure SetLengthAndZero(var V: DoubleArray; const NewLength: Integer);
  7027. var OldLen, NewLen, I : Integer;
  7028. begin
  7029. NewLen := NewLength;
  7030. if NewLen < 0 then
  7031. NewLen := 0;
  7032. OldLen := Length(V);
  7033. if OldLen = NewLen then
  7034. exit;
  7035. SetLength(V, NewLen);
  7036. if OldLen > NewLen then
  7037. exit;
  7038. for I := 0 to NewLen - OldLen - 1 do
  7039. V[OldLen + I] := 0.0;
  7040. end;
  7041. {$ELSE}
  7042. procedure SetLengthAndZero(var V: DoubleArray; const NewLength: Integer);
  7043. var OldLen, NewLen : Integer;
  7044. begin
  7045. NewLen := NewLength;
  7046. if NewLen < 0 then
  7047. NewLen := 0;
  7048. OldLen := Length(V);
  7049. if OldLen = NewLen then
  7050. exit;
  7051. SetLength(V, NewLen);
  7052. if OldLen > NewLen then
  7053. exit;
  7054. FillChar(Pointer(@V[OldLen])^, Sizeof(Double) * (NewLen - OldLen), #0);
  7055. end;
  7056. {$ENDIF}
  7057. {$IFDEF ManagedCode}
  7058. procedure SetLengthAndZero(var V: ExtendedArray; const NewLength: Integer);
  7059. var OldLen, NewLen, I : Integer;
  7060. begin
  7061. NewLen := NewLength;
  7062. if NewLen < 0 then
  7063. NewLen := 0;
  7064. OldLen := Length(V);
  7065. if OldLen = NewLen then
  7066. exit;
  7067. SetLength(V, NewLen);
  7068. if OldLen > NewLen then
  7069. exit;
  7070. for I := 0 to NewLen - OldLen - 1 do
  7071. V[OldLen + I] := 0.0;
  7072. end;
  7073. {$ELSE}
  7074. procedure SetLengthAndZero(var V: ExtendedArray; const NewLength: Integer);
  7075. var OldLen, NewLen : Integer;
  7076. begin
  7077. NewLen := NewLength;
  7078. if NewLen < 0 then
  7079. NewLen := 0;
  7080. OldLen := Length(V);
  7081. if OldLen = NewLen then
  7082. exit;
  7083. SetLength(V, NewLen);
  7084. if OldLen > NewLen then
  7085. exit;
  7086. FillChar(Pointer(@V[OldLen])^, Sizeof(Extended) * (NewLen - OldLen), #0);
  7087. end;
  7088. {$ENDIF}
  7089. {$IFDEF ManagedCode}
  7090. procedure SetLengthAndZero(var V: CurrencyArray; const NewLength: Integer);
  7091. var OldLen, NewLen, I : Integer;
  7092. begin
  7093. NewLen := NewLength;
  7094. if NewLen < 0 then
  7095. NewLen := 0;
  7096. OldLen := Length(V);
  7097. if OldLen = NewLen then
  7098. exit;
  7099. SetLength(V, NewLen);
  7100. if OldLen > NewLen then
  7101. exit;
  7102. for I := 0 to NewLen - OldLen - 1 do
  7103. V[OldLen + I] := 0.0;
  7104. end;
  7105. {$ELSE}
  7106. procedure SetLengthAndZero(var V: CurrencyArray; const NewLength: Integer);
  7107. var OldLen, NewLen : Integer;
  7108. begin
  7109. NewLen := NewLength;
  7110. if NewLen < 0 then
  7111. NewLen := 0;
  7112. OldLen := Length(V);
  7113. if OldLen = NewLen then
  7114. exit;
  7115. SetLength(V, NewLen);
  7116. if OldLen > NewLen then
  7117. exit;
  7118. FillChar(Pointer(@V[OldLen])^, Sizeof(Currency) * (NewLen - OldLen), #0);
  7119. end;
  7120. {$ENDIF}
  7121. {$IFDEF ManagedCode}
  7122. procedure SetLengthAndZero(var V: CharSetArray; const NewLength: Integer);
  7123. var OldLen, NewLen, I : Integer;
  7124. begin
  7125. NewLen := NewLength;
  7126. if NewLen < 0 then
  7127. NewLen := 0;
  7128. OldLen := Length(V);
  7129. if OldLen = NewLen then
  7130. exit;
  7131. SetLength(V, NewLen);
  7132. if OldLen > NewLen then
  7133. exit;
  7134. for I := 0 to NewLen - OldLen - 1 do
  7135. V[OldLen + I] := [];
  7136. end;
  7137. {$ELSE}
  7138. procedure SetLengthAndZero(var V: CharSetArray; const NewLength: Integer);
  7139. var OldLen, NewLen : Integer;
  7140. begin
  7141. NewLen := NewLength;
  7142. if NewLen < 0 then
  7143. NewLen := 0;
  7144. OldLen := Length(V);
  7145. if OldLen = NewLen then
  7146. exit;
  7147. SetLength(V, NewLen);
  7148. if OldLen > NewLen then
  7149. exit;
  7150. FillChar(Pointer(@V[OldLen])^, Sizeof(CharSet) * (NewLen - OldLen), #0);
  7151. end;
  7152. {$ENDIF}
  7153. {$IFDEF ManagedCode}
  7154. procedure SetLengthAndZero(var V: BooleanArray; const NewLength: Integer);
  7155. var OldLen, NewLen, I : Integer;
  7156. begin
  7157. NewLen := NewLength;
  7158. if NewLen < 0 then
  7159. NewLen := 0;
  7160. OldLen := Length(V);
  7161. if OldLen = NewLen then
  7162. exit;
  7163. SetLength(V, NewLen);
  7164. if OldLen > NewLen then
  7165. exit;
  7166. for I := 0 to NewLen - OldLen - 1 do
  7167. V[OldLen + I] := False;
  7168. end;
  7169. {$ELSE}
  7170. procedure SetLengthAndZero(var V: BooleanArray; const NewLength: Integer);
  7171. var OldLen, NewLen : Integer;
  7172. begin
  7173. NewLen := NewLength;
  7174. if NewLen < 0 then
  7175. NewLen := 0;
  7176. OldLen := Length(V);
  7177. if OldLen = NewLen then
  7178. exit;
  7179. SetLength(V, NewLen);
  7180. if OldLen > NewLen then
  7181. exit;
  7182. FillChar(Pointer(@V[OldLen])^, Sizeof(Boolean) * (NewLen - OldLen), #0);
  7183. end;
  7184. {$ENDIF}
  7185. {$IFNDEF Managedcode}
  7186. {$IFDEF ManagedCode}
  7187. procedure SetLengthAndZero(var V: PointerArray; const NewLength: Integer);
  7188. var OldLen, NewLen, I : Integer;
  7189. begin
  7190. NewLen := NewLength;
  7191. if NewLen < 0 then
  7192. NewLen := 0;
  7193. OldLen := Length(V);
  7194. if OldLen = NewLen then
  7195. exit;
  7196. SetLength(V, NewLen);
  7197. if OldLen > NewLen then
  7198. exit;
  7199. for I := 0 to NewLen - OldLen - 1 do
  7200. V[OldLen + I] := nil;
  7201. end;
  7202. {$ELSE}
  7203. procedure SetLengthAndZero(var V: PointerArray; const NewLength: Integer);
  7204. var OldLen, NewLen : Integer;
  7205. begin
  7206. NewLen := NewLength;
  7207. if NewLen < 0 then
  7208. NewLen := 0;
  7209. OldLen := Length(V);
  7210. if OldLen = NewLen then
  7211. exit;
  7212. SetLength(V, NewLen);
  7213. if OldLen > NewLen then
  7214. exit;
  7215. FillChar(Pointer(@V[OldLen])^, Sizeof(Pointer) * (NewLen - OldLen), #0);
  7216. end;
  7217. {$ENDIF}
  7218. {$ENDIF}
  7219. procedure SetLengthAndZero(var V: ObjectArray; const NewLength: Integer;
  7220. const FreeObjects: Boolean);
  7221. var I, L : Integer;
  7222. begin
  7223. L := Length(V);
  7224. if L = NewLength then
  7225. exit;
  7226. if (L > NewLength) and FreeObjects then
  7227. for I := NewLength to L - 1 do
  7228. FreeAndNil(V[I]);
  7229. SetLength(V, NewLength);
  7230. if L > NewLength then
  7231. exit;
  7232. {$IFDEF ManagedCode}
  7233. for I := 0 to NewLength - L - 1 do
  7234. V[L + I] := nil;
  7235. {$ELSE}
  7236. FillChar(V[L], Sizeof(Pointer) * (NewLength - L), #0);
  7237. {$ENDIF}
  7238. end;
  7239. { }
  7240. { DynArrayIsEqual }
  7241. { }
  7242. {$IFDEF ManagedCode}
  7243. function DynArrayIsEqual(const V1, V2: ByteArray): Boolean;
  7244. var I, L : Integer;
  7245. begin
  7246. L := Length(V1);
  7247. if L <> Length(V2) then
  7248. begin
  7249. Result := False;
  7250. exit;
  7251. end;
  7252. for I := 0 to L - 1 do
  7253. if V1[I] <> V2[I] then
  7254. begin
  7255. Result := False;
  7256. exit;
  7257. end;
  7258. Result := True;
  7259. end;
  7260. {$ELSE}
  7261. function DynArrayIsEqual(const V1, V2: ByteArray): Boolean;
  7262. var L : Integer;
  7263. begin
  7264. L := Length(V1);
  7265. if L <> Length(V2) then
  7266. begin
  7267. Result := False;
  7268. exit;
  7269. end;
  7270. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Byte) * L);
  7271. end;
  7272. {$ENDIF}
  7273. {$IFDEF ManagedCode}
  7274. function DynArrayIsEqual(const V1, V2: WordArray): Boolean;
  7275. var I, L : Integer;
  7276. begin
  7277. L := Length(V1);
  7278. if L <> Length(V2) then
  7279. begin
  7280. Result := False;
  7281. exit;
  7282. end;
  7283. for I := 0 to L - 1 do
  7284. if V1[I] <> V2[I] then
  7285. begin
  7286. Result := False;
  7287. exit;
  7288. end;
  7289. Result := True;
  7290. end;
  7291. {$ELSE}
  7292. function DynArrayIsEqual(const V1, V2: WordArray): Boolean;
  7293. var L : Integer;
  7294. begin
  7295. L := Length(V1);
  7296. if L <> Length(V2) then
  7297. begin
  7298. Result := False;
  7299. exit;
  7300. end;
  7301. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Word) * L);
  7302. end;
  7303. {$ENDIF}
  7304. {$IFDEF ManagedCode}
  7305. function DynArrayIsEqual(const V1, V2: LongWordArray): Boolean;
  7306. var I, L : Integer;
  7307. begin
  7308. L := Length(V1);
  7309. if L <> Length(V2) then
  7310. begin
  7311. Result := False;
  7312. exit;
  7313. end;
  7314. for I := 0 to L - 1 do
  7315. if V1[I] <> V2[I] then
  7316. begin
  7317. Result := False;
  7318. exit;
  7319. end;
  7320. Result := True;
  7321. end;
  7322. {$ELSE}
  7323. function DynArrayIsEqual(const V1, V2: LongWordArray): Boolean;
  7324. var L : Integer;
  7325. begin
  7326. L := Length(V1);
  7327. if L <> Length(V2) then
  7328. begin
  7329. Result := False;
  7330. exit;
  7331. end;
  7332. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(LongWord) * L);
  7333. end;
  7334. {$ENDIF}
  7335. {$IFDEF ManagedCode}
  7336. function DynArrayIsEqual(const V1, V2: ShortIntArray): Boolean;
  7337. var I, L : Integer;
  7338. begin
  7339. L := Length(V1);
  7340. if L <> Length(V2) then
  7341. begin
  7342. Result := False;
  7343. exit;
  7344. end;
  7345. for I := 0 to L - 1 do
  7346. if V1[I] <> V2[I] then
  7347. begin
  7348. Result := False;
  7349. exit;
  7350. end;
  7351. Result := True;
  7352. end;
  7353. {$ELSE}
  7354. function DynArrayIsEqual(const V1, V2: ShortIntArray): Boolean;
  7355. var L : Integer;
  7356. begin
  7357. L := Length(V1);
  7358. if L <> Length(V2) then
  7359. begin
  7360. Result := False;
  7361. exit;
  7362. end;
  7363. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(ShortInt) * L);
  7364. end;
  7365. {$ENDIF}
  7366. {$IFDEF ManagedCode}
  7367. function DynArrayIsEqual(const V1, V2: SmallIntArray): Boolean;
  7368. var I, L : Integer;
  7369. begin
  7370. L := Length(V1);
  7371. if L <> Length(V2) then
  7372. begin
  7373. Result := False;
  7374. exit;
  7375. end;
  7376. for I := 0 to L - 1 do
  7377. if V1[I] <> V2[I] then
  7378. begin
  7379. Result := False;
  7380. exit;
  7381. end;
  7382. Result := True;
  7383. end;
  7384. {$ELSE}
  7385. function DynArrayIsEqual(const V1, V2: SmallIntArray): Boolean;
  7386. var L : Integer;
  7387. begin
  7388. L := Length(V1);
  7389. if L <> Length(V2) then
  7390. begin
  7391. Result := False;
  7392. exit;
  7393. end;
  7394. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(SmallInt) * L);
  7395. end;
  7396. {$ENDIF}
  7397. {$IFDEF ManagedCode}
  7398. function DynArrayIsEqual(const V1, V2: LongIntArray): Boolean;
  7399. var I, L : Integer;
  7400. begin
  7401. L := Length(V1);
  7402. if L <> Length(V2) then
  7403. begin
  7404. Result := False;
  7405. exit;
  7406. end;
  7407. for I := 0 to L - 1 do
  7408. if V1[I] <> V2[I] then
  7409. begin
  7410. Result := False;
  7411. exit;
  7412. end;
  7413. Result := True;
  7414. end;
  7415. {$ELSE}
  7416. function DynArrayIsEqual(const V1, V2: LongIntArray): Boolean;
  7417. var L : Integer;
  7418. begin
  7419. L := Length(V1);
  7420. if L <> Length(V2) then
  7421. begin
  7422. Result := False;
  7423. exit;
  7424. end;
  7425. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(LongInt) * L);
  7426. end;
  7427. {$ENDIF}
  7428. {$IFDEF ManagedCode}
  7429. function DynArrayIsEqual(const V1, V2: Int64Array): Boolean;
  7430. var I, L : Integer;
  7431. begin
  7432. L := Length(V1);
  7433. if L <> Length(V2) then
  7434. begin
  7435. Result := False;
  7436. exit;
  7437. end;
  7438. for I := 0 to L - 1 do
  7439. if V1[I] <> V2[I] then
  7440. begin
  7441. Result := False;
  7442. exit;
  7443. end;
  7444. Result := True;
  7445. end;
  7446. {$ELSE}
  7447. function DynArrayIsEqual(const V1, V2: Int64Array): Boolean;
  7448. var L : Integer;
  7449. begin
  7450. L := Length(V1);
  7451. if L <> Length(V2) then
  7452. begin
  7453. Result := False;
  7454. exit;
  7455. end;
  7456. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Int64) * L);
  7457. end;
  7458. {$ENDIF}
  7459. {$IFDEF ManagedCode}
  7460. function DynArrayIsEqual(const V1, V2: SingleArray): Boolean;
  7461. var I, L : Integer;
  7462. begin
  7463. L := Length(V1);
  7464. if L <> Length(V2) then
  7465. begin
  7466. Result := False;
  7467. exit;
  7468. end;
  7469. for I := 0 to L - 1 do
  7470. if V1[I] <> V2[I] then
  7471. begin
  7472. Result := False;
  7473. exit;
  7474. end;
  7475. Result := True;
  7476. end;
  7477. {$ELSE}
  7478. function DynArrayIsEqual(const V1, V2: SingleArray): Boolean;
  7479. var L : Integer;
  7480. begin
  7481. L := Length(V1);
  7482. if L <> Length(V2) then
  7483. begin
  7484. Result := False;
  7485. exit;
  7486. end;
  7487. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Single) * L);
  7488. end;
  7489. {$ENDIF}
  7490. {$IFDEF ManagedCode}
  7491. function DynArrayIsEqual(const V1, V2: DoubleArray): Boolean;
  7492. var I, L : Integer;
  7493. begin
  7494. L := Length(V1);
  7495. if L <> Length(V2) then
  7496. begin
  7497. Result := False;
  7498. exit;
  7499. end;
  7500. for I := 0 to L - 1 do
  7501. if V1[I] <> V2[I] then
  7502. begin
  7503. Result := False;
  7504. exit;
  7505. end;
  7506. Result := True;
  7507. end;
  7508. {$ELSE}
  7509. function DynArrayIsEqual(const V1, V2: DoubleArray): Boolean;
  7510. var L : Integer;
  7511. begin
  7512. L := Length(V1);
  7513. if L <> Length(V2) then
  7514. begin
  7515. Result := False;
  7516. exit;
  7517. end;
  7518. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Double) * L);
  7519. end;
  7520. {$ENDIF}
  7521. {$IFDEF ManagedCode}
  7522. function DynArrayIsEqual(const V1, V2: ExtendedArray): Boolean;
  7523. var I, L : Integer;
  7524. begin
  7525. L := Length(V1);
  7526. if L <> Length(V2) then
  7527. begin
  7528. Result := False;
  7529. exit;
  7530. end;
  7531. for I := 0 to L - 1 do
  7532. if V1[I] <> V2[I] then
  7533. begin
  7534. Result := False;
  7535. exit;
  7536. end;
  7537. Result := True;
  7538. end;
  7539. {$ELSE}
  7540. function DynArrayIsEqual(const V1, V2: ExtendedArray): Boolean;
  7541. var L : Integer;
  7542. begin
  7543. L := Length(V1);
  7544. if L <> Length(V2) then
  7545. begin
  7546. Result := False;
  7547. exit;
  7548. end;
  7549. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Extended) * L);
  7550. end;
  7551. {$ENDIF}
  7552. {$IFDEF ManagedCode}
  7553. function DynArrayIsEqual(const V1, V2: CurrencyArray): Boolean;
  7554. var I, L : Integer;
  7555. begin
  7556. L := Length(V1);
  7557. if L <> Length(V2) then
  7558. begin
  7559. Result := False;
  7560. exit;
  7561. end;
  7562. for I := 0 to L - 1 do
  7563. if V1[I] <> V2[I] then
  7564. begin
  7565. Result := False;
  7566. exit;
  7567. end;
  7568. Result := True;
  7569. end;
  7570. {$ELSE}
  7571. function DynArrayIsEqual(const V1, V2: CurrencyArray): Boolean;
  7572. var L : Integer;
  7573. begin
  7574. L := Length(V1);
  7575. if L <> Length(V2) then
  7576. begin
  7577. Result := False;
  7578. exit;
  7579. end;
  7580. Result := CompareMem(Pointer(V1)^, Pointer(V2)^, Sizeof(Currency) * L);
  7581. end;
  7582. {$ENDIF}
  7583. function DynArrayIsEqualA(const V1, V2: AnsiStringArray): Boolean;
  7584. var I, L : Integer;
  7585. begin
  7586. L := Length(V1);
  7587. if L <> Length(V2) then
  7588. begin
  7589. Result := False;
  7590. exit;
  7591. end;
  7592. for I := 0 to L - 1 do
  7593. if V1[I] <> V2[I] then
  7594. begin
  7595. Result := False;
  7596. exit;
  7597. end;
  7598. Result := True;
  7599. end;
  7600. function DynArrayIsEqualW(const V1, V2: WideStringArray): Boolean;
  7601. var I, L : Integer;
  7602. begin
  7603. L := Length(V1);
  7604. if L <> Length(V2) then
  7605. begin
  7606. Result := False;
  7607. exit;
  7608. end;
  7609. for I := 0 to L - 1 do
  7610. if V1[I] <> V2[I] then
  7611. begin
  7612. Result := False;
  7613. exit;
  7614. end;
  7615. Result := True;
  7616. end;
  7617. function DynArrayIsEqualU(const V1, V2: UnicodeStringArray): Boolean;
  7618. var I, L : Integer;
  7619. begin
  7620. L := Length(V1);
  7621. if L <> Length(V2) then
  7622. begin
  7623. Result := False;
  7624. exit;
  7625. end;
  7626. for I := 0 to L - 1 do
  7627. if V1[I] <> V2[I] then
  7628. begin
  7629. Result := False;
  7630. exit;
  7631. end;
  7632. Result := True;
  7633. end;
  7634. function DynArrayIsEqual(const V1, V2: StringArray): Boolean;
  7635. var I, L : Integer;
  7636. begin
  7637. L := Length(V1);
  7638. if L <> Length(V2) then
  7639. begin
  7640. Result := False;
  7641. exit;
  7642. end;
  7643. for I := 0 to L - 1 do
  7644. if V1[I] <> V2[I] then
  7645. begin
  7646. Result := False;
  7647. exit;
  7648. end;
  7649. Result := True;
  7650. end;
  7651. function DynArrayIsEqual(const V1, V2: CharSetArray): Boolean;
  7652. var I, L : Integer;
  7653. begin
  7654. L := Length(V1);
  7655. if L <> Length(V2) then
  7656. begin
  7657. Result := False;
  7658. exit;
  7659. end;
  7660. for I := 0 to L - 1 do
  7661. if V1[I] <> V2[I] then
  7662. begin
  7663. Result := False;
  7664. exit;
  7665. end;
  7666. Result := True;
  7667. end;
  7668. { }
  7669. { Dynamic array to Dynamic array }
  7670. { }
  7671. function ByteArrayToLongIntArray(const V: ByteArray): LongIntArray;
  7672. var I, L : Integer;
  7673. begin
  7674. L := Length(V);
  7675. SetLength(Result, L);
  7676. for I := 0 to L - 1 do
  7677. Result[I] := V[I];
  7678. end;
  7679. function WordArrayToLongIntArray(const V: WordArray): LongIntArray;
  7680. var I, L : Integer;
  7681. begin
  7682. L := Length(V);
  7683. SetLength(Result, L);
  7684. for I := 0 to L - 1 do
  7685. Result[I] := V[I];
  7686. end;
  7687. function ShortIntArrayToLongIntArray(const V: ShortIntArray): LongIntArray;
  7688. var I, L : Integer;
  7689. begin
  7690. L := Length(V);
  7691. SetLength(Result, L);
  7692. for I := 0 to L - 1 do
  7693. Result[I] := V[I];
  7694. end;
  7695. function SmallIntArrayToLongIntArray(const V: SmallIntArray): LongIntArray;
  7696. var I, L : Integer;
  7697. begin
  7698. L := Length(V);
  7699. SetLength(Result, L);
  7700. for I := 0 to L - 1 do
  7701. Result[I] := V[I];
  7702. end;
  7703. function LongIntArrayToInt64Array(const V: LongIntArray): Int64Array;
  7704. var I, L : Integer;
  7705. begin
  7706. L := Length(V);
  7707. SetLength(Result, L);
  7708. for I := 0 to L - 1 do
  7709. Result[I] := V[I];
  7710. end;
  7711. function LongIntArrayToSingleArray(const V: LongIntArray): SingleArray;
  7712. var I, L : Integer;
  7713. begin
  7714. L := Length(V);
  7715. SetLength(Result, L);
  7716. for I := 0 to L - 1 do
  7717. Result[I] := V[I];
  7718. end;
  7719. function LongIntArrayToDoubleArray(const V: LongIntArray): DoubleArray;
  7720. var I, L : Integer;
  7721. begin
  7722. L := Length(V);
  7723. SetLength(Result, L);
  7724. for I := 0 to L - 1 do
  7725. Result[I] := V[I];
  7726. end;
  7727. function LongIntArrayToExtendedArray(const V: LongIntArray): ExtendedArray;
  7728. var I, L : Integer;
  7729. begin
  7730. L := Length(V);
  7731. SetLength(Result, L);
  7732. for I := 0 to L - 1 do
  7733. Result[I] := V[I];
  7734. end;
  7735. function SingleArrayToDoubleArray(const V: SingleArray): DoubleArray;
  7736. var I, L : Integer;
  7737. begin
  7738. L := Length(V);
  7739. SetLength(Result, L);
  7740. for I := 0 to L - 1 do
  7741. Result[I] := V[I];
  7742. end;
  7743. function SingleArrayToExtendedArray(const V: SingleArray): ExtendedArray;
  7744. var I, L : Integer;
  7745. begin
  7746. L := Length(V);
  7747. SetLength(Result, L);
  7748. for I := 0 to L - 1 do
  7749. Result[I] := V[I];
  7750. end;
  7751. function SingleArrayToCurrencyArray(const V: SingleArray): CurrencyArray;
  7752. var I, L : Integer;
  7753. begin
  7754. L := Length(V);
  7755. SetLength(Result, L);
  7756. for I := 0 to L - 1 do
  7757. Result[I] := V[I];
  7758. end;
  7759. function SingleArrayToLongIntArray(const V: SingleArray): LongIntArray;
  7760. var I, L : Integer;
  7761. begin
  7762. L := Length(V);
  7763. SetLength(Result, L);
  7764. for I := 0 to L - 1 do
  7765. Result[I] := LongInt(Trunc(V[I]));
  7766. end;
  7767. function SingleArrayToInt64Array(const V: SingleArray): Int64Array;
  7768. var I, L : Integer;
  7769. begin
  7770. L := Length(V);
  7771. SetLength(Result, L);
  7772. for I := 0 to L - 1 do
  7773. Result[I] := Trunc(V[I]);
  7774. end;
  7775. function DoubleArrayToExtendedArray(const V: DoubleArray): ExtendedArray;
  7776. var I, L : Integer;
  7777. begin
  7778. L := Length(V);
  7779. SetLength(Result, L);
  7780. for I := 0 to L - 1 do
  7781. Result[I] := V[I];
  7782. end;
  7783. function DoubleArrayToCurrencyArray(const V: DoubleArray): CurrencyArray;
  7784. var I, L : Integer;
  7785. begin
  7786. L := Length(V);
  7787. SetLength(Result, L);
  7788. for I := 0 to L - 1 do
  7789. Result[I] := V[I];
  7790. end;
  7791. function DoubleArrayToLongIntArray(const V: DoubleArray): LongIntArray;
  7792. var I, L : Integer;
  7793. begin
  7794. L := Length(V);
  7795. SetLength(Result, L);
  7796. for I := 0 to L - 1 do
  7797. Result[I] := LongInt(Trunc(V[I]));
  7798. end;
  7799. function DoubleArrayToInt64Array(const V: DoubleArray): Int64Array;
  7800. var I, L : Integer;
  7801. begin
  7802. L := Length(V);
  7803. SetLength(Result, L);
  7804. for I := 0 to L - 1 do
  7805. Result[I] := Trunc(V[I]);
  7806. end;
  7807. function ExtendedArrayToCurrencyArray(const V: ExtendedArray): CurrencyArray;
  7808. var I, L : Integer;
  7809. begin
  7810. L := Length(V);
  7811. SetLength(Result, L);
  7812. for I := 0 to L - 1 do
  7813. Result[I] := V[I];
  7814. end;
  7815. function ExtendedArrayToLongIntArray(const V: ExtendedArray): LongIntArray;
  7816. var I, L : Integer;
  7817. begin
  7818. L := Length(V);
  7819. SetLength(Result, L);
  7820. for I := 0 to L - 1 do
  7821. Result[I] := LongInt(Trunc(V[I]));
  7822. end;
  7823. function ExtendedArrayToInt64Array(const V: ExtendedArray): Int64Array;
  7824. var I, L : Integer;
  7825. begin
  7826. L := Length(V);
  7827. SetLength(Result, L);
  7828. for I := 0 to L - 1 do
  7829. Result[I] := Trunc(V[I]);
  7830. end;
  7831. { }
  7832. { Array from indexes }
  7833. { }
  7834. function ByteArrayFromIndexes(const V: ByteArray; const Indexes: IntegerArray): ByteArray;
  7835. var I, L : Integer;
  7836. begin
  7837. L := Length(Indexes);
  7838. SetLength(Result, L);
  7839. for I := 0 to L - 1 do
  7840. Result[I] := V[Indexes[I]];
  7841. end;
  7842. function WordArrayFromIndexes(const V: WordArray; const Indexes: IntegerArray): WordArray;
  7843. var I, L : Integer;
  7844. begin
  7845. L := Length(Indexes);
  7846. SetLength(Result, L);
  7847. for I := 0 to L - 1 do
  7848. Result[I] := V[Indexes[I]];
  7849. end;
  7850. function LongWordArrayFromIndexes(const V: LongWordArray; const Indexes: IntegerArray): LongWordArray;
  7851. var I, L : Integer;
  7852. begin
  7853. L := Length(Indexes);
  7854. SetLength(Result, L);
  7855. for I := 0 to L - 1 do
  7856. Result[I] := V[Indexes[I]];
  7857. end;
  7858. function CardinalArrayFromIndexes(const V: CardinalArray; const Indexes: IntegerArray): CardinalArray;
  7859. var I, L : Integer;
  7860. begin
  7861. L := Length(Indexes);
  7862. SetLength(Result, L);
  7863. for I := 0 to L - 1 do
  7864. Result[I] := V[Indexes[I]];
  7865. end;
  7866. function ShortIntArrayFromIndexes(const V: ShortIntArray; const Indexes: IntegerArray): ShortIntArray;
  7867. var I, L : Integer;
  7868. begin
  7869. L := Length(Indexes);
  7870. SetLength(Result, L);
  7871. for I := 0 to L - 1 do
  7872. Result[I] := V[Indexes[I]];
  7873. end;
  7874. function SmallIntArrayFromIndexes(const V: SmallIntArray; const Indexes: IntegerArray): SmallIntArray;
  7875. var I, L : Integer;
  7876. begin
  7877. L := Length(Indexes);
  7878. SetLength(Result, L);
  7879. for I := 0 to L - 1 do
  7880. Result[I] := V[Indexes[I]];
  7881. end;
  7882. function LongIntArrayFromIndexes(const V: LongIntArray; const Indexes: IntegerArray): LongIntArray;
  7883. var I, L : Integer;
  7884. begin
  7885. L := Length(Indexes);
  7886. SetLength(Result, L);
  7887. for I := 0 to L - 1 do
  7888. Result[I] := V[Indexes[I]];
  7889. end;
  7890. function IntegerArrayFromIndexes(const V: IntegerArray; const Indexes: IntegerArray): IntegerArray;
  7891. var I, L : Integer;
  7892. begin
  7893. L := Length(Indexes);
  7894. SetLength(Result, L);
  7895. for I := 0 to L - 1 do
  7896. Result[I] := V[Indexes[I]];
  7897. end;
  7898. function Int64ArrayFromIndexes(const V: Int64Array; const Indexes: IntegerArray): Int64Array;
  7899. var I, L : Integer;
  7900. begin
  7901. L := Length(Indexes);
  7902. SetLength(Result, L);
  7903. for I := 0 to L - 1 do
  7904. Result[I] := V[Indexes[I]];
  7905. end;
  7906. function SingleArrayFromIndexes(const V: SingleArray; const Indexes: IntegerArray): SingleArray;
  7907. var I, L : Integer;
  7908. begin
  7909. L := Length(Indexes);
  7910. SetLength(Result, L);
  7911. for I := 0 to L - 1 do
  7912. Result[I] := V[Indexes[I]];
  7913. end;
  7914. function DoubleArrayFromIndexes(const V: DoubleArray; const Indexes: IntegerArray): DoubleArray;
  7915. var I, L : Integer;
  7916. begin
  7917. L := Length(Indexes);
  7918. SetLength(Result, L);
  7919. for I := 0 to L - 1 do
  7920. Result[I] := V[Indexes[I]];
  7921. end;
  7922. function ExtendedArrayFromIndexes(const V: ExtendedArray; const Indexes: IntegerArray): ExtendedArray;
  7923. var I, L : Integer;
  7924. begin
  7925. L := Length(Indexes);
  7926. SetLength(Result, L);
  7927. for I := 0 to L - 1 do
  7928. Result[I] := V[Indexes[I]];
  7929. end;
  7930. function StringArrayFromIndexes(const V: StringArray; const Indexes: IntegerArray): StringArray;
  7931. var I, L : Integer;
  7932. begin
  7933. L := Length(Indexes);
  7934. SetLength(Result, L);
  7935. for I := 0 to L - 1 do
  7936. Result[I] := V[Indexes[I]];
  7937. end;
  7938. { }
  7939. { Dynamic array sort }
  7940. { }
  7941. {$IFDEF ManagedCode}
  7942. procedure DynArraySort(const V: ByteArray);
  7943. procedure QuickSort(L, R: Integer);
  7944. var I, J, M : Integer;
  7945. W, T : Byte;
  7946. begin
  7947. repeat
  7948. I := L;
  7949. J := R;
  7950. M := (L + R) shr 1;
  7951. W := V[M];
  7952. repeat
  7953. while V[I] < W do
  7954. Inc(I);
  7955. while V[J] > W do
  7956. Dec(J);
  7957. if I <= J then
  7958. begin
  7959. T := V[I];
  7960. V[I] := V[J];
  7961. V[J] := T;
  7962. if M = I then
  7963. begin
  7964. M := J;
  7965. W := V[J];
  7966. end else
  7967. if M = J then
  7968. begin
  7969. M := I;
  7970. W := V[I];
  7971. end;
  7972. Inc(I);
  7973. Dec(J);
  7974. end;
  7975. until I > J;
  7976. if L < J then
  7977. QuickSort(L, J);
  7978. L := I;
  7979. until I >= R;
  7980. end;
  7981. var I : Integer;
  7982. begin
  7983. I := Length(V);
  7984. if I > 0 then
  7985. QuickSort(0, I - 1);
  7986. end;
  7987. {$ELSE}
  7988. procedure DynArraySort(const V: ByteArray);
  7989. procedure QuickSort(L, R: Integer);
  7990. var I, J, M : Integer;
  7991. W, T : Byte;
  7992. P, Q : PByte;
  7993. begin
  7994. repeat
  7995. I := L;
  7996. P := @V[I];
  7997. J := R;
  7998. Q := @V[J];
  7999. M := (L + R) shr 1;
  8000. W := V[M];
  8001. repeat
  8002. while P^ < W do
  8003. begin
  8004. Inc(P);
  8005. Inc(I);
  8006. end;
  8007. while Q^ > W do
  8008. begin
  8009. Dec(Q);
  8010. Dec(J);
  8011. end;
  8012. if I <= J then
  8013. begin
  8014. T := P^;
  8015. P^ := Q^;
  8016. Q^ := T;
  8017. if M = I then
  8018. begin
  8019. M := J;
  8020. W := Q^;
  8021. end else
  8022. if M = J then
  8023. begin
  8024. M := I;
  8025. W := P^;
  8026. end;
  8027. Inc(P);
  8028. Inc(I);
  8029. Dec(Q);
  8030. Dec(J);
  8031. end;
  8032. until I > J;
  8033. if L < J then
  8034. QuickSort(L, J);
  8035. L := I;
  8036. until I >= R;
  8037. end;
  8038. var I : Integer;
  8039. begin
  8040. I := Length(V);
  8041. if I > 0 then
  8042. QuickSort(0, I - 1);
  8043. end;
  8044. {$ENDIF}
  8045. {$IFDEF ManagedCode}
  8046. procedure DynArraySort(const V: WordArray);
  8047. procedure QuickSort(L, R: Integer);
  8048. var I, J, M : Integer;
  8049. W, T : Word;
  8050. begin
  8051. repeat
  8052. I := L;
  8053. J := R;
  8054. M := (L + R) shr 1;
  8055. W := V[M];
  8056. repeat
  8057. while V[I] < W do
  8058. Inc(I);
  8059. while V[J] > W do
  8060. Dec(J);
  8061. if I <= J then
  8062. begin
  8063. T := V[I];
  8064. V[I] := V[J];
  8065. V[J] := T;
  8066. if M = I then
  8067. begin
  8068. M := J;
  8069. W := V[J];
  8070. end else
  8071. if M = J then
  8072. begin
  8073. M := I;
  8074. W := V[I];
  8075. end;
  8076. Inc(I);
  8077. Dec(J);
  8078. end;
  8079. until I > J;
  8080. if L < J then
  8081. QuickSort(L, J);
  8082. L := I;
  8083. until I >= R;
  8084. end;
  8085. var I : Integer;
  8086. begin
  8087. I := Length(V);
  8088. if I > 0 then
  8089. QuickSort(0, I - 1);
  8090. end;
  8091. {$ELSE}
  8092. procedure DynArraySort(const V: WordArray);
  8093. procedure QuickSort(L, R: Integer);
  8094. var I, J, M : Integer;
  8095. W, T : Word;
  8096. P, Q : PWord;
  8097. begin
  8098. repeat
  8099. I := L;
  8100. P := @V[I];
  8101. J := R;
  8102. Q := @V[J];
  8103. M := (L + R) shr 1;
  8104. W := V[M];
  8105. repeat
  8106. while P^ < W do
  8107. begin
  8108. Inc(P);
  8109. Inc(I);
  8110. end;
  8111. while Q^ > W do
  8112. begin
  8113. Dec(Q);
  8114. Dec(J);
  8115. end;
  8116. if I <= J then
  8117. begin
  8118. T := P^;
  8119. P^ := Q^;
  8120. Q^ := T;
  8121. if M = I then
  8122. begin
  8123. M := J;
  8124. W := Q^;
  8125. end else
  8126. if M = J then
  8127. begin
  8128. M := I;
  8129. W := P^;
  8130. end;
  8131. Inc(P);
  8132. Inc(I);
  8133. Dec(Q);
  8134. Dec(J);
  8135. end;
  8136. until I > J;
  8137. if L < J then
  8138. QuickSort(L, J);
  8139. L := I;
  8140. until I >= R;
  8141. end;
  8142. var I : Integer;
  8143. begin
  8144. I := Length(V);
  8145. if I > 0 then
  8146. QuickSort(0, I - 1);
  8147. end;
  8148. {$ENDIF}
  8149. {$IFDEF ManagedCode}
  8150. procedure DynArraySort(const V: LongWordArray);
  8151. procedure QuickSort(L, R: Integer);
  8152. var I, J, M : Integer;
  8153. W, T : LongWord;
  8154. begin
  8155. repeat
  8156. I := L;
  8157. J := R;
  8158. M := (L + R) shr 1;
  8159. W := V[M];
  8160. repeat
  8161. while V[I] < W do
  8162. Inc(I);
  8163. while V[J] > W do
  8164. Dec(J);
  8165. if I <= J then
  8166. begin
  8167. T := V[I];
  8168. V[I] := V[J];
  8169. V[J] := T;
  8170. if M = I then
  8171. begin
  8172. M := J;
  8173. W := V[J];
  8174. end else
  8175. if M = J then
  8176. begin
  8177. M := I;
  8178. W := V[I];
  8179. end;
  8180. Inc(I);
  8181. Dec(J);
  8182. end;
  8183. until I > J;
  8184. if L < J then
  8185. QuickSort(L, J);
  8186. L := I;
  8187. until I >= R;
  8188. end;
  8189. var I : Integer;
  8190. begin
  8191. I := Length(V);
  8192. if I > 0 then
  8193. QuickSort(0, I - 1);
  8194. end;
  8195. {$ELSE}
  8196. procedure DynArraySort(const V: LongWordArray);
  8197. procedure QuickSort(L, R: Integer);
  8198. var I, J, M : Integer;
  8199. W, T : LongWord;
  8200. P, Q : PLongWord;
  8201. begin
  8202. repeat
  8203. I := L;
  8204. P := @V[I];
  8205. J := R;
  8206. Q := @V[J];
  8207. M := (L + R) shr 1;
  8208. W := V[M];
  8209. repeat
  8210. while P^ < W do
  8211. begin
  8212. Inc(P);
  8213. Inc(I);
  8214. end;
  8215. while Q^ > W do
  8216. begin
  8217. Dec(Q);
  8218. Dec(J);
  8219. end;
  8220. if I <= J then
  8221. begin
  8222. T := P^;
  8223. P^ := Q^;
  8224. Q^ := T;
  8225. if M = I then
  8226. begin
  8227. M := J;
  8228. W := Q^;
  8229. end else
  8230. if M = J then
  8231. begin
  8232. M := I;
  8233. W := P^;
  8234. end;
  8235. Inc(P);
  8236. Inc(I);
  8237. Dec(Q);
  8238. Dec(J);
  8239. end;
  8240. until I > J;
  8241. if L < J then
  8242. QuickSort(L, J);
  8243. L := I;
  8244. until I >= R;
  8245. end;
  8246. var I : Integer;
  8247. begin
  8248. I := Length(V);
  8249. if I > 0 then
  8250. QuickSort(0, I - 1);
  8251. end;
  8252. {$ENDIF}
  8253. {$IFDEF ManagedCode}
  8254. procedure DynArraySort(const V: NativeUIntArray);
  8255. procedure QuickSort(L, R: Integer);
  8256. var I, J, M : Integer;
  8257. W, T : NativeUInt;
  8258. begin
  8259. repeat
  8260. I := L;
  8261. J := R;
  8262. M := (L + R) shr 1;
  8263. W := V[M];
  8264. repeat
  8265. while V[I] < W do
  8266. Inc(I);
  8267. while V[J] > W do
  8268. Dec(J);
  8269. if I <= J then
  8270. begin
  8271. T := V[I];
  8272. V[I] := V[J];
  8273. V[J] := T;
  8274. if M = I then
  8275. begin
  8276. M := J;
  8277. W := V[J];
  8278. end else
  8279. if M = J then
  8280. begin
  8281. M := I;
  8282. W := V[I];
  8283. end;
  8284. Inc(I);
  8285. Dec(J);
  8286. end;
  8287. until I > J;
  8288. if L < J then
  8289. QuickSort(L, J);
  8290. L := I;
  8291. until I >= R;
  8292. end;
  8293. var I : Integer;
  8294. begin
  8295. I := Length(V);
  8296. if I > 0 then
  8297. QuickSort(0, I - 1);
  8298. end;
  8299. {$ELSE}
  8300. procedure DynArraySort(const V: NativeUIntArray);
  8301. procedure QuickSort(L, R: Integer);
  8302. var I, J, M : Integer;
  8303. W, T : NativeUInt;
  8304. P, Q : PNativeUInt;
  8305. begin
  8306. repeat
  8307. I := L;
  8308. P := @V[I];
  8309. J := R;
  8310. Q := @V[J];
  8311. M := (L + R) shr 1;
  8312. W := V[M];
  8313. repeat
  8314. while P^ < W do
  8315. begin
  8316. Inc(P);
  8317. Inc(I);
  8318. end;
  8319. while Q^ > W do
  8320. begin
  8321. Dec(Q);
  8322. Dec(J);
  8323. end;
  8324. if I <= J then
  8325. begin
  8326. T := P^;
  8327. P^ := Q^;
  8328. Q^ := T;
  8329. if M = I then
  8330. begin
  8331. M := J;
  8332. W := Q^;
  8333. end else
  8334. if M = J then
  8335. begin
  8336. M := I;
  8337. W := P^;
  8338. end;
  8339. Inc(P);
  8340. Inc(I);
  8341. Dec(Q);
  8342. Dec(J);
  8343. end;
  8344. until I > J;
  8345. if L < J then
  8346. QuickSort(L, J);
  8347. L := I;
  8348. until I >= R;
  8349. end;
  8350. var I : Integer;
  8351. begin
  8352. I := Length(V);
  8353. if I > 0 then
  8354. QuickSort(0, I - 1);
  8355. end;
  8356. {$ENDIF}
  8357. {$IFDEF ManagedCode}
  8358. procedure DynArraySort(const V: ShortIntArray);
  8359. procedure QuickSort(L, R: Integer);
  8360. var I, J, M : Integer;
  8361. W, T : ShortInt;
  8362. begin
  8363. repeat
  8364. I := L;
  8365. J := R;
  8366. M := (L + R) shr 1;
  8367. W := V[M];
  8368. repeat
  8369. while V[I] < W do
  8370. Inc(I);
  8371. while V[J] > W do
  8372. Dec(J);
  8373. if I <= J then
  8374. begin
  8375. T := V[I];
  8376. V[I] := V[J];
  8377. V[J] := T;
  8378. if M = I then
  8379. begin
  8380. M := J;
  8381. W := V[J];
  8382. end else
  8383. if M = J then
  8384. begin
  8385. M := I;
  8386. W := V[I];
  8387. end;
  8388. Inc(I);
  8389. Dec(J);
  8390. end;
  8391. until I > J;
  8392. if L < J then
  8393. QuickSort(L, J);
  8394. L := I;
  8395. until I >= R;
  8396. end;
  8397. var I : Integer;
  8398. begin
  8399. I := Length(V);
  8400. if I > 0 then
  8401. QuickSort(0, I - 1);
  8402. end;
  8403. {$ELSE}
  8404. procedure DynArraySort(const V: ShortIntArray);
  8405. procedure QuickSort(L, R: Integer);
  8406. var I, J, M : Integer;
  8407. W, T : ShortInt;
  8408. P, Q : PShortInt;
  8409. begin
  8410. repeat
  8411. I := L;
  8412. P := @V[I];
  8413. J := R;
  8414. Q := @V[J];
  8415. M := (L + R) shr 1;
  8416. W := V[M];
  8417. repeat
  8418. while P^ < W do
  8419. begin
  8420. Inc(P);
  8421. Inc(I);
  8422. end;
  8423. while Q^ > W do
  8424. begin
  8425. Dec(Q);
  8426. Dec(J);
  8427. end;
  8428. if I <= J then
  8429. begin
  8430. T := P^;
  8431. P^ := Q^;
  8432. Q^ := T;
  8433. if M = I then
  8434. begin
  8435. M := J;
  8436. W := Q^;
  8437. end else
  8438. if M = J then
  8439. begin
  8440. M := I;
  8441. W := P^;
  8442. end;
  8443. Inc(P);
  8444. Inc(I);
  8445. Dec(Q);
  8446. Dec(J);
  8447. end;
  8448. until I > J;
  8449. if L < J then
  8450. QuickSort(L, J);
  8451. L := I;
  8452. until I >= R;
  8453. end;
  8454. var I : Integer;
  8455. begin
  8456. I := Length(V);
  8457. if I > 0 then
  8458. QuickSort(0, I - 1);
  8459. end;
  8460. {$ENDIF}
  8461. {$IFDEF ManagedCode}
  8462. procedure DynArraySort(const V: SmallIntArray);
  8463. procedure QuickSort(L, R: Integer);
  8464. var I, J, M : Integer;
  8465. W, T : SmallInt;
  8466. begin
  8467. repeat
  8468. I := L;
  8469. J := R;
  8470. M := (L + R) shr 1;
  8471. W := V[M];
  8472. repeat
  8473. while V[I] < W do
  8474. Inc(I);
  8475. while V[J] > W do
  8476. Dec(J);
  8477. if I <= J then
  8478. begin
  8479. T := V[I];
  8480. V[I] := V[J];
  8481. V[J] := T;
  8482. if M = I then
  8483. begin
  8484. M := J;
  8485. W := V[J];
  8486. end else
  8487. if M = J then
  8488. begin
  8489. M := I;
  8490. W := V[I];
  8491. end;
  8492. Inc(I);
  8493. Dec(J);
  8494. end;
  8495. until I > J;
  8496. if L < J then
  8497. QuickSort(L, J);
  8498. L := I;
  8499. until I >= R;
  8500. end;
  8501. var I : Integer;
  8502. begin
  8503. I := Length(V);
  8504. if I > 0 then
  8505. QuickSort(0, I - 1);
  8506. end;
  8507. {$ELSE}
  8508. procedure DynArraySort(const V: SmallIntArray);
  8509. procedure QuickSort(L, R: Integer);
  8510. var I, J, M : Integer;
  8511. W, T : SmallInt;
  8512. P, Q : PSmallInt;
  8513. begin
  8514. repeat
  8515. I := L;
  8516. P := @V[I];
  8517. J := R;
  8518. Q := @V[J];
  8519. M := (L + R) shr 1;
  8520. W := V[M];
  8521. repeat
  8522. while P^ < W do
  8523. begin
  8524. Inc(P);
  8525. Inc(I);
  8526. end;
  8527. while Q^ > W do
  8528. begin
  8529. Dec(Q);
  8530. Dec(J);
  8531. end;
  8532. if I <= J then
  8533. begin
  8534. T := P^;
  8535. P^ := Q^;
  8536. Q^ := T;
  8537. if M = I then
  8538. begin
  8539. M := J;
  8540. W := Q^;
  8541. end else
  8542. if M = J then
  8543. begin
  8544. M := I;
  8545. W := P^;
  8546. end;
  8547. Inc(P);
  8548. Inc(I);
  8549. Dec(Q);
  8550. Dec(J);
  8551. end;
  8552. until I > J;
  8553. if L < J then
  8554. QuickSort(L, J);
  8555. L := I;
  8556. until I >= R;
  8557. end;
  8558. var I : Integer;
  8559. begin
  8560. I := Length(V);
  8561. if I > 0 then
  8562. QuickSort(0, I - 1);
  8563. end;
  8564. {$ENDIF}
  8565. {$IFDEF ManagedCode}
  8566. procedure DynArraySort(const V: LongIntArray);
  8567. procedure QuickSort(L, R: Integer);
  8568. var I, J, M : Integer;
  8569. W, T : LongInt;
  8570. begin
  8571. repeat
  8572. I := L;
  8573. J := R;
  8574. M := (L + R) shr 1;
  8575. W := V[M];
  8576. repeat
  8577. while V[I] < W do
  8578. Inc(I);
  8579. while V[J] > W do
  8580. Dec(J);
  8581. if I <= J then
  8582. begin
  8583. T := V[I];
  8584. V[I] := V[J];
  8585. V[J] := T;
  8586. if M = I then
  8587. begin
  8588. M := J;
  8589. W := V[J];
  8590. end else
  8591. if M = J then
  8592. begin
  8593. M := I;
  8594. W := V[I];
  8595. end;
  8596. Inc(I);
  8597. Dec(J);
  8598. end;
  8599. until I > J;
  8600. if L < J then
  8601. QuickSort(L, J);
  8602. L := I;
  8603. until I >= R;
  8604. end;
  8605. var I : Integer;
  8606. begin
  8607. I := Length(V);
  8608. if I > 0 then
  8609. QuickSort(0, I - 1);
  8610. end;
  8611. {$ELSE}
  8612. procedure DynArraySort(const V: LongIntArray);
  8613. procedure QuickSort(L, R: Integer);
  8614. var I, J, M : Integer;
  8615. W, T : LongInt;
  8616. P, Q : PLongInt;
  8617. begin
  8618. repeat
  8619. I := L;
  8620. P := @V[I];
  8621. J := R;
  8622. Q := @V[J];
  8623. M := (L + R) shr 1;
  8624. W := V[M];
  8625. repeat
  8626. while P^ < W do
  8627. begin
  8628. Inc(P);
  8629. Inc(I);
  8630. end;
  8631. while Q^ > W do
  8632. begin
  8633. Dec(Q);
  8634. Dec(J);
  8635. end;
  8636. if I <= J then
  8637. begin
  8638. T := P^;
  8639. P^ := Q^;
  8640. Q^ := T;
  8641. if M = I then
  8642. begin
  8643. M := J;
  8644. W := Q^;
  8645. end else
  8646. if M = J then
  8647. begin
  8648. M := I;
  8649. W := P^;
  8650. end;
  8651. Inc(P);
  8652. Inc(I);
  8653. Dec(Q);
  8654. Dec(J);
  8655. end;
  8656. until I > J;
  8657. if L < J then
  8658. QuickSort(L, J);
  8659. L := I;
  8660. until I >= R;
  8661. end;
  8662. var I : Integer;
  8663. begin
  8664. I := Length(V);
  8665. if I > 0 then
  8666. QuickSort(0, I - 1);
  8667. end;
  8668. {$ENDIF}
  8669. {$IFDEF ManagedCode}
  8670. procedure DynArraySort(const V: Int64Array);
  8671. procedure QuickSort(L, R: Integer);
  8672. var I, J, M : Integer;
  8673. W, T : Int64;
  8674. begin
  8675. repeat
  8676. I := L;
  8677. J := R;
  8678. M := (L + R) shr 1;
  8679. W := V[M];
  8680. repeat
  8681. while V[I] < W do
  8682. Inc(I);
  8683. while V[J] > W do
  8684. Dec(J);
  8685. if I <= J then
  8686. begin
  8687. T := V[I];
  8688. V[I] := V[J];
  8689. V[J] := T;
  8690. if M = I then
  8691. begin
  8692. M := J;
  8693. W := V[J];
  8694. end else
  8695. if M = J then
  8696. begin
  8697. M := I;
  8698. W := V[I];
  8699. end;
  8700. Inc(I);
  8701. Dec(J);
  8702. end;
  8703. until I > J;
  8704. if L < J then
  8705. QuickSort(L, J);
  8706. L := I;
  8707. until I >= R;
  8708. end;
  8709. var I : Integer;
  8710. begin
  8711. I := Length(V);
  8712. if I > 0 then
  8713. QuickSort(0, I - 1);
  8714. end;
  8715. {$ELSE}
  8716. procedure DynArraySort(const V: Int64Array);
  8717. procedure QuickSort(L, R: Integer);
  8718. var I, J, M : Integer;
  8719. W, T : Int64;
  8720. P, Q : PInt64;
  8721. begin
  8722. repeat
  8723. I := L;
  8724. P := @V[I];
  8725. J := R;
  8726. Q := @V[J];
  8727. M := (L + R) shr 1;
  8728. W := V[M];
  8729. repeat
  8730. while P^ < W do
  8731. begin
  8732. Inc(P);
  8733. Inc(I);
  8734. end;
  8735. while Q^ > W do
  8736. begin
  8737. Dec(Q);
  8738. Dec(J);
  8739. end;
  8740. if I <= J then
  8741. begin
  8742. T := P^;
  8743. P^ := Q^;
  8744. Q^ := T;
  8745. if M = I then
  8746. begin
  8747. M := J;
  8748. W := Q^;
  8749. end else
  8750. if M = J then
  8751. begin
  8752. M := I;
  8753. W := P^;
  8754. end;
  8755. Inc(P);
  8756. Inc(I);
  8757. Dec(Q);
  8758. Dec(J);
  8759. end;
  8760. until I > J;
  8761. if L < J then
  8762. QuickSort(L, J);
  8763. L := I;
  8764. until I >= R;
  8765. end;
  8766. var I : Integer;
  8767. begin
  8768. I := Length(V);
  8769. if I > 0 then
  8770. QuickSort(0, I - 1);
  8771. end;
  8772. {$ENDIF}
  8773. {$IFDEF ManagedCode}
  8774. procedure DynArraySort(const V: NativeIntArray);
  8775. procedure QuickSort(L, R: Integer);
  8776. var I, J, M : Integer;
  8777. W, T : NativeInt;
  8778. begin
  8779. repeat
  8780. I := L;
  8781. J := R;
  8782. M := (L + R) shr 1;
  8783. W := V[M];
  8784. repeat
  8785. while V[I] < W do
  8786. Inc(I);
  8787. while V[J] > W do
  8788. Dec(J);
  8789. if I <= J then
  8790. begin
  8791. T := V[I];
  8792. V[I] := V[J];
  8793. V[J] := T;
  8794. if M = I then
  8795. begin
  8796. M := J;
  8797. W := V[J];
  8798. end else
  8799. if M = J then
  8800. begin
  8801. M := I;
  8802. W := V[I];
  8803. end;
  8804. Inc(I);
  8805. Dec(J);
  8806. end;
  8807. until I > J;
  8808. if L < J then
  8809. QuickSort(L, J);
  8810. L := I;
  8811. until I >= R;
  8812. end;
  8813. var I : Integer;
  8814. begin
  8815. I := Length(V);
  8816. if I > 0 then
  8817. QuickSort(0, I - 1);
  8818. end;
  8819. {$ELSE}
  8820. procedure DynArraySort(const V: NativeIntArray);
  8821. procedure QuickSort(L, R: Integer);
  8822. var I, J, M : Integer;
  8823. W, T : NativeInt;
  8824. P, Q : PNativeInt;
  8825. begin
  8826. repeat
  8827. I := L;
  8828. P := @V[I];
  8829. J := R;
  8830. Q := @V[J];
  8831. M := (L + R) shr 1;
  8832. W := V[M];
  8833. repeat
  8834. while P^ < W do
  8835. begin
  8836. Inc(P);
  8837. Inc(I);
  8838. end;
  8839. while Q^ > W do
  8840. begin
  8841. Dec(Q);
  8842. Dec(J);
  8843. end;
  8844. if I <= J then
  8845. begin
  8846. T := P^;
  8847. P^ := Q^;
  8848. Q^ := T;
  8849. if M = I then
  8850. begin
  8851. M := J;
  8852. W := Q^;
  8853. end else
  8854. if M = J then
  8855. begin
  8856. M := I;
  8857. W := P^;
  8858. end;
  8859. Inc(P);
  8860. Inc(I);
  8861. Dec(Q);
  8862. Dec(J);
  8863. end;
  8864. until I > J;
  8865. if L < J then
  8866. QuickSort(L, J);
  8867. L := I;
  8868. until I >= R;
  8869. end;
  8870. var I : Integer;
  8871. begin
  8872. I := Length(V);
  8873. if I > 0 then
  8874. QuickSort(0, I - 1);
  8875. end;
  8876. {$ENDIF}
  8877. {$IFDEF ManagedCode}
  8878. procedure DynArraySort(const V: SingleArray);
  8879. procedure QuickSort(L, R: Integer);
  8880. var I, J, M : Integer;
  8881. W, T : Single;
  8882. begin
  8883. repeat
  8884. I := L;
  8885. J := R;
  8886. M := (L + R) shr 1;
  8887. W := V[M];
  8888. repeat
  8889. while V[I] < W do
  8890. Inc(I);
  8891. while V[J] > W do
  8892. Dec(J);
  8893. if I <= J then
  8894. begin
  8895. T := V[I];
  8896. V[I] := V[J];
  8897. V[J] := T;
  8898. if M = I then
  8899. begin
  8900. M := J;
  8901. W := V[J];
  8902. end else
  8903. if M = J then
  8904. begin
  8905. M := I;
  8906. W := V[I];
  8907. end;
  8908. Inc(I);
  8909. Dec(J);
  8910. end;
  8911. until I > J;
  8912. if L < J then
  8913. QuickSort(L, J);
  8914. L := I;
  8915. until I >= R;
  8916. end;
  8917. var I : Integer;
  8918. begin
  8919. I := Length(V);
  8920. if I > 0 then
  8921. QuickSort(0, I - 1);
  8922. end;
  8923. {$ELSE}
  8924. procedure DynArraySort(const V: SingleArray);
  8925. procedure QuickSort(L, R: Integer);
  8926. var I, J, M : Integer;
  8927. W, T : Single;
  8928. P, Q : PSingle;
  8929. begin
  8930. repeat
  8931. I := L;
  8932. P := @V[I];
  8933. J := R;
  8934. Q := @V[J];
  8935. M := (L + R) shr 1;
  8936. W := V[M];
  8937. repeat
  8938. while P^ < W do
  8939. begin
  8940. Inc(P);
  8941. Inc(I);
  8942. end;
  8943. while Q^ > W do
  8944. begin
  8945. Dec(Q);
  8946. Dec(J);
  8947. end;
  8948. if I <= J then
  8949. begin
  8950. T := P^;
  8951. P^ := Q^;
  8952. Q^ := T;
  8953. if M = I then
  8954. begin
  8955. M := J;
  8956. W := Q^;
  8957. end else
  8958. if M = J then
  8959. begin
  8960. M := I;
  8961. W := P^;
  8962. end;
  8963. Inc(P);
  8964. Inc(I);
  8965. Dec(Q);
  8966. Dec(J);
  8967. end;
  8968. until I > J;
  8969. if L < J then
  8970. QuickSort(L, J);
  8971. L := I;
  8972. until I >= R;
  8973. end;
  8974. var I : Integer;
  8975. begin
  8976. I := Length(V);
  8977. if I > 0 then
  8978. QuickSort(0, I - 1);
  8979. end;
  8980. {$ENDIF}
  8981. {$IFDEF ManagedCode}
  8982. procedure DynArraySort(const V: DoubleArray);
  8983. procedure QuickSort(L, R: Integer);
  8984. var I, J, M : Integer;
  8985. W, T : Double;
  8986. begin
  8987. repeat
  8988. I := L;
  8989. J := R;
  8990. M := (L + R) shr 1;
  8991. W := V[M];
  8992. repeat
  8993. while V[I] < W do
  8994. Inc(I);
  8995. while V[J] > W do
  8996. Dec(J);
  8997. if I <= J then
  8998. begin
  8999. T := V[I];
  9000. V[I] := V[J];
  9001. V[J] := T;
  9002. if M = I then
  9003. begin
  9004. M := J;
  9005. W := V[J];
  9006. end else
  9007. if M = J then
  9008. begin
  9009. M := I;
  9010. W := V[I];
  9011. end;
  9012. Inc(I);
  9013. Dec(J);
  9014. end;
  9015. until I > J;
  9016. if L < J then
  9017. QuickSort(L, J);
  9018. L := I;
  9019. until I >= R;
  9020. end;
  9021. var I : Integer;
  9022. begin
  9023. I := Length(V);
  9024. if I > 0 then
  9025. QuickSort(0, I - 1);
  9026. end;
  9027. {$ELSE}
  9028. procedure DynArraySort(const V: DoubleArray);
  9029. procedure QuickSort(L, R: Integer);
  9030. var I, J, M : Integer;
  9031. W, T : Double;
  9032. P, Q : PDouble;
  9033. begin
  9034. repeat
  9035. I := L;
  9036. P := @V[I];
  9037. J := R;
  9038. Q := @V[J];
  9039. M := (L + R) shr 1;
  9040. W := V[M];
  9041. repeat
  9042. while P^ < W do
  9043. begin
  9044. Inc(P);
  9045. Inc(I);
  9046. end;
  9047. while Q^ > W do
  9048. begin
  9049. Dec(Q);
  9050. Dec(J);
  9051. end;
  9052. if I <= J then
  9053. begin
  9054. T := P^;
  9055. P^ := Q^;
  9056. Q^ := T;
  9057. if M = I then
  9058. begin
  9059. M := J;
  9060. W := Q^;
  9061. end else
  9062. if M = J then
  9063. begin
  9064. M := I;
  9065. W := P^;
  9066. end;
  9067. Inc(P);
  9068. Inc(I);
  9069. Dec(Q);
  9070. Dec(J);
  9071. end;
  9072. until I > J;
  9073. if L < J then
  9074. QuickSort(L, J);
  9075. L := I;
  9076. until I >= R;
  9077. end;
  9078. var I : Integer;
  9079. begin
  9080. I := Length(V);
  9081. if I > 0 then
  9082. QuickSort(0, I - 1);
  9083. end;
  9084. {$ENDIF}
  9085. {$IFDEF ManagedCode}
  9086. procedure DynArraySort(const V: ExtendedArray);
  9087. procedure QuickSort(L, R: Integer);
  9088. var I, J, M : Integer;
  9089. W, T : Extended;
  9090. begin
  9091. repeat
  9092. I := L;
  9093. J := R;
  9094. M := (L + R) shr 1;
  9095. W := V[M];
  9096. repeat
  9097. while V[I] < W do
  9098. Inc(I);
  9099. while V[J] > W do
  9100. Dec(J);
  9101. if I <= J then
  9102. begin
  9103. T := V[I];
  9104. V[I] := V[J];
  9105. V[J] := T;
  9106. if M = I then
  9107. begin
  9108. M := J;
  9109. W := V[J];
  9110. end else
  9111. if M = J then
  9112. begin
  9113. M := I;
  9114. W := V[I];
  9115. end;
  9116. Inc(I);
  9117. Dec(J);
  9118. end;
  9119. until I > J;
  9120. if L < J then
  9121. QuickSort(L, J);
  9122. L := I;
  9123. until I >= R;
  9124. end;
  9125. var I : Integer;
  9126. begin
  9127. I := Length(V);
  9128. if I > 0 then
  9129. QuickSort(0, I - 1);
  9130. end;
  9131. {$ELSE}
  9132. procedure DynArraySort(const V: ExtendedArray);
  9133. procedure QuickSort(L, R: Integer);
  9134. var I, J, M : Integer;
  9135. W, T : Extended;
  9136. P, Q : PExtended;
  9137. begin
  9138. repeat
  9139. I := L;
  9140. P := @V[I];
  9141. J := R;
  9142. Q := @V[J];
  9143. M := (L + R) shr 1;
  9144. W := V[M];
  9145. repeat
  9146. while P^ < W do
  9147. begin
  9148. Inc(P);
  9149. Inc(I);
  9150. end;
  9151. while Q^ > W do
  9152. begin
  9153. Dec(Q);
  9154. Dec(J);
  9155. end;
  9156. if I <= J then
  9157. begin
  9158. T := P^;
  9159. P^ := Q^;
  9160. Q^ := T;
  9161. if M = I then
  9162. begin
  9163. M := J;
  9164. W := Q^;
  9165. end else
  9166. if M = J then
  9167. begin
  9168. M := I;
  9169. W := P^;
  9170. end;
  9171. Inc(P);
  9172. Inc(I);
  9173. Dec(Q);
  9174. Dec(J);
  9175. end;
  9176. until I > J;
  9177. if L < J then
  9178. QuickSort(L, J);
  9179. L := I;
  9180. until I >= R;
  9181. end;
  9182. var I : Integer;
  9183. begin
  9184. I := Length(V);
  9185. if I > 0 then
  9186. QuickSort(0, I - 1);
  9187. end;
  9188. {$ENDIF}
  9189. {$IFDEF ManagedCode}
  9190. procedure DynArraySortA(const V: AnsiStringArray);
  9191. procedure QuickSort(L, R: Integer);
  9192. var I, J, M : Integer;
  9193. W, T : AnsiString;
  9194. begin
  9195. repeat
  9196. I := L;
  9197. J := R;
  9198. M := (L + R) shr 1;
  9199. W := V[M];
  9200. repeat
  9201. while V[I] < W do
  9202. Inc(I);
  9203. while V[J] > W do
  9204. Dec(J);
  9205. if I <= J then
  9206. begin
  9207. T := V[I];
  9208. V[I] := V[J];
  9209. V[J] := T;
  9210. if M = I then
  9211. begin
  9212. M := J;
  9213. W := V[J];
  9214. end else
  9215. if M = J then
  9216. begin
  9217. M := I;
  9218. W := V[I];
  9219. end;
  9220. Inc(I);
  9221. Dec(J);
  9222. end;
  9223. until I > J;
  9224. if L < J then
  9225. QuickSort(L, J);
  9226. L := I;
  9227. until I >= R;
  9228. end;
  9229. var I : Integer;
  9230. begin
  9231. I := Length(V);
  9232. if I > 0 then
  9233. QuickSort(0, I - 1);
  9234. end;
  9235. {$ELSE}
  9236. procedure DynArraySortA(const V: AnsiStringArray);
  9237. procedure QuickSort(L, R: Integer);
  9238. var I, J, M : Integer;
  9239. W, T : AnsiString;
  9240. P, Q : PAnsiString;
  9241. begin
  9242. repeat
  9243. I := L;
  9244. P := @V[I];
  9245. J := R;
  9246. Q := @V[J];
  9247. M := (L + R) shr 1;
  9248. W := V[M];
  9249. repeat
  9250. while P^ < W do
  9251. begin
  9252. Inc(P);
  9253. Inc(I);
  9254. end;
  9255. while Q^ > W do
  9256. begin
  9257. Dec(Q);
  9258. Dec(J);
  9259. end;
  9260. if I <= J then
  9261. begin
  9262. T := P^;
  9263. P^ := Q^;
  9264. Q^ := T;
  9265. if M = I then
  9266. begin
  9267. M := J;
  9268. W := Q^;
  9269. end else
  9270. if M = J then
  9271. begin
  9272. M := I;
  9273. W := P^;
  9274. end;
  9275. Inc(P);
  9276. Inc(I);
  9277. Dec(Q);
  9278. Dec(J);
  9279. end;
  9280. until I > J;
  9281. if L < J then
  9282. QuickSort(L, J);
  9283. L := I;
  9284. until I >= R;
  9285. end;
  9286. var I : Integer;
  9287. begin
  9288. I := Length(V);
  9289. if I > 0 then
  9290. QuickSort(0, I - 1);
  9291. end;
  9292. {$ENDIF}
  9293. {$IFDEF ManagedCode}
  9294. procedure DynArraySortW(const V: WideStringArray);
  9295. procedure QuickSort(L, R: Integer);
  9296. var I, J, M : Integer;
  9297. W, T : WideString;
  9298. begin
  9299. repeat
  9300. I := L;
  9301. J := R;
  9302. M := (L + R) shr 1;
  9303. W := V[M];
  9304. repeat
  9305. while V[I] < W do
  9306. Inc(I);
  9307. while V[J] > W do
  9308. Dec(J);
  9309. if I <= J then
  9310. begin
  9311. T := V[I];
  9312. V[I] := V[J];
  9313. V[J] := T;
  9314. if M = I then
  9315. begin
  9316. M := J;
  9317. W := V[J];
  9318. end else
  9319. if M = J then
  9320. begin
  9321. M := I;
  9322. W := V[I];
  9323. end;
  9324. Inc(I);
  9325. Dec(J);
  9326. end;
  9327. until I > J;
  9328. if L < J then
  9329. QuickSort(L, J);
  9330. L := I;
  9331. until I >= R;
  9332. end;
  9333. var I : Integer;
  9334. begin
  9335. I := Length(V);
  9336. if I > 0 then
  9337. QuickSort(0, I - 1);
  9338. end;
  9339. {$ELSE}
  9340. procedure DynArraySortW(const V: WideStringArray);
  9341. procedure QuickSort(L, R: Integer);
  9342. var I, J, M : Integer;
  9343. W, T : WideString;
  9344. P, Q : PWideString;
  9345. begin
  9346. repeat
  9347. I := L;
  9348. P := @V[I];
  9349. J := R;
  9350. Q := @V[J];
  9351. M := (L + R) shr 1;
  9352. W := V[M];
  9353. repeat
  9354. while P^ < W do
  9355. begin
  9356. Inc(P);
  9357. Inc(I);
  9358. end;
  9359. while Q^ > W do
  9360. begin
  9361. Dec(Q);
  9362. Dec(J);
  9363. end;
  9364. if I <= J then
  9365. begin
  9366. T := P^;
  9367. P^ := Q^;
  9368. Q^ := T;
  9369. if M = I then
  9370. begin
  9371. M := J;
  9372. W := Q^;
  9373. end else
  9374. if M = J then
  9375. begin
  9376. M := I;
  9377. W := P^;
  9378. end;
  9379. Inc(P);
  9380. Inc(I);
  9381. Dec(Q);
  9382. Dec(J);
  9383. end;
  9384. until I > J;
  9385. if L < J then
  9386. QuickSort(L, J);
  9387. L := I;
  9388. until I >= R;
  9389. end;
  9390. var I : Integer;
  9391. begin
  9392. I := Length(V);
  9393. if I > 0 then
  9394. QuickSort(0, I - 1);
  9395. end;
  9396. {$ENDIF}
  9397. {$IFDEF ManagedCode}
  9398. procedure DynArraySortU(const V: UnicodeStringArray);
  9399. procedure QuickSort(L, R: Integer);
  9400. var I, J, M : Integer;
  9401. W, T : UnicodeString;
  9402. begin
  9403. repeat
  9404. I := L;
  9405. J := R;
  9406. M := (L + R) shr 1;
  9407. W := V[M];
  9408. repeat
  9409. while V[I] < W do
  9410. Inc(I);
  9411. while V[J] > W do
  9412. Dec(J);
  9413. if I <= J then
  9414. begin
  9415. T := V[I];
  9416. V[I] := V[J];
  9417. V[J] := T;
  9418. if M = I then
  9419. begin
  9420. M := J;
  9421. W := V[J];
  9422. end else
  9423. if M = J then
  9424. begin
  9425. M := I;
  9426. W := V[I];
  9427. end;
  9428. Inc(I);
  9429. Dec(J);
  9430. end;
  9431. until I > J;
  9432. if L < J then
  9433. QuickSort(L, J);
  9434. L := I;
  9435. until I >= R;
  9436. end;
  9437. var I : Integer;
  9438. begin
  9439. I := Length(V);
  9440. if I > 0 then
  9441. QuickSort(0, I - 1);
  9442. end;
  9443. {$ELSE}
  9444. procedure DynArraySortU(const V: UnicodeStringArray);
  9445. procedure QuickSort(L, R: Integer);
  9446. var I, J, M : Integer;
  9447. W, T : UnicodeString;
  9448. P, Q : PUnicodeString;
  9449. begin
  9450. repeat
  9451. I := L;
  9452. P := @V[I];
  9453. J := R;
  9454. Q := @V[J];
  9455. M := (L + R) shr 1;
  9456. W := V[M];
  9457. repeat
  9458. while P^ < W do
  9459. begin
  9460. Inc(P);
  9461. Inc(I);
  9462. end;
  9463. while Q^ > W do
  9464. begin
  9465. Dec(Q);
  9466. Dec(J);
  9467. end;
  9468. if I <= J then
  9469. begin
  9470. T := P^;
  9471. P^ := Q^;
  9472. Q^ := T;
  9473. if M = I then
  9474. begin
  9475. M := J;
  9476. W := Q^;
  9477. end else
  9478. if M = J then
  9479. begin
  9480. M := I;
  9481. W := P^;
  9482. end;
  9483. Inc(P);
  9484. Inc(I);
  9485. Dec(Q);
  9486. Dec(J);
  9487. end;
  9488. until I > J;
  9489. if L < J then
  9490. QuickSort(L, J);
  9491. L := I;
  9492. until I >= R;
  9493. end;
  9494. var I : Integer;
  9495. begin
  9496. I := Length(V);
  9497. if I > 0 then
  9498. QuickSort(0, I - 1);
  9499. end;
  9500. {$ENDIF}
  9501. {$IFDEF ManagedCode}
  9502. procedure DynArraySort(const V: StringArray);
  9503. procedure QuickSort(L, R: Integer);
  9504. var I, J, M : Integer;
  9505. W, T : String;
  9506. begin
  9507. repeat
  9508. I := L;
  9509. J := R;
  9510. M := (L + R) shr 1;
  9511. W := V[M];
  9512. repeat
  9513. while V[I] < W do
  9514. Inc(I);
  9515. while V[J] > W do
  9516. Dec(J);
  9517. if I <= J then
  9518. begin
  9519. T := V[I];
  9520. V[I] := V[J];
  9521. V[J] := T;
  9522. if M = I then
  9523. begin
  9524. M := J;
  9525. W := V[J];
  9526. end else
  9527. if M = J then
  9528. begin
  9529. M := I;
  9530. W := V[I];
  9531. end;
  9532. Inc(I);
  9533. Dec(J);
  9534. end;
  9535. until I > J;
  9536. if L < J then
  9537. QuickSort(L, J);
  9538. L := I;
  9539. until I >= R;
  9540. end;
  9541. var I : Integer;
  9542. begin
  9543. I := Length(V);
  9544. if I > 0 then
  9545. QuickSort(0, I - 1);
  9546. end;
  9547. {$ELSE}
  9548. procedure DynArraySort(const V: StringArray);
  9549. procedure QuickSort(L, R: Integer);
  9550. var I, J, M : Integer;
  9551. W, T : String;
  9552. P, Q : PString;
  9553. begin
  9554. repeat
  9555. I := L;
  9556. P := @V[I];
  9557. J := R;
  9558. Q := @V[J];
  9559. M := (L + R) shr 1;
  9560. W := V[M];
  9561. repeat
  9562. while P^ < W do
  9563. begin
  9564. Inc(P);
  9565. Inc(I);
  9566. end;
  9567. while Q^ > W do
  9568. begin
  9569. Dec(Q);
  9570. Dec(J);
  9571. end;
  9572. if I <= J then
  9573. begin
  9574. T := P^;
  9575. P^ := Q^;
  9576. Q^ := T;
  9577. if M = I then
  9578. begin
  9579. M := J;
  9580. W := Q^;
  9581. end else
  9582. if M = J then
  9583. begin
  9584. M := I;
  9585. W := P^;
  9586. end;
  9587. Inc(P);
  9588. Inc(I);
  9589. Dec(Q);
  9590. Dec(J);
  9591. end;
  9592. until I > J;
  9593. if L < J then
  9594. QuickSort(L, J);
  9595. L := I;
  9596. until I >= R;
  9597. end;
  9598. var I : Integer;
  9599. begin
  9600. I := Length(V);
  9601. if I > 0 then
  9602. QuickSort(0, I - 1);
  9603. end;
  9604. {$ENDIF}
  9605. {$IFDEF ManagedCode}
  9606. procedure DynArraySort(const Key: IntegerArray; const Data: IntegerArray);
  9607. procedure QuickSort(L, R: Integer);
  9608. var I, J, M : Integer;
  9609. W, T : Integer;
  9610. A : Integer;
  9611. begin
  9612. repeat
  9613. I := L;
  9614. J := R;
  9615. M := (L + R) shr 1;
  9616. W := Key[M];
  9617. repeat
  9618. while Key[I] < W do
  9619. Inc(I);
  9620. while Key[J] > W do
  9621. Dec(J);
  9622. if I <= J then
  9623. begin
  9624. T := Key[I];
  9625. Key[I] := Key[J];
  9626. Key[J] := T;
  9627. A := Data[I];
  9628. Data[I] := Data[J];
  9629. Data[J] := A;
  9630. if M = I then
  9631. begin
  9632. M := J;
  9633. W := Key[J];
  9634. end else
  9635. if M = J then
  9636. begin
  9637. M := I;
  9638. W := Key[I];
  9639. end;
  9640. Inc(I);
  9641. Dec(J);
  9642. end;
  9643. until I > J;
  9644. if L < J then
  9645. QuickSort(L, J);
  9646. L := I;
  9647. until I >= R;
  9648. end;
  9649. var I : Integer;
  9650. begin
  9651. Assert(Length(Key) = Length(Data));
  9652. I := Length(Key);
  9653. if I > 0 then
  9654. QuickSort(0, I - 1);
  9655. end;
  9656. {$ELSE}
  9657. procedure DynArraySort(const Key: IntegerArray; const Data: IntegerArray);
  9658. procedure QuickSort(L, R: Integer);
  9659. var I, J, M : Integer;
  9660. W, T : Integer;
  9661. P, Q : PInteger;
  9662. A : Integer;
  9663. begin
  9664. repeat
  9665. I := L;
  9666. P := @Key[I];
  9667. J := R;
  9668. Q := @Key[J];
  9669. M := (L + R) shr 1;
  9670. W := Key[M];
  9671. repeat
  9672. while P^ < W do
  9673. begin
  9674. Inc(P);
  9675. Inc(I);
  9676. end;
  9677. while Q^ > W do
  9678. begin
  9679. Dec(Q);
  9680. Dec(J);
  9681. end;
  9682. if I <= J then
  9683. begin
  9684. T := P^;
  9685. P^ := Q^;
  9686. Q^ := T;
  9687. A := Data[I];
  9688. Data[I] := Data[J];
  9689. Data[J] := A;
  9690. if M = I then
  9691. begin
  9692. M := J;
  9693. W := Q^;
  9694. end else
  9695. if M = J then
  9696. begin
  9697. M := I;
  9698. W := P^;
  9699. end;
  9700. Inc(P);
  9701. Inc(I);
  9702. Dec(Q);
  9703. Dec(J);
  9704. end;
  9705. until I > J;
  9706. if L < J then
  9707. QuickSort(L, J);
  9708. L := I;
  9709. until I >= R;
  9710. end;
  9711. var I : Integer;
  9712. begin
  9713. Assert(Length(Key) = Length(Data));
  9714. I := Length(Key);
  9715. if I > 0 then
  9716. QuickSort(0, I - 1);
  9717. end;
  9718. {$ENDIF}
  9719. {$IFDEF ManagedCode}
  9720. procedure DynArraySort(const Key: IntegerArray; const Data: Int64Array);
  9721. procedure QuickSort(L, R: Integer);
  9722. var I, J, M : Integer;
  9723. W, T : Integer;
  9724. A : Int64;
  9725. begin
  9726. repeat
  9727. I := L;
  9728. J := R;
  9729. M := (L + R) shr 1;
  9730. W := Key[M];
  9731. repeat
  9732. while Key[I] < W do
  9733. Inc(I);
  9734. while Key[J] > W do
  9735. Dec(J);
  9736. if I <= J then
  9737. begin
  9738. T := Key[I];
  9739. Key[I] := Key[J];
  9740. Key[J] := T;
  9741. A := Data[I];
  9742. Data[I] := Data[J];
  9743. Data[J] := A;
  9744. if M = I then
  9745. begin
  9746. M := J;
  9747. W := Key[J];
  9748. end else
  9749. if M = J then
  9750. begin
  9751. M := I;
  9752. W := Key[I];
  9753. end;
  9754. Inc(I);
  9755. Dec(J);
  9756. end;
  9757. until I > J;
  9758. if L < J then
  9759. QuickSort(L, J);
  9760. L := I;
  9761. until I >= R;
  9762. end;
  9763. var I : Integer;
  9764. begin
  9765. Assert(Length(Key) = Length(Data));
  9766. I := Length(Key);
  9767. if I > 0 then
  9768. QuickSort(0, I - 1);
  9769. end;
  9770. {$ELSE}
  9771. procedure DynArraySort(const Key: IntegerArray; const Data: Int64Array);
  9772. procedure QuickSort(L, R: Integer);
  9773. var I, J, M : Integer;
  9774. W, T : Integer;
  9775. P, Q : PInteger;
  9776. A : Int64;
  9777. begin
  9778. repeat
  9779. I := L;
  9780. P := @Key[I];
  9781. J := R;
  9782. Q := @Key[J];
  9783. M := (L + R) shr 1;
  9784. W := Key[M];
  9785. repeat
  9786. while P^ < W do
  9787. begin
  9788. Inc(P);
  9789. Inc(I);
  9790. end;
  9791. while Q^ > W do
  9792. begin
  9793. Dec(Q);
  9794. Dec(J);
  9795. end;
  9796. if I <= J then
  9797. begin
  9798. T := P^;
  9799. P^ := Q^;
  9800. Q^ := T;
  9801. A := Data[I];
  9802. Data[I] := Data[J];
  9803. Data[J] := A;
  9804. if M = I then
  9805. begin
  9806. M := J;
  9807. W := Q^;
  9808. end else
  9809. if M = J then
  9810. begin
  9811. M := I;
  9812. W := P^;
  9813. end;
  9814. Inc(P);
  9815. Inc(I);
  9816. Dec(Q);
  9817. Dec(J);
  9818. end;
  9819. until I > J;
  9820. if L < J then
  9821. QuickSort(L, J);
  9822. L := I;
  9823. until I >= R;
  9824. end;
  9825. var I : Integer;
  9826. begin
  9827. Assert(Length(Key) = Length(Data));
  9828. I := Length(Key);
  9829. if I > 0 then
  9830. QuickSort(0, I - 1);
  9831. end;
  9832. {$ENDIF}
  9833. {$IFDEF ManagedCode}
  9834. procedure DynArraySort(const Key: IntegerArray; const Data: AnsiStringArray);
  9835. procedure QuickSort(L, R: Integer);
  9836. var I, J, M : Integer;
  9837. W, T : Integer;
  9838. A : AnsiString;
  9839. begin
  9840. repeat
  9841. I := L;
  9842. J := R;
  9843. M := (L + R) shr 1;
  9844. W := Key[M];
  9845. repeat
  9846. while Key[I] < W do
  9847. Inc(I);
  9848. while Key[J] > W do
  9849. Dec(J);
  9850. if I <= J then
  9851. begin
  9852. T := Key[I];
  9853. Key[I] := Key[J];
  9854. Key[J] := T;
  9855. A := Data[I];
  9856. Data[I] := Data[J];
  9857. Data[J] := A;
  9858. if M = I then
  9859. begin
  9860. M := J;
  9861. W := Key[J];
  9862. end else
  9863. if M = J then
  9864. begin
  9865. M := I;
  9866. W := Key[I];
  9867. end;
  9868. Inc(I);
  9869. Dec(J);
  9870. end;
  9871. until I > J;
  9872. if L < J then
  9873. QuickSort(L, J);
  9874. L := I;
  9875. until I >= R;
  9876. end;
  9877. var I : Integer;
  9878. begin
  9879. Assert(Length(Key) = Length(Data));
  9880. I := Length(Key);
  9881. if I > 0 then
  9882. QuickSort(0, I - 1);
  9883. end;
  9884. {$ELSE}
  9885. procedure DynArraySort(const Key: IntegerArray; const Data: AnsiStringArray);
  9886. procedure QuickSort(L, R: Integer);
  9887. var I, J, M : Integer;
  9888. W, T : Integer;
  9889. P, Q : PInteger;
  9890. A : AnsiString;
  9891. begin
  9892. repeat
  9893. I := L;
  9894. P := @Key[I];
  9895. J := R;
  9896. Q := @Key[J];
  9897. M := (L + R) shr 1;
  9898. W := Key[M];
  9899. repeat
  9900. while P^ < W do
  9901. begin
  9902. Inc(P);
  9903. Inc(I);
  9904. end;
  9905. while Q^ > W do
  9906. begin
  9907. Dec(Q);
  9908. Dec(J);
  9909. end;
  9910. if I <= J then
  9911. begin
  9912. T := P^;
  9913. P^ := Q^;
  9914. Q^ := T;
  9915. A := Data[I];
  9916. Data[I] := Data[J];
  9917. Data[J] := A;
  9918. if M = I then
  9919. begin
  9920. M := J;
  9921. W := Q^;
  9922. end else
  9923. if M = J then
  9924. begin
  9925. M := I;
  9926. W := P^;
  9927. end;
  9928. Inc(P);
  9929. Inc(I);
  9930. Dec(Q);
  9931. Dec(J);
  9932. end;
  9933. until I > J;
  9934. if L < J then
  9935. QuickSort(L, J);
  9936. L := I;
  9937. until I >= R;
  9938. end;
  9939. var I : Integer;
  9940. begin
  9941. Assert(Length(Key) = Length(Data));
  9942. I := Length(Key);
  9943. if I > 0 then
  9944. QuickSort(0, I - 1);
  9945. end;
  9946. {$ENDIF}
  9947. {$IFDEF ManagedCode}
  9948. procedure DynArraySort(const Key: IntegerArray; const Data: ExtendedArray);
  9949. procedure QuickSort(L, R: Integer);
  9950. var I, J, M : Integer;
  9951. W, T : Integer;
  9952. A : Extended;
  9953. begin
  9954. repeat
  9955. I := L;
  9956. J := R;
  9957. M := (L + R) shr 1;
  9958. W := Key[M];
  9959. repeat
  9960. while Key[I] < W do
  9961. Inc(I);
  9962. while Key[J] > W do
  9963. Dec(J);
  9964. if I <= J then
  9965. begin
  9966. T := Key[I];
  9967. Key[I] := Key[J];
  9968. Key[J] := T;
  9969. A := Data[I];
  9970. Data[I] := Data[J];
  9971. Data[J] := A;
  9972. if M = I then
  9973. begin
  9974. M := J;
  9975. W := Key[J];
  9976. end else
  9977. if M = J then
  9978. begin
  9979. M := I;
  9980. W := Key[I];
  9981. end;
  9982. Inc(I);
  9983. Dec(J);
  9984. end;
  9985. until I > J;
  9986. if L < J then
  9987. QuickSort(L, J);
  9988. L := I;
  9989. until I >= R;
  9990. end;
  9991. var I : Integer;
  9992. begin
  9993. Assert(Length(Key) = Length(Data));
  9994. I := Length(Key);
  9995. if I > 0 then
  9996. QuickSort(0, I - 1);
  9997. end;
  9998. {$ELSE}
  9999. procedure DynArraySort(const Key: IntegerArray; const Data: ExtendedArray);
  10000. procedure QuickSort(L, R: Integer);
  10001. var I, J, M : Integer;
  10002. W, T : Integer;
  10003. P, Q : PInteger;
  10004. A : Extended;
  10005. begin
  10006. repeat
  10007. I := L;
  10008. P := @Key[I];
  10009. J := R;
  10010. Q := @Key[J];
  10011. M := (L + R) shr 1;
  10012. W := Key[M];
  10013. repeat
  10014. while P^ < W do
  10015. begin
  10016. Inc(P);
  10017. Inc(I);
  10018. end;
  10019. while Q^ > W do
  10020. begin
  10021. Dec(Q);
  10022. Dec(J);
  10023. end;
  10024. if I <= J then
  10025. begin
  10026. T := P^;
  10027. P^ := Q^;
  10028. Q^ := T;
  10029. A := Data[I];
  10030. Data[I] := Data[J];
  10031. Data[J] := A;
  10032. if M = I then
  10033. begin
  10034. M := J;
  10035. W := Q^;
  10036. end else
  10037. if M = J then
  10038. begin
  10039. M := I;
  10040. W := P^;
  10041. end;
  10042. Inc(P);
  10043. Inc(I);
  10044. Dec(Q);
  10045. Dec(J);
  10046. end;
  10047. until I > J;
  10048. if L < J then
  10049. QuickSort(L, J);
  10050. L := I;
  10051. until I >= R;
  10052. end;
  10053. var I : Integer;
  10054. begin
  10055. Assert(Length(Key) = Length(Data));
  10056. I := Length(Key);
  10057. if I > 0 then
  10058. QuickSort(0, I - 1);
  10059. end;
  10060. {$ENDIF}
  10061. {$IFNDEF ManagedCode}
  10062. {$IFDEF ManagedCode}
  10063. procedure DynArraySort(const Key: IntegerArray; const Data: PointerArray);
  10064. procedure QuickSort(L, R: Integer);
  10065. var I, J, M : Integer;
  10066. W, T : Integer;
  10067. A : Pointer;
  10068. begin
  10069. repeat
  10070. I := L;
  10071. J := R;
  10072. M := (L + R) shr 1;
  10073. W := Key[M];
  10074. repeat
  10075. while Key[I] < W do
  10076. Inc(I);
  10077. while Key[J] > W do
  10078. Dec(J);
  10079. if I <= J then
  10080. begin
  10081. T := Key[I];
  10082. Key[I] := Key[J];
  10083. Key[J] := T;
  10084. A := Data[I];
  10085. Data[I] := Data[J];
  10086. Data[J] := A;
  10087. if M = I then
  10088. begin
  10089. M := J;
  10090. W := Key[J];
  10091. end else
  10092. if M = J then
  10093. begin
  10094. M := I;
  10095. W := Key[I];
  10096. end;
  10097. Inc(I);
  10098. Dec(J);
  10099. end;
  10100. until I > J;
  10101. if L < J then
  10102. QuickSort(L, J);
  10103. L := I;
  10104. until I >= R;
  10105. end;
  10106. var I : Integer;
  10107. begin
  10108. Assert(Length(Key) = Length(Data));
  10109. I := Length(Key);
  10110. if I > 0 then
  10111. QuickSort(0, I - 1);
  10112. end;
  10113. {$ELSE}
  10114. procedure DynArraySort(const Key: IntegerArray; const Data: PointerArray);
  10115. procedure QuickSort(L, R: Integer);
  10116. var I, J, M : Integer;
  10117. W, T : Integer;
  10118. P, Q : PInteger;
  10119. A : Pointer;
  10120. begin
  10121. repeat
  10122. I := L;
  10123. P := @Key[I];
  10124. J := R;
  10125. Q := @Key[J];
  10126. M := (L + R) shr 1;
  10127. W := Key[M];
  10128. repeat
  10129. while P^ < W do
  10130. begin
  10131. Inc(P);
  10132. Inc(I);
  10133. end;
  10134. while Q^ > W do
  10135. begin
  10136. Dec(Q);
  10137. Dec(J);
  10138. end;
  10139. if I <= J then
  10140. begin
  10141. T := P^;
  10142. P^ := Q^;
  10143. Q^ := T;
  10144. A := Data[I];
  10145. Data[I] := Data[J];
  10146. Data[J] := A;
  10147. if M = I then
  10148. begin
  10149. M := J;
  10150. W := Q^;
  10151. end else
  10152. if M = J then
  10153. begin
  10154. M := I;
  10155. W := P^;
  10156. end;
  10157. Inc(P);
  10158. Inc(I);
  10159. Dec(Q);
  10160. Dec(J);
  10161. end;
  10162. until I > J;
  10163. if L < J then
  10164. QuickSort(L, J);
  10165. L := I;
  10166. until I >= R;
  10167. end;
  10168. var I : Integer;
  10169. begin
  10170. Assert(Length(Key) = Length(Data));
  10171. I := Length(Key);
  10172. if I > 0 then
  10173. QuickSort(0, I - 1);
  10174. end;
  10175. {$ENDIF}
  10176. {$ENDIF}
  10177. {$IFDEF ManagedCode}
  10178. procedure DynArraySort(const Key: AnsiStringArray; const Data: IntegerArray);
  10179. procedure QuickSort(L, R: Integer);
  10180. var I, J, M : Integer;
  10181. W, T : AnsiString;
  10182. A : Integer;
  10183. begin
  10184. repeat
  10185. I := L;
  10186. J := R;
  10187. M := (L + R) shr 1;
  10188. W := Key[M];
  10189. repeat
  10190. while Key[I] < W do
  10191. Inc(I);
  10192. while Key[J] > W do
  10193. Dec(J);
  10194. if I <= J then
  10195. begin
  10196. T := Key[I];
  10197. Key[I] := Key[J];
  10198. Key[J] := T;
  10199. A := Data[I];
  10200. Data[I] := Data[J];
  10201. Data[J] := A;
  10202. if M = I then
  10203. begin
  10204. M := J;
  10205. W := Key[J];
  10206. end else
  10207. if M = J then
  10208. begin
  10209. M := I;
  10210. W := Key[I];
  10211. end;
  10212. Inc(I);
  10213. Dec(J);
  10214. end;
  10215. until I > J;
  10216. if L < J then
  10217. QuickSort(L, J);
  10218. L := I;
  10219. until I >= R;
  10220. end;
  10221. var I : Integer;
  10222. begin
  10223. Assert(Length(Key) = Length(Data));
  10224. I := Length(Key);
  10225. if I > 0 then
  10226. QuickSort(0, I - 1);
  10227. end;
  10228. {$ELSE}
  10229. procedure DynArraySort(const Key: AnsiStringArray; const Data: IntegerArray);
  10230. procedure QuickSort(L, R: Integer);
  10231. var I, J, M : Integer;
  10232. W, T : AnsiString;
  10233. P, Q : PAnsiString;
  10234. A : Integer;
  10235. begin
  10236. repeat
  10237. I := L;
  10238. P := @Key[I];
  10239. J := R;
  10240. Q := @Key[J];
  10241. M := (L + R) shr 1;
  10242. W := Key[M];
  10243. repeat
  10244. while P^ < W do
  10245. begin
  10246. Inc(P);
  10247. Inc(I);
  10248. end;
  10249. while Q^ > W do
  10250. begin
  10251. Dec(Q);
  10252. Dec(J);
  10253. end;
  10254. if I <= J then
  10255. begin
  10256. T := P^;
  10257. P^ := Q^;
  10258. Q^ := T;
  10259. A := Data[I];
  10260. Data[I] := Data[J];
  10261. Data[J] := A;
  10262. if M = I then
  10263. begin
  10264. M := J;
  10265. W := Q^;
  10266. end else
  10267. if M = J then
  10268. begin
  10269. M := I;
  10270. W := P^;
  10271. end;
  10272. Inc(P);
  10273. Inc(I);
  10274. Dec(Q);
  10275. Dec(J);
  10276. end;
  10277. until I > J;
  10278. if L < J then
  10279. QuickSort(L, J);
  10280. L := I;
  10281. until I >= R;
  10282. end;
  10283. var I : Integer;
  10284. begin
  10285. Assert(Length(Key) = Length(Data));
  10286. I := Length(Key);
  10287. if I > 0 then
  10288. QuickSort(0, I - 1);
  10289. end;
  10290. {$ENDIF}
  10291. {$IFDEF ManagedCode}
  10292. procedure DynArraySort(const Key: AnsiStringArray; const Data: Int64Array);
  10293. procedure QuickSort(L, R: Integer);
  10294. var I, J, M : Integer;
  10295. W, T : AnsiString;
  10296. A : Int64;
  10297. begin
  10298. repeat
  10299. I := L;
  10300. J := R;
  10301. M := (L + R) shr 1;
  10302. W := Key[M];
  10303. repeat
  10304. while Key[I] < W do
  10305. Inc(I);
  10306. while Key[J] > W do
  10307. Dec(J);
  10308. if I <= J then
  10309. begin
  10310. T := Key[I];
  10311. Key[I] := Key[J];
  10312. Key[J] := T;
  10313. A := Data[I];
  10314. Data[I] := Data[J];
  10315. Data[J] := A;
  10316. if M = I then
  10317. begin
  10318. M := J;
  10319. W := Key[J];
  10320. end else
  10321. if M = J then
  10322. begin
  10323. M := I;
  10324. W := Key[I];
  10325. end;
  10326. Inc(I);
  10327. Dec(J);
  10328. end;
  10329. until I > J;
  10330. if L < J then
  10331. QuickSort(L, J);
  10332. L := I;
  10333. until I >= R;
  10334. end;
  10335. var I : Integer;
  10336. begin
  10337. Assert(Length(Key) = Length(Data));
  10338. I := Length(Key);
  10339. if I > 0 then
  10340. QuickSort(0, I - 1);
  10341. end;
  10342. {$ELSE}
  10343. procedure DynArraySort(const Key: AnsiStringArray; const Data: Int64Array);
  10344. procedure QuickSort(L, R: Integer);
  10345. var I, J, M : Integer;
  10346. W, T : AnsiString;
  10347. P, Q : PAnsiString;
  10348. A : Int64;
  10349. begin
  10350. repeat
  10351. I := L;
  10352. P := @Key[I];
  10353. J := R;
  10354. Q := @Key[J];
  10355. M := (L + R) shr 1;
  10356. W := Key[M];
  10357. repeat
  10358. while P^ < W do
  10359. begin
  10360. Inc(P);
  10361. Inc(I);
  10362. end;
  10363. while Q^ > W do
  10364. begin
  10365. Dec(Q);
  10366. Dec(J);
  10367. end;
  10368. if I <= J then
  10369. begin
  10370. T := P^;
  10371. P^ := Q^;
  10372. Q^ := T;
  10373. A := Data[I];
  10374. Data[I] := Data[J];
  10375. Data[J] := A;
  10376. if M = I then
  10377. begin
  10378. M := J;
  10379. W := Q^;
  10380. end else
  10381. if M = J then
  10382. begin
  10383. M := I;
  10384. W := P^;
  10385. end;
  10386. Inc(P);
  10387. Inc(I);
  10388. Dec(Q);
  10389. Dec(J);
  10390. end;
  10391. until I > J;
  10392. if L < J then
  10393. QuickSort(L, J);
  10394. L := I;
  10395. until I >= R;
  10396. end;
  10397. var I : Integer;
  10398. begin
  10399. Assert(Length(Key) = Length(Data));
  10400. I := Length(Key);
  10401. if I > 0 then
  10402. QuickSort(0, I - 1);
  10403. end;
  10404. {$ENDIF}
  10405. {$IFDEF ManagedCode}
  10406. procedure DynArraySort(const Key: AnsiStringArray; const Data: AnsiStringArray);
  10407. procedure QuickSort(L, R: Integer);
  10408. var I, J, M : Integer;
  10409. W, T : AnsiString;
  10410. A : AnsiString;
  10411. begin
  10412. repeat
  10413. I := L;
  10414. J := R;
  10415. M := (L + R) shr 1;
  10416. W := Key[M];
  10417. repeat
  10418. while Key[I] < W do
  10419. Inc(I);
  10420. while Key[J] > W do
  10421. Dec(J);
  10422. if I <= J then
  10423. begin
  10424. T := Key[I];
  10425. Key[I] := Key[J];
  10426. Key[J] := T;
  10427. A := Data[I];
  10428. Data[I] := Data[J];
  10429. Data[J] := A;
  10430. if M = I then
  10431. begin
  10432. M := J;
  10433. W := Key[J];
  10434. end else
  10435. if M = J then
  10436. begin
  10437. M := I;
  10438. W := Key[I];
  10439. end;
  10440. Inc(I);
  10441. Dec(J);
  10442. end;
  10443. until I > J;
  10444. if L < J then
  10445. QuickSort(L, J);
  10446. L := I;
  10447. until I >= R;
  10448. end;
  10449. var I : Integer;
  10450. begin
  10451. Assert(Length(Key) = Length(Data));
  10452. I := Length(Key);
  10453. if I > 0 then
  10454. QuickSort(0, I - 1);
  10455. end;
  10456. {$ELSE}
  10457. procedure DynArraySort(const Key: AnsiStringArray; const Data: AnsiStringArray);
  10458. procedure QuickSort(L, R: Integer);
  10459. var I, J, M : Integer;
  10460. W, T : AnsiString;
  10461. P, Q : PAnsiString;
  10462. A : AnsiString;
  10463. begin
  10464. repeat
  10465. I := L;
  10466. P := @Key[I];
  10467. J := R;
  10468. Q := @Key[J];
  10469. M := (L + R) shr 1;
  10470. W := Key[M];
  10471. repeat
  10472. while P^ < W do
  10473. begin
  10474. Inc(P);
  10475. Inc(I);
  10476. end;
  10477. while Q^ > W do
  10478. begin
  10479. Dec(Q);
  10480. Dec(J);
  10481. end;
  10482. if I <= J then
  10483. begin
  10484. T := P^;
  10485. P^ := Q^;
  10486. Q^ := T;
  10487. A := Data[I];
  10488. Data[I] := Data[J];
  10489. Data[J] := A;
  10490. if M = I then
  10491. begin
  10492. M := J;
  10493. W := Q^;
  10494. end else
  10495. if M = J then
  10496. begin
  10497. M := I;
  10498. W := P^;
  10499. end;
  10500. Inc(P);
  10501. Inc(I);
  10502. Dec(Q);
  10503. Dec(J);
  10504. end;
  10505. until I > J;
  10506. if L < J then
  10507. QuickSort(L, J);
  10508. L := I;
  10509. until I >= R;
  10510. end;
  10511. var I : Integer;
  10512. begin
  10513. Assert(Length(Key) = Length(Data));
  10514. I := Length(Key);
  10515. if I > 0 then
  10516. QuickSort(0, I - 1);
  10517. end;
  10518. {$ENDIF}
  10519. {$IFDEF ManagedCode}
  10520. procedure DynArraySort(const Key: AnsiStringArray; const Data: ExtendedArray);
  10521. procedure QuickSort(L, R: Integer);
  10522. var I, J, M : Integer;
  10523. W, T : AnsiString;
  10524. A : Extended;
  10525. begin
  10526. repeat
  10527. I := L;
  10528. J := R;
  10529. M := (L + R) shr 1;
  10530. W := Key[M];
  10531. repeat
  10532. while Key[I] < W do
  10533. Inc(I);
  10534. while Key[J] > W do
  10535. Dec(J);
  10536. if I <= J then
  10537. begin
  10538. T := Key[I];
  10539. Key[I] := Key[J];
  10540. Key[J] := T;
  10541. A := Data[I];
  10542. Data[I] := Data[J];
  10543. Data[J] := A;
  10544. if M = I then
  10545. begin
  10546. M := J;
  10547. W := Key[J];
  10548. end else
  10549. if M = J then
  10550. begin
  10551. M := I;
  10552. W := Key[I];
  10553. end;
  10554. Inc(I);
  10555. Dec(J);
  10556. end;
  10557. until I > J;
  10558. if L < J then
  10559. QuickSort(L, J);
  10560. L := I;
  10561. until I >= R;
  10562. end;
  10563. var I : Integer;
  10564. begin
  10565. Assert(Length(Key) = Length(Data));
  10566. I := Length(Key);
  10567. if I > 0 then
  10568. QuickSort(0, I - 1);
  10569. end;
  10570. {$ELSE}
  10571. procedure DynArraySort(const Key: AnsiStringArray; const Data: ExtendedArray);
  10572. procedure QuickSort(L, R: Integer);
  10573. var I, J, M : Integer;
  10574. W, T : AnsiString;
  10575. P, Q : PAnsiString;
  10576. A : Extended;
  10577. begin
  10578. repeat
  10579. I := L;
  10580. P := @Key[I];
  10581. J := R;
  10582. Q := @Key[J];
  10583. M := (L + R) shr 1;
  10584. W := Key[M];
  10585. repeat
  10586. while P^ < W do
  10587. begin
  10588. Inc(P);
  10589. Inc(I);
  10590. end;
  10591. while Q^ > W do
  10592. begin
  10593. Dec(Q);
  10594. Dec(J);
  10595. end;
  10596. if I <= J then
  10597. begin
  10598. T := P^;
  10599. P^ := Q^;
  10600. Q^ := T;
  10601. A := Data[I];
  10602. Data[I] := Data[J];
  10603. Data[J] := A;
  10604. if M = I then
  10605. begin
  10606. M := J;
  10607. W := Q^;
  10608. end else
  10609. if M = J then
  10610. begin
  10611. M := I;
  10612. W := P^;
  10613. end;
  10614. Inc(P);
  10615. Inc(I);
  10616. Dec(Q);
  10617. Dec(J);
  10618. end;
  10619. until I > J;
  10620. if L < J then
  10621. QuickSort(L, J);
  10622. L := I;
  10623. until I >= R;
  10624. end;
  10625. var I : Integer;
  10626. begin
  10627. Assert(Length(Key) = Length(Data));
  10628. I := Length(Key);
  10629. if I > 0 then
  10630. QuickSort(0, I - 1);
  10631. end;
  10632. {$ENDIF}
  10633. {$IFNDEF Managedcode}
  10634. {$IFDEF ManagedCode}
  10635. procedure DynArraySort(const Key: AnsiStringArray; const Data: PointerArray);
  10636. procedure QuickSort(L, R: Integer);
  10637. var I, J, M : Integer;
  10638. W, T : AnsiString;
  10639. A : Pointer;
  10640. begin
  10641. repeat
  10642. I := L;
  10643. J := R;
  10644. M := (L + R) shr 1;
  10645. W := Key[M];
  10646. repeat
  10647. while Key[I] < W do
  10648. Inc(I);
  10649. while Key[J] > W do
  10650. Dec(J);
  10651. if I <= J then
  10652. begin
  10653. T := Key[I];
  10654. Key[I] := Key[J];
  10655. Key[J] := T;
  10656. A := Data[I];
  10657. Data[I] := Data[J];
  10658. Data[J] := A;
  10659. if M = I then
  10660. begin
  10661. M := J;
  10662. W := Key[J];
  10663. end else
  10664. if M = J then
  10665. begin
  10666. M := I;
  10667. W := Key[I];
  10668. end;
  10669. Inc(I);
  10670. Dec(J);
  10671. end;
  10672. until I > J;
  10673. if L < J then
  10674. QuickSort(L, J);
  10675. L := I;
  10676. until I >= R;
  10677. end;
  10678. var I : Integer;
  10679. begin
  10680. Assert(Length(Key) = Length(Data));
  10681. I := Length(Key);
  10682. if I > 0 then
  10683. QuickSort(0, I - 1);
  10684. end;
  10685. {$ELSE}
  10686. procedure DynArraySort(const Key: AnsiStringArray; const Data: PointerArray);
  10687. procedure QuickSort(L, R: Integer);
  10688. var I, J, M : Integer;
  10689. W, T : AnsiString;
  10690. P, Q : PAnsiString;
  10691. A : Pointer;
  10692. begin
  10693. repeat
  10694. I := L;
  10695. P := @Key[I];
  10696. J := R;
  10697. Q := @Key[J];
  10698. M := (L + R) shr 1;
  10699. W := Key[M];
  10700. repeat
  10701. while P^ < W do
  10702. begin
  10703. Inc(P);
  10704. Inc(I);
  10705. end;
  10706. while Q^ > W do
  10707. begin
  10708. Dec(Q);
  10709. Dec(J);
  10710. end;
  10711. if I <= J then
  10712. begin
  10713. T := P^;
  10714. P^ := Q^;
  10715. Q^ := T;
  10716. A := Data[I];
  10717. Data[I] := Data[J];
  10718. Data[J] := A;
  10719. if M = I then
  10720. begin
  10721. M := J;
  10722. W := Q^;
  10723. end else
  10724. if M = J then
  10725. begin
  10726. M := I;
  10727. W := P^;
  10728. end;
  10729. Inc(P);
  10730. Inc(I);
  10731. Dec(Q);
  10732. Dec(J);
  10733. end;
  10734. until I > J;
  10735. if L < J then
  10736. QuickSort(L, J);
  10737. L := I;
  10738. until I >= R;
  10739. end;
  10740. var I : Integer;
  10741. begin
  10742. Assert(Length(Key) = Length(Data));
  10743. I := Length(Key);
  10744. if I > 0 then
  10745. QuickSort(0, I - 1);
  10746. end;
  10747. {$ENDIF}
  10748. {$ENDIF}
  10749. {$IFDEF ManagedCode}
  10750. procedure DynArraySort(const Key: ExtendedArray; const Data: IntegerArray);
  10751. procedure QuickSort(L, R: Integer);
  10752. var I, J, M : Integer;
  10753. W, T : Extended;
  10754. A : Integer;
  10755. begin
  10756. repeat
  10757. I := L;
  10758. J := R;
  10759. M := (L + R) shr 1;
  10760. W := Key[M];
  10761. repeat
  10762. while Key[I] < W do
  10763. Inc(I);
  10764. while Key[J] > W do
  10765. Dec(J);
  10766. if I <= J then
  10767. begin
  10768. T := Key[I];
  10769. Key[I] := Key[J];
  10770. Key[J] := T;
  10771. A := Data[I];
  10772. Data[I] := Data[J];
  10773. Data[J] := A;
  10774. if M = I then
  10775. begin
  10776. M := J;
  10777. W := Key[J];
  10778. end else
  10779. if M = J then
  10780. begin
  10781. M := I;
  10782. W := Key[I];
  10783. end;
  10784. Inc(I);
  10785. Dec(J);
  10786. end;
  10787. until I > J;
  10788. if L < J then
  10789. QuickSort(L, J);
  10790. L := I;
  10791. until I >= R;
  10792. end;
  10793. var I : Integer;
  10794. begin
  10795. Assert(Length(Key) = Length(Data));
  10796. I := Length(Key);
  10797. if I > 0 then
  10798. QuickSort(0, I - 1);
  10799. end;
  10800. {$ELSE}
  10801. procedure DynArraySort(const Key: ExtendedArray; const Data: IntegerArray);
  10802. procedure QuickSort(L, R: Integer);
  10803. var I, J, M : Integer;
  10804. W, T : Extended;
  10805. P, Q : PExtended;
  10806. A : Integer;
  10807. begin
  10808. repeat
  10809. I := L;
  10810. P := @Key[I];
  10811. J := R;
  10812. Q := @Key[J];
  10813. M := (L + R) shr 1;
  10814. W := Key[M];
  10815. repeat
  10816. while P^ < W do
  10817. begin
  10818. Inc(P);
  10819. Inc(I);
  10820. end;
  10821. while Q^ > W do
  10822. begin
  10823. Dec(Q);
  10824. Dec(J);
  10825. end;
  10826. if I <= J then
  10827. begin
  10828. T := P^;
  10829. P^ := Q^;
  10830. Q^ := T;
  10831. A := Data[I];
  10832. Data[I] := Data[J];
  10833. Data[J] := A;
  10834. if M = I then
  10835. begin
  10836. M := J;
  10837. W := Q^;
  10838. end else
  10839. if M = J then
  10840. begin
  10841. M := I;
  10842. W := P^;
  10843. end;
  10844. Inc(P);
  10845. Inc(I);
  10846. Dec(Q);
  10847. Dec(J);
  10848. end;
  10849. until I > J;
  10850. if L < J then
  10851. QuickSort(L, J);
  10852. L := I;
  10853. until I >= R;
  10854. end;
  10855. var I : Integer;
  10856. begin
  10857. Assert(Length(Key) = Length(Data));
  10858. I := Length(Key);
  10859. if I > 0 then
  10860. QuickSort(0, I - 1);
  10861. end;
  10862. {$ENDIF}
  10863. {$IFDEF ManagedCode}
  10864. procedure DynArraySort(const Key: ExtendedArray; const Data: Int64Array);
  10865. procedure QuickSort(L, R: Integer);
  10866. var I, J, M : Integer;
  10867. W, T : Extended;
  10868. A : Int64;
  10869. begin
  10870. repeat
  10871. I := L;
  10872. J := R;
  10873. M := (L + R) shr 1;
  10874. W := Key[M];
  10875. repeat
  10876. while Key[I] < W do
  10877. Inc(I);
  10878. while Key[J] > W do
  10879. Dec(J);
  10880. if I <= J then
  10881. begin
  10882. T := Key[I];
  10883. Key[I] := Key[J];
  10884. Key[J] := T;
  10885. A := Data[I];
  10886. Data[I] := Data[J];
  10887. Data[J] := A;
  10888. if M = I then
  10889. begin
  10890. M := J;
  10891. W := Key[J];
  10892. end else
  10893. if M = J then
  10894. begin
  10895. M := I;
  10896. W := Key[I];
  10897. end;
  10898. Inc(I);
  10899. Dec(J);
  10900. end;
  10901. until I > J;
  10902. if L < J then
  10903. QuickSort(L, J);
  10904. L := I;
  10905. until I >= R;
  10906. end;
  10907. var I : Integer;
  10908. begin
  10909. Assert(Length(Key) = Length(Data));
  10910. I := Length(Key);
  10911. if I > 0 then
  10912. QuickSort(0, I - 1);
  10913. end;
  10914. {$ELSE}
  10915. procedure DynArraySort(const Key: ExtendedArray; const Data: Int64Array);
  10916. procedure QuickSort(L, R: Integer);
  10917. var I, J, M : Integer;
  10918. W, T : Extended;
  10919. P, Q : PExtended;
  10920. A : Int64;
  10921. begin
  10922. repeat
  10923. I := L;
  10924. P := @Key[I];
  10925. J := R;
  10926. Q := @Key[J];
  10927. M := (L + R) shr 1;
  10928. W := Key[M];
  10929. repeat
  10930. while P^ < W do
  10931. begin
  10932. Inc(P);
  10933. Inc(I);
  10934. end;
  10935. while Q^ > W do
  10936. begin
  10937. Dec(Q);
  10938. Dec(J);
  10939. end;
  10940. if I <= J then
  10941. begin
  10942. T := P^;
  10943. P^ := Q^;
  10944. Q^ := T;
  10945. A := Data[I];
  10946. Data[I] := Data[J];
  10947. Data[J] := A;
  10948. if M = I then
  10949. begin
  10950. M := J;
  10951. W := Q^;
  10952. end else
  10953. if M = J then
  10954. begin
  10955. M := I;
  10956. W := P^;
  10957. end;
  10958. Inc(P);
  10959. Inc(I);
  10960. Dec(Q);
  10961. Dec(J);
  10962. end;
  10963. until I > J;
  10964. if L < J then
  10965. QuickSort(L, J);
  10966. L := I;
  10967. until I >= R;
  10968. end;
  10969. var I : Integer;
  10970. begin
  10971. Assert(Length(Key) = Length(Data));
  10972. I := Length(Key);
  10973. if I > 0 then
  10974. QuickSort(0, I - 1);
  10975. end;
  10976. {$ENDIF}
  10977. {$IFDEF ManagedCode}
  10978. procedure DynArraySort(const Key: ExtendedArray; const Data: AnsiStringArray);
  10979. procedure QuickSort(L, R: Integer);
  10980. var I, J, M : Integer;
  10981. W, T : Extended;
  10982. A : AnsiString;
  10983. begin
  10984. repeat
  10985. I := L;
  10986. J := R;
  10987. M := (L + R) shr 1;
  10988. W := Key[M];
  10989. repeat
  10990. while Key[I] < W do
  10991. Inc(I);
  10992. while Key[J] > W do
  10993. Dec(J);
  10994. if I <= J then
  10995. begin
  10996. T := Key[I];
  10997. Key[I] := Key[J];
  10998. Key[J] := T;
  10999. A := Data[I];
  11000. Data[I] := Data[J];
  11001. Data[J] := A;
  11002. if M = I then
  11003. begin
  11004. M := J;
  11005. W := Key[J];
  11006. end else
  11007. if M = J then
  11008. begin
  11009. M := I;
  11010. W := Key[I];
  11011. end;
  11012. Inc(I);
  11013. Dec(J);
  11014. end;
  11015. until I > J;
  11016. if L < J then
  11017. QuickSort(L, J);
  11018. L := I;
  11019. until I >= R;
  11020. end;
  11021. var I : Integer;
  11022. begin
  11023. Assert(Length(Key) = Length(Data));
  11024. I := Length(Key);
  11025. if I > 0 then
  11026. QuickSort(0, I - 1);
  11027. end;
  11028. {$ELSE}
  11029. procedure DynArraySort(const Key: ExtendedArray; const Data: AnsiStringArray);
  11030. procedure QuickSort(L, R: Integer);
  11031. var I, J, M : Integer;
  11032. W, T : Extended;
  11033. P, Q : PExtended;
  11034. A : AnsiString;
  11035. begin
  11036. repeat
  11037. I := L;
  11038. P := @Key[I];
  11039. J := R;
  11040. Q := @Key[J];
  11041. M := (L + R) shr 1;
  11042. W := Key[M];
  11043. repeat
  11044. while P^ < W do
  11045. begin
  11046. Inc(P);
  11047. Inc(I);
  11048. end;
  11049. while Q^ > W do
  11050. begin
  11051. Dec(Q);
  11052. Dec(J);
  11053. end;
  11054. if I <= J then
  11055. begin
  11056. T := P^;
  11057. P^ := Q^;
  11058. Q^ := T;
  11059. A := Data[I];
  11060. Data[I] := Data[J];
  11061. Data[J] := A;
  11062. if M = I then
  11063. begin
  11064. M := J;
  11065. W := Q^;
  11066. end else
  11067. if M = J then
  11068. begin
  11069. M := I;
  11070. W := P^;
  11071. end;
  11072. Inc(P);
  11073. Inc(I);
  11074. Dec(Q);
  11075. Dec(J);
  11076. end;
  11077. until I > J;
  11078. if L < J then
  11079. QuickSort(L, J);
  11080. L := I;
  11081. until I >= R;
  11082. end;
  11083. var I : Integer;
  11084. begin
  11085. Assert(Length(Key) = Length(Data));
  11086. I := Length(Key);
  11087. if I > 0 then
  11088. QuickSort(0, I - 1);
  11089. end;
  11090. {$ENDIF}
  11091. {$IFDEF ManagedCode}
  11092. procedure DynArraySort(const Key: ExtendedArray; const Data: ExtendedArray);
  11093. procedure QuickSort(L, R: Integer);
  11094. var I, J, M : Integer;
  11095. W, T : Extended;
  11096. A : Extended;
  11097. begin
  11098. repeat
  11099. I := L;
  11100. J := R;
  11101. M := (L + R) shr 1;
  11102. W := Key[M];
  11103. repeat
  11104. while Key[I] < W do
  11105. Inc(I);
  11106. while Key[J] > W do
  11107. Dec(J);
  11108. if I <= J then
  11109. begin
  11110. T := Key[I];
  11111. Key[I] := Key[J];
  11112. Key[J] := T;
  11113. A := Data[I];
  11114. Data[I] := Data[J];
  11115. Data[J] := A;
  11116. if M = I then
  11117. begin
  11118. M := J;
  11119. W := Key[J];
  11120. end else
  11121. if M = J then
  11122. begin
  11123. M := I;
  11124. W := Key[I];
  11125. end;
  11126. Inc(I);
  11127. Dec(J);
  11128. end;
  11129. until I > J;
  11130. if L < J then
  11131. QuickSort(L, J);
  11132. L := I;
  11133. until I >= R;
  11134. end;
  11135. var I : Integer;
  11136. begin
  11137. Assert(Length(Key) = Length(Data));
  11138. I := Length(Key);
  11139. if I > 0 then
  11140. QuickSort(0, I - 1);
  11141. end;
  11142. {$ELSE}
  11143. procedure DynArraySort(const Key: ExtendedArray; const Data: ExtendedArray);
  11144. procedure QuickSort(L, R: Integer);
  11145. var I, J, M : Integer;
  11146. W, T : Extended;
  11147. P, Q : PExtended;
  11148. A : Extended;
  11149. begin
  11150. repeat
  11151. I := L;
  11152. P := @Key[I];
  11153. J := R;
  11154. Q := @Key[J];
  11155. M := (L + R) shr 1;
  11156. W := Key[M];
  11157. repeat
  11158. while P^ < W do
  11159. begin
  11160. Inc(P);
  11161. Inc(I);
  11162. end;
  11163. while Q^ > W do
  11164. begin
  11165. Dec(Q);
  11166. Dec(J);
  11167. end;
  11168. if I <= J then
  11169. begin
  11170. T := P^;
  11171. P^ := Q^;
  11172. Q^ := T;
  11173. A := Data[I];
  11174. Data[I] := Data[J];
  11175. Data[J] := A;
  11176. if M = I then
  11177. begin
  11178. M := J;
  11179. W := Q^;
  11180. end else
  11181. if M = J then
  11182. begin
  11183. M := I;
  11184. W := P^;
  11185. end;
  11186. Inc(P);
  11187. Inc(I);
  11188. Dec(Q);
  11189. Dec(J);
  11190. end;
  11191. until I > J;
  11192. if L < J then
  11193. QuickSort(L, J);
  11194. L := I;
  11195. until I >= R;
  11196. end;
  11197. var I : Integer;
  11198. begin
  11199. Assert(Length(Key) = Length(Data));
  11200. I := Length(Key);
  11201. if I > 0 then
  11202. QuickSort(0, I - 1);
  11203. end;
  11204. {$ENDIF}
  11205. {$IFNDEF ManagedCode}
  11206. {$IFDEF ManagedCode}
  11207. procedure DynArraySort(const Key: ExtendedArray; const Data: PointerArray);
  11208. procedure QuickSort(L, R: Integer);
  11209. var I, J, M : Integer;
  11210. W, T : Extended;
  11211. A : Pointer;
  11212. begin
  11213. repeat
  11214. I := L;
  11215. J := R;
  11216. M := (L + R) shr 1;
  11217. W := Key[M];
  11218. repeat
  11219. while Key[I] < W do
  11220. Inc(I);
  11221. while Key[J] > W do
  11222. Dec(J);
  11223. if I <= J then
  11224. begin
  11225. T := Key[I];
  11226. Key[I] := Key[J];
  11227. Key[J] := T;
  11228. A := Data[I];
  11229. Data[I] := Data[J];
  11230. Data[J] := A;
  11231. if M = I then
  11232. begin
  11233. M := J;
  11234. W := Key[J];
  11235. end else
  11236. if M = J then
  11237. begin
  11238. M := I;
  11239. W := Key[I];
  11240. end;
  11241. Inc(I);
  11242. Dec(J);
  11243. end;
  11244. until I > J;
  11245. if L < J then
  11246. QuickSort(L, J);
  11247. L := I;
  11248. until I >= R;
  11249. end;
  11250. var I : Integer;
  11251. begin
  11252. Assert(Length(Key) = Length(Data));
  11253. I := Length(Key);
  11254. if I > 0 then
  11255. QuickSort(0, I - 1);
  11256. end;
  11257. {$ELSE}
  11258. procedure DynArraySort(const Key: ExtendedArray; const Data: PointerArray);
  11259. procedure QuickSort(L, R: Integer);
  11260. var I, J, M : Integer;
  11261. W, T : Extended;
  11262. P, Q : PExtended;
  11263. A : Pointer;
  11264. begin
  11265. repeat
  11266. I := L;
  11267. P := @Key[I];
  11268. J := R;
  11269. Q := @Key[J];
  11270. M := (L + R) shr 1;
  11271. W := Key[M];
  11272. repeat
  11273. while P^ < W do
  11274. begin
  11275. Inc(P);
  11276. Inc(I);
  11277. end;
  11278. while Q^ > W do
  11279. begin
  11280. Dec(Q);
  11281. Dec(J);
  11282. end;
  11283. if I <= J then
  11284. begin
  11285. T := P^;
  11286. P^ := Q^;
  11287. Q^ := T;
  11288. A := Data[I];
  11289. Data[I] := Data[J];
  11290. Data[J] := A;
  11291. if M = I then
  11292. begin
  11293. M := J;
  11294. W := Q^;
  11295. end else
  11296. if M = J then
  11297. begin
  11298. M := I;
  11299. W := P^;
  11300. end;
  11301. Inc(P);
  11302. Inc(I);
  11303. Dec(Q);
  11304. Dec(J);
  11305. end;
  11306. until I > J;
  11307. if L < J then
  11308. QuickSort(L, J);
  11309. L := I;
  11310. until I >= R;
  11311. end;
  11312. var I : Integer;
  11313. begin
  11314. Assert(Length(Key) = Length(Data));
  11315. I := Length(Key);
  11316. if I > 0 then
  11317. QuickSort(0, I - 1);
  11318. end;
  11319. {$ENDIF}
  11320. {$ENDIF}
  11321. {$IFNDEF CLR}
  11322. { }
  11323. { Generic quick sort algorithm }
  11324. { }
  11325. procedure GenericQuickSort(const Data: Pointer; const Count: Integer;
  11326. const CompareFunc: TQuickSortCompareFunction;
  11327. const SwapFunc: TQuickSortSwapFunction);
  11328. procedure QuickSort(L, R: Integer);
  11329. var I, J, M : Integer;
  11330. begin
  11331. repeat
  11332. I := L;
  11333. J := R;
  11334. M := (L + R) shr 1;
  11335. repeat
  11336. while CompareFunc(Data, I, M) = crLess do
  11337. Inc(I);
  11338. while CompareFunc(Data, J, M) = crGreater do
  11339. Dec(J);
  11340. if I <= J then
  11341. begin
  11342. SwapFunc(Data, I, J);
  11343. if M = I then
  11344. M := J
  11345. else
  11346. if M = J then
  11347. M := I;
  11348. Inc(I);
  11349. Dec(J);
  11350. end;
  11351. until I > J;
  11352. if L < J then
  11353. QuickSort(L, J);
  11354. L := I;
  11355. until I >= R;
  11356. end;
  11357. begin
  11358. if Count > 0 then
  11359. QuickSort(0, Count - 1);
  11360. end;
  11361. { }
  11362. { Generic binary search algorithm }
  11363. { }
  11364. function GenericBinarySearch(const Data: Pointer; const Count: Integer;
  11365. const Item: Pointer;
  11366. const CompareFunc: TBinarySearchCompareFunction): Integer;
  11367. var L, H, I : Integer;
  11368. begin
  11369. L := 0;
  11370. H := Count - 1;
  11371. while L <= H do
  11372. begin
  11373. I := (L + H) div 2;
  11374. case CompareFunc(Data, I, Item) of
  11375. crEqual :
  11376. begin
  11377. while (I > 0) and (CompareFunc(Data, I - 1, Item) = crEqual) do
  11378. Dec(I);
  11379. Result := I;
  11380. exit;
  11381. end;
  11382. crGreater : H := I - 1;
  11383. crLess : L := I + 1;
  11384. end;
  11385. end;
  11386. Result := -1;
  11387. end;
  11388. {$ENDIF}
  11389. { }
  11390. { Test cases }
  11391. { }
  11392. {$IFDEF DYNARRAYS_SELFTEST}
  11393. {$ASSERTIONS ON}
  11394. procedure Test_IntegerArray;
  11395. var S, T : IntegerArray;
  11396. F : Integer;
  11397. begin
  11398. S := nil;
  11399. for F := 1 to 100 do
  11400. begin
  11401. DynArrayAppend(S, F);
  11402. Assert(Length(S) = F, 'Append');
  11403. Assert(S[F - 1] = F, 'Append');
  11404. end;
  11405. T := Copy(S);
  11406. DynArrayAppendIntegerArray(S, T);
  11407. for F := 1 to 100 do
  11408. Assert(S[F + 99] = F, 'Append');
  11409. Assert(DynArrayPosNext(60, S) = 59, 'PosNext');
  11410. Assert(DynArrayPosNext(60, T) = 59, 'PosNext');
  11411. Assert(DynArrayPosNext(60, S, 59) = 159, 'PosNext');
  11412. Assert(DynArrayPosNext(60, T, 59) = -1, 'PosNext');
  11413. Assert(DynArrayPosNext(60, T, -1, True) = 59, 'PosNext');
  11414. Assert(DynArrayPosNext(60, T, 59, True) = -1, 'PosNext');
  11415. for F := 1 to 100 do
  11416. begin
  11417. DynArrayRemove(S, DynArrayPosNext(F, S), 1);
  11418. Assert(Length(S) = 200 - F, 'Remove');
  11419. end;
  11420. for F := 99 downto 0 do
  11421. begin
  11422. DynArrayRemove(S, DynArrayPosNext(F xor 3 + 1, S), 1);
  11423. Assert(Length(S) = F, 'Remove');
  11424. end;
  11425. S := AsIntegerArray([3, 1, 2, 5, 4]);
  11426. DynArraySort(S);
  11427. Assert(S[0] = 1, 'Sort');
  11428. Assert(S[1] = 2, 'Sort');
  11429. Assert(S[2] = 3, 'Sort');
  11430. Assert(S[3] = 4, 'Sort');
  11431. Assert(S[4] = 5, 'Sort');
  11432. S := AsIntegerArray([3, 5, 5, 2, 5, 5, 1]);
  11433. DynArraySort(S);
  11434. Assert(S[0] = 1, 'Sort');
  11435. Assert(S[1] = 2, 'Sort');
  11436. Assert(S[2] = 3, 'Sort');
  11437. Assert(S[3] = 5, 'Sort');
  11438. Assert(S[4] = 5, 'Sort');
  11439. Assert(S[5] = 5, 'Sort');
  11440. Assert(S[6] = 5, 'Sort');
  11441. SetLength(S, 1000);
  11442. for F := 0 to 999 do
  11443. S[F] := F mod 5;
  11444. DynArraySort(S);
  11445. for F := 0 to 999 do
  11446. Assert(S[F] = F div 200, 'Sort');
  11447. S := AsIntegerArray([6, 3, 5, 1]);
  11448. T := AsIntegerArray([1, 2, 3, 4]);
  11449. DynArraySort(S, T);
  11450. Assert(S[0] = 1, 'Sort');
  11451. Assert(S[1] = 3, 'Sort');
  11452. Assert(S[2] = 5, 'Sort');
  11453. Assert(S[3] = 6, 'Sort');
  11454. Assert(T[0] = 4, 'Sort');
  11455. Assert(T[1] = 2, 'Sort');
  11456. Assert(T[2] = 3, 'Sort');
  11457. Assert(T[3] = 1, 'Sort');
  11458. end;
  11459. procedure Test_ObjectArray;
  11460. var S, T : ObjectArray;
  11461. F : Integer;
  11462. V : TObject;
  11463. begin
  11464. S := nil;
  11465. V := TObject.Create;
  11466. try
  11467. for F := 1 to 100 do
  11468. begin
  11469. DynArrayAppend(S, V);
  11470. Assert(Length(S) = F, 'Append');
  11471. Assert(S[F - 1] = V, 'Append');
  11472. end;
  11473. T := Copy(S);
  11474. for F := 1 to 10 do
  11475. begin
  11476. DynArrayRemove(S, F - 1, 1, False);
  11477. Assert(Length(S) = 100 - F, 'Remove');
  11478. end;
  11479. DynArrayRemove(S, 89, 1, False);
  11480. Assert(Length(S) = 89, 'Remove');
  11481. DynArrayRemove(S, 87, 1, False);
  11482. Assert(Length(S) = 88, 'Remove');
  11483. DynArrayAppendObjectArray(S, T);
  11484. Assert(Length(S) = 188, 'AppendObjectArray');
  11485. DynArrayRemove(S, 10, 88, False);
  11486. Assert(Length(S) = 100, 'Remove');
  11487. DynArrayRemove(S, 0, 100, False);
  11488. Assert(Length(S) = 0, 'Remove');
  11489. finally
  11490. V.Free;
  11491. end;
  11492. end;
  11493. procedure Test_StringArray;
  11494. var S, T : StringArray;
  11495. U : String;
  11496. F : Integer;
  11497. begin
  11498. S := nil;
  11499. for F := 1 to 100 do
  11500. begin
  11501. U := IntToStr(F);
  11502. DynArrayAppend(S, U);
  11503. Assert(Length(S) = F, 'Append');
  11504. Assert(S[F - 1] = U, 'Append');
  11505. end;
  11506. T := Copy(S);
  11507. DynArrayAppendStringArray(S, T);
  11508. for F := 1 to 100 do
  11509. Assert(S[F + 99] = IntToStr(F), 'Append');
  11510. Assert(DynArrayPosNext('60', S) = 59, 'PosNext');
  11511. Assert(DynArrayPosNext('60', T) = 59, 'PosNext');
  11512. Assert(DynArrayPosNext('60', S, 59) = 159, 'PosNext');
  11513. Assert(DynArrayPosNext('60', T, 59) = -1, 'PosNext');
  11514. Assert(DynArrayPosNext('60', T, -1, True) = 59, 'PosNext');
  11515. Assert(DynArrayPosNext('60', T, 59, True) = -1, 'PosNext');
  11516. for F := 1 to 100 do
  11517. begin
  11518. DynArrayRemove(S, DynArrayPosNext(IntToStr(F), S), 1);
  11519. Assert(Length(S) = 200 - F, 'Remove');
  11520. end;
  11521. for F := 99 downto 0 do
  11522. begin
  11523. DynArrayRemove(S, DynArrayPosNext(IntToStr(F xor 3 + 1), S), 1);
  11524. Assert(Length(S) = F, 'Remove');
  11525. end;
  11526. S := AsStringArray(['3', '1', '2', '5', '4']);
  11527. DynArraySort(S);
  11528. Assert(S[0] = '1', 'Sort');
  11529. Assert(S[1] = '2', 'Sort');
  11530. Assert(S[2] = '3', 'Sort');
  11531. Assert(S[3] = '4', 'Sort');
  11532. Assert(S[4] = '5', 'Sort');
  11533. S := AsStringArray(['3', '5', '5', '2', '5', '5', '1']);
  11534. DynArraySort(S);
  11535. Assert(S[0] = '1', 'Sort');
  11536. Assert(S[1] = '2', 'Sort');
  11537. Assert(S[2] = '3', 'Sort');
  11538. Assert(S[3] = '5', 'Sort');
  11539. Assert(S[4] = '5', 'Sort');
  11540. Assert(S[5] = '5', 'Sort');
  11541. Assert(S[6] = '5', 'Sort');
  11542. SetLength(S, 1000);
  11543. for F := 0 to 999 do
  11544. S[F] := IntToStr(F mod 5);
  11545. DynArraySort(S);
  11546. for F := 0 to 999 do
  11547. Assert(S[F] = IntToStr(F div 200), 'Sort');
  11548. end;
  11549. procedure SelfTest;
  11550. begin
  11551. Test_IntegerArray;
  11552. Test_ObjectArray;
  11553. Test_StringArray;
  11554. end;
  11555. {$ENDIF}
  11556. end.