sysutils.tex 199 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1999, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The SYSUTILS unit.}
  22. This chapter describes the \file{sysutils} unit. The \var{sysutils} unit
  23. was largely written by Gertjan Schouten, and completed by michael Van Canneyt.
  24. It aims to be compatible to the Delphi sysutils unit, but in contrast with
  25. the latter, it is designed to work on multiple platforms.
  26. This chapter starts out with a definition of all types and constants
  27. that are defined, followed by a complete explanation of each function.
  28. \section{Constants and types}
  29. The following general-purpose constants are defined:
  30. \begin{verbatim}
  31. const
  32. SecsPerDay = 24 * 60 * 60; // Seconds and milliseconds per day
  33. MSecsPerDay = SecsPerDay * 1000;
  34. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  35. Eoln = #10;
  36. \end{verbatim}
  37. The following types are used frequently in date and time functions.
  38. They are the same on all platforms.
  39. \begin{verbatim}
  40. type
  41. TSystemTime = record
  42. Year, Month, Day: word;
  43. Hour, Minute, Second, MilliSecond: word;
  44. end ;
  45. TDateTime = double;
  46. TTimeStamp = record
  47. Time: integer; { Number of milliseconds since midnight }
  48. Date: integer; { One plus number of days since 1/1/0001 }
  49. end ;
  50. \end{verbatim}
  51. The following type is used in the \seef{FindFirst},\seef{FindNext}
  52. and \seepl{FindClose}{FindCloseSys} functions. The \var{win32} version differs from
  53. the other versions. If code is to be portable, that part shouldn't
  54. be used.
  55. \begin{verbatim}
  56. Type
  57. THandle = Longint;
  58. TSearchRec = Record
  59. Time,Size, Attr : Longint;
  60. Name : TFileName;
  61. ExcludeAttr : Longint;
  62. FindHandle : THandle;
  63. {$ifdef Win32}
  64. FindData : TWin32FindData;
  65. {$endif}
  66. end;
  67. \end{verbatim}
  68. The following constants are file-attributes that need to be matched in the
  69. findfirst call.
  70. \begin{verbatim}
  71. Const
  72. faReadOnly = $00000001;
  73. faHidden = $00000002;
  74. faSysFile = $00000004;
  75. faVolumeId = $00000008;
  76. faDirectory = $00000010;
  77. faArchive = $00000020;
  78. faAnyFile = $0000003f;
  79. \end{verbatim}
  80. The following constants can be used in the \seef{FileOpen} call.
  81. \begin{verbatim}
  82. Const
  83. fmOpenRead = $0000;
  84. fmOpenWrite = $0001;
  85. fmOpenReadWrite = $0002;
  86. \end{verbatim}
  87. The following constants can be used in the \seef{FileSeek} call.
  88. \begin{verbatim}
  89. Const
  90. fsFromBeginning = 0;
  91. fsFromCurrent = 1;
  92. fsFromEnd = 2;
  93. \end{verbatim}
  94. The following variables are used in the case translation routines.
  95. \begin{verbatim}
  96. type
  97. TCaseTranslationTable = array[0..255] of char;
  98. var
  99. UpperCaseTable: TCaseTranslationTable;
  100. LowerCaseTable: TCaseTranslationTable;
  101. \end{verbatim}
  102. The initialization code of the \file{sysutils} unit fills these
  103. tables with the appropriate values. For the win32 and go32v2
  104. versions, this information is obtained from the operating system.
  105. The following constants control the formatting of dates.
  106. For the Win32 version of the \file{sysutils} unit, these
  107. constants are set according to the internationalization
  108. settings of Windows by the initialization code of the unit.
  109. \begin{verbatim}
  110. Const
  111. DateSeparator: char = '-';
  112. ShortDateFormat: string = 'd/m/y';
  113. LongDateFormat: string = 'dd" "mmmm" "yyyy';
  114. ShortMonthNames: array[1..12] of string[128] =
  115. ('Jan','Feb','Mar','Apr','May','Jun',
  116. 'Jul','Aug','Sep','Oct','Nov','Dec');
  117. LongMonthNames: array[1..12] of string[128] =
  118. ('January','February','March','April',
  119. 'May','June','July','August',
  120. 'September','October','November','December');
  121. ShortDayNames: array[1..7] of string[128] =
  122. ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  123. LongDayNames: array[1..7] of string[128] =
  124. ('Sunday','Monday','Tuesday','Wednesday',
  125. 'Thursday','Friday','Saturday');
  126. \end{verbatim}
  127. The following constants control the formatting of times.
  128. For the Win32 version of the \file{sysutils} unit, these
  129. constants are set according to the internationalization
  130. settings of Windows by the initialization code of the unit.
  131. \begin{verbatim}
  132. Const
  133. ShortTimeFormat: string = 'hh:nn';
  134. LongTimeFormat: string = 'hh:nn:ss';
  135. TimeSeparator: char = ':';
  136. TimeAMString: string[7] = 'AM';
  137. TimePMString: string[7] = 'PM';
  138. \end{verbatim}
  139. The following constants control the formatting of currencies
  140. and numbers. For the Win32 version of the \file{sysutils} unit,
  141. these constants are set according to the internationalization
  142. settings of Windows by the initialization code of the unit.
  143. \begin{verbatim}
  144. Const
  145. DecimalSeparator : Char = '.';
  146. ThousandSeparator : Char = ',';
  147. CurrencyDecimals : Byte = 2;
  148. CurrencyString : String[7] = '$';
  149. { Format to use when formatting currency :
  150. 0 = $1 1 = 1$ 2 = $ 1 3 = 1 $
  151. 4 = Currency string replaces decimal indicator.
  152. e.g. 1$50
  153. }
  154. CurrencyFormat : Byte = 1;
  155. { Same as above, only for negative currencies:
  156. 0 = ($1)
  157. 1 = -$1
  158. 2 = $-1
  159. 3 = $1-
  160. 4 = (1$)
  161. 5 = -1$
  162. 6 = 1-$
  163. 7 = 1$-
  164. 8 = -1 $
  165. 9 = -$ 1
  166. 10 = $ 1-
  167. }
  168. NegCurrFormat : Byte = 5;
  169. \end{verbatim}
  170. The following types are used in various string functions.
  171. \begin{verbatim}
  172. type
  173. PString = ^String;
  174. TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  175. \end{verbatim}
  176. The following constants are used in the file name handling routines. Do not
  177. use a slash of backslash character directly as a path separator; instead
  178. use the \var{OsDirSeparator} character.
  179. \begin{verbatim}
  180. Const
  181. DirSeparators : set of char = ['/','\'];
  182. {$ifdef Linux}
  183. OSDirSeparator = '/';
  184. {$else}
  185. OsDirSeparator = '\';
  186. {$endif}
  187. \end{verbatim}
  188. \section{Date and time functions}
  189. \subsection{Date and time formatting characters}
  190. \label{se:formatchars}
  191. Various date and time formatting routines accept a format string.
  192. to format the date and or time. The following characters can be used
  193. to control the date and time formatting:
  194. \begin{description}
  195. \item[c] : shortdateformat + ' ' + shorttimeformat
  196. \item[d] : day of month
  197. \item[dd] : day of month (leading zero)
  198. \item[ddd] : day of week (abbreviation)
  199. \item[dddd] : day of week (full)
  200. \item[ddddd] : shortdateformat
  201. \item[dddddd] : longdateformat
  202. \item[m] : month
  203. \item[mm] : month (leading zero)
  204. \item[mmm] : month (abbreviation)
  205. \item[mmmm] : month (full)
  206. \item[y] : year (four digits)
  207. \item[yy] : year (two digits)
  208. \item[yyyy] : year (with century)
  209. \item[h] : hour
  210. \item[hh] : hour (leading zero)
  211. \item[n] : minute
  212. \item[nn] : minute (leading zero)
  213. \item[s] : second
  214. \item[ss] : second (leading zero)
  215. \item[t] : shorttimeformat
  216. \item[tt] : longtimeformat
  217. \item[am/pm] : use 12 hour clock and display am and pm accordingly
  218. \item[a/p] : use 12 hour clock and display a and p accordingly
  219. \item[/] : insert date seperator
  220. \item[:] : insert time seperator
  221. \item["xx"] : literal text
  222. \item['xx'] : literal text
  223. \end{description}
  224. \begin{type}{TDateTime}
  225. \Declaration
  226. TDateTime = Double;
  227. \Description
  228. Many functions return or require a \var{TDateTime} type, which contains
  229. a date and time in encoded form. The date and time are converted to a double
  230. as follows:
  231. \end{type}
  232. \begin{function}{Date}
  233. \Declaration
  234. Function Date: TDateTime;
  235. \Description
  236. \var{Date} returns the current date in \var{TDateTime} format.
  237. For more information about the \var{TDateTime} type, see \seety{TDateTime}.
  238. \Errors
  239. None.
  240. \SeeAlso
  241. \seef{Time},\seef{Now}, \seety{TDateTime}.
  242. \end{function}
  243. \latex{\inputlisting{sysutex/ex1.pp}}
  244. \html{\input{sysutex/ex1.tex}}
  245. \begin{function}{DateTimeToFileDate}
  246. \Declaration
  247. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  248. \Description
  249. \var{DateTimeToFileDate} function converts a date/time indication in
  250. \var{TDateTime} format to a filedate function, such as returned for
  251. instance by the \seef{FileAge} function.
  252. \Errors
  253. None.
  254. \SeeAlso
  255. \seef{Time}, \seef{Date}, \seef{FileDateToDateTime},
  256. \seep{DateTimeToSystemTime}, \seef{DateTimeToTimeStamp}
  257. \end{function}
  258. \latex{\inputlisting{sysutex/ex2.pp}}
  259. \html{\input{sysutex/ex2.tex}}
  260. \begin{function}{DateTimeToStr}
  261. \Declaration
  262. Function DateTimeToStr(DateTime: TDateTime): string;
  263. \Description
  264. \var{DateTimeToStr} returns a string representation of
  265. \var{DateTime} using the formatting specified in
  266. \var{ShortDateTimeFormat}. It corresponds to a call to
  267. \var{FormatDateTime('c',DateTime)} (see \sees{formatchars}).
  268. \Errors
  269. None.
  270. \SeeAlso
  271. \seef{FormatDateTime}, \seety{TDateTime}.
  272. \end{function}
  273. \latex{\inputlisting{sysutex/ex3.pp}}
  274. \html{\input{sysutex/ex3.tex}}
  275. \begin{procedure}{DateTimeToString}
  276. \Declaration
  277. Procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  278. \Description
  279. \var{DateTimeToString} returns in \var{Result} a string representation of
  280. \var{DateTime} using the formatting specified in \var{FormatStr}.
  281. for a list of characters that can be used in the \var{FormatStr} formatting
  282. string, see \sees{formatchars}.
  283. \Errors
  284. In case a wrong formatting character is found, an \var{EConvertError} is
  285. raised.
  286. \SeeAlso
  287. \seef{FormatDateTime}, \sees{formatchars}.
  288. \end{procedure}
  289. \latex{\inputlisting{sysutex/ex4.pp}}
  290. \html{\input{sysutex/ex4.tex}}
  291. \begin{procedure}{DateTimeToSystemTime}
  292. \Declaration
  293. Procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  294. \Description
  295. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  296. \var{TDateTime} format to a system time \var{SystemTime}.
  297. \Errors
  298. None.
  299. \SeeAlso
  300. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  301. \seef{DateTimeToTimeStamp}
  302. \end{procedure}
  303. \latex{\inputlisting{sysutex/ex5.pp}}
  304. \html{\input{sysutex/ex5.tex}}
  305. \begin{function}{DateTimeToTimeStamp}
  306. \Declaration
  307. Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  308. \Description
  309. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  310. \var{TDateTime} format to a \var{TTimeStamp} format.
  311. \Errors
  312. None.
  313. \SeeAlso
  314. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  315. \seep{DateTimeToSystemTime}
  316. \end{function}
  317. \latex{\inputlisting{sysutex/ex6.pp}}
  318. \html{\input{sysutex/ex6.tex}}
  319. \begin{function}{DateToStr}
  320. \Declaration
  321. Function DateToStr(Date: TDateTime): string;
  322. \Description
  323. \var{DateToStr} converts \var{Date} to a string representation. It uses
  324. \var{ShortDateFormat} as it's formatting string. It is hence completely
  325. equivalent to a \var{FormatDateTime('ddddd', Date)}.
  326. \Errors
  327. None.
  328. \SeeAlso
  329. \seef{TimeToStr}, \seef{DateTimeToStr}, \seef{FormatDateTime},
  330. \seef{StrToDate}
  331. \end{function}
  332. \latex{\inputlisting{sysutex/ex7.pp}}
  333. \html{\input{sysutex/ex7.tex}}
  334. \begin{function}{DayOfWeek}
  335. \Declaration
  336. Function DayOfWeek(DateTime: TDateTime): integer;
  337. \Description
  338. \var{DayOfWeek} returns the day of the week from \var{DateTime}.
  339. \var{Sunday} is counted as day 1, \var{Saturday} is counted as
  340. day 7. The result of \var{DayOfWeek} can serve as an index to
  341. the \var{LongDayNames} constant array, to retrieve the name of
  342. the day.
  343. \Errors
  344. None.
  345. \SeeAlso
  346. \seef{Date}, \seef{DateToStr}
  347. \end{function}
  348. \latex{\inputlisting{sysutex/ex8.pp}}
  349. \html{\input{sysutex/ex8.tex}}
  350. \begin{procedure}{DecodeDate}
  351. \Declaration
  352. Procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  353. \Description
  354. \var{DecodeDate} decodes the Year, Month and Day stored in \var{Date},
  355. and returns them in the \var{Year}, \var{Month} and \var{Day} variables.
  356. \Errors
  357. None.
  358. \SeeAlso
  359. \seef{EncodeDate}, \seep{DecodeTime}.
  360. \end{procedure}
  361. \latex{\inputlisting{sysutex/ex9.pp}}
  362. \html{\input{sysutex/ex9.tex}}
  363. \begin{procedure}{DecodeTime}
  364. \Declaration
  365. Procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  366. \Description
  367. \var{DecodeDate} decodes the hours, minutes, second and milliseconds stored
  368. in \var{Time}, and returns them in the \var{Hour}, \var{Minute} and
  369. \var{Second} and \var{MilliSecond} variables.
  370. \Errors
  371. None.
  372. \SeeAlso
  373. \seef{EncodeTime}, \seep{DecodeDate}.
  374. \end{procedure}
  375. \latex{\inputlisting{sysutex/ex10.pp}}
  376. \html{\input{sysutex/ex10.tex}}
  377. \begin{function}{EncodeDate}
  378. \Declaration
  379. Function EncodeDate(Year, Month, Day :word): TDateTime;
  380. \Description
  381. \var{EncodeDate} encodes the \var{Year}, \var{Month} and \var{Day} variables to
  382. a date in \var{TDateTime} format. It does the opposite of the
  383. \seep{DecodeDate} procedure.
  384. The parameters must lie withing valid ranges (boundaries included):
  385. \begin{description}
  386. \item[Year] must be between 1 and 9999.
  387. \item[Month] must be within the range 1-12.
  388. \item[Day] msut be between 1 and 31.
  389. \end{description}
  390. \Errors
  391. In case one of the parameters is out of it's valid range, 0 is returned.
  392. \SeeAlso
  393. \seef{EncodeTime}, \seep{DecodeDate}.
  394. \end{function}
  395. \latex{\inputlisting{sysutex/ex11.pp}}
  396. \html{\input{sysutex/ex11.tex}}
  397. \begin{function}{EncodeTime}
  398. \Declaration
  399. Function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  400. \Description
  401. \var{EncodeTime} encodes the \var{Hour}, \var{Minute}, \var{Second},
  402. \var{MilliSecond} variables to a \var{TDateTime} format result.
  403. It does the opposite of the \seep{DecodeTime} procedure.
  404. The parameters must have a valid range (boundaries included):
  405. \begin{description}
  406. \item[Hour] must be between 0 and 23.
  407. \item[Minute,second] must both be between 0 and 59.
  408. \item[Millisecond] must be between 0 and 999.
  409. \end{description}
  410. \Errors
  411. In case one of the parameters is outside of it's valid range, 0 is returned.
  412. \SeeAlso
  413. \seef{EncodeDate}, \seep{DecodeTime}.
  414. \end{function}
  415. \latex{\inputlisting{sysutex/ex12.pp}}
  416. \html{\input{sysutex/ex12.tex}}
  417. \begin{function}{FileDateToDateTime}
  418. \Declaration
  419. Function FileDateToDateTime(Filedate : Longint) : TDateTime;
  420. \Description
  421. \var{FileDateToDateTime} converts the date/time encoded in \var{filedate}
  422. to a \var{TDateTime} encoded form. It can be used to convert date/time values
  423. returned by the \seef{FileAge} or \seef{FindFirst}/\seef{FindNext}
  424. functions to \var{TDateTime} form.
  425. \Errors
  426. None.
  427. \SeeAlso
  428. \seef{DateTimeToFileDate}
  429. \end{function}
  430. \latex{\inputlisting{sysutex/ex13.pp}}
  431. \html{\input{sysutex/ex13.tex}}
  432. \begin{function}{FormatDateTime}
  433. \Declaration
  434. Function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  435. \Description
  436. \var{FormatDateTime} formats the date and time encoded in \var{DateTime}
  437. according to the formatting given in \var{FormatStr}. The complete list
  438. of formatting characters can be found in \sees{formatchars}.
  439. \Errors
  440. On error (such as an invalid character in the formatting string), and
  441. \var{EConvertError} exception is raised.
  442. \SeeAlso
  443. \seef{DateTimeToStr}, \seef{DateToStr}, \seef{TimeToStr},
  444. \seef{StrToDateTime}
  445. \end{function}
  446. \latex{\inputlisting{sysutex/ex14.pp}}
  447. \html{\input{sysutex/ex14.tex}}
  448. \begin{function}{IncMonth}
  449. \Declaration
  450. Function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  451. \Description
  452. \var{IncMonth} increases the month number in \var{DateTime} with
  453. \var{NumberOfMonths}. It wraps the result as to get a month between 1 and
  454. 12, and updates the year accordingly. \var{NumberOfMonths} can be negative,
  455. and can be larger than 12 (in absolute value).
  456. \Errors
  457. None.
  458. \SeeAlso
  459. \seef{Date}, \seef{Time}, \seef{Now}
  460. \end{function}
  461. \latex{\inputlisting{sysutex/ex15.pp}}
  462. \html{\input{sysutex/ex15.tex}}
  463. \begin{function}{IsLeapYear}
  464. \Declaration
  465. Function IsLeapYear(Year: Word): boolean;
  466. \Description
  467. \var{IsLeapYear} returns \var{True} if \var{Year} is a leap year,
  468. \var{False} otherwise.
  469. \Errors
  470. None.
  471. \SeeAlso
  472. \seef{IncMonth}, \seef{Date}
  473. \end{function}
  474. \latex{\inputlisting{sysutex/ex16.pp}}
  475. \html{\input{sysutex/ex16.tex}}
  476. \begin{function}{MSecsToTimeStamp}
  477. \Declaration
  478. Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  479. \Description
  480. \var{MSecsTiTimeStamp} converts the given number of milliseconds to
  481. a \var{TTimeStamp} date/time notation.
  482. Use \var{TTimeStamp} variables if you need to keep very precise track of
  483. time.
  484. \Errors
  485. None.
  486. \SeeAlso
  487. \seef{TimeStampToMSecs}, \seef{DateTimeToTimeStamp},
  488. \end{function}
  489. \latex{\inputlisting{sysutex/ex17.pp}}
  490. \html{\input{sysutex/ex17.tex}}
  491. \begin{function}{Now}
  492. \Declaration
  493. Function Now: TDateTime;
  494. \Description
  495. \var{Now} returns the current date and time. It is equivalent to
  496. \var{Date+Time}.
  497. \Errors
  498. None.
  499. \SeeAlso
  500. \seef{Date}, \seef{Time}
  501. \end{function}
  502. \latex{\inputlisting{sysutex/ex18.pp}}
  503. \html{\input{sysutex/ex18.tex}}
  504. \begin{function}{StrToDate}
  505. \Declaration
  506. Function StrToDate(const S: string): TDateTime;
  507. \Description
  508. \var{StrToDate} converts the string \var{S} to a \var{TDateTime} date
  509. value. The Date must consist of 1 to three digits, separated by the
  510. \var{DateSeparator} character. If two numbers are given, they
  511. are supposed to form the day and month of the current year. If only
  512. one number is given, it is supposed to represent the day of the
  513. current month. (This is \em{not} supported in Delphi)
  514. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  515. \var{ShortDateFormat} variable.
  516. \Errors
  517. On error (e.g. an invalid date or invalid character),
  518. an \var{EConvertError} exception is raised.
  519. \SeeAlso
  520. \seef{StrToTime}, \seef{DateToStr}n \seef{TimeToStr}.
  521. \end{function}
  522. \latex{\inputlisting{sysutex/ex19.pp}}
  523. \html{\input{sysutex/ex19.tex}}
  524. \begin{function}{StrToDateTime}
  525. \Declaration
  526. Function StrToDateTime(const S: string): TDateTime;
  527. \Description
  528. \var{StrToDateTime} converts the string \var{S} to a \var{TDateTime} date
  529. and time value. The Date must consist of 1 to three digits, separated by the
  530. \var{DateSeparator} character. If two numbers are given, they
  531. are supposed to form the day and month of the current year. If only
  532. one number is given, it is supposed to represent the day of the
  533. current month. (This is \em{not} supported in Delphi)
  534. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  535. \var{ShortDateFormat} variable.
  536. \Errors
  537. On error (e.g. an invalid date or invalid character),
  538. an \var{EConvertError} exception is raised.
  539. \SeeAlso
  540. \seef{StrToDate}, \seef{StrToTime}, \seef{DateTimeToStr}
  541. \end{function}
  542. \latex{\inputlisting{sysutex/ex20.pp}}
  543. \html{\input{sysutex/ex20.tex}}
  544. \begin{function}{StrToTime}
  545. \Declaration
  546. Function StrToTime(const S: string): TDateTime;
  547. \Description
  548. \var{StrToTime} converts the string \var{S} to a \var{TDateTime} time
  549. value. The time must consist of 1 to 4 digits, separated by the
  550. \var{TimeSeparator} character. If two numbers are given, they
  551. are supposed to form the hour and minutes.
  552. \Errors
  553. On error (e.g. an invalid date or invalid character),
  554. an \var{EConvertError} exception is raised.
  555. \SeeAlso
  556. \seef{StrToDate}, \seef{StrToDateTime}, \seef{TimeToStr}
  557. \end{function}
  558. \latex{\inputlisting{sysutex/ex21.pp}}
  559. \html{\input{sysutex/ex21.tex}}
  560. \begin{function}{SystemTimeToDateTime}
  561. \Declaration
  562. Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  563. \Description
  564. \var{SystemTimeToDateTime} converts a \var{TSystemTime} record to a
  565. \var{TDateTime} style date/time indication.
  566. \Errors
  567. None.
  568. \SeeAlso
  569. \seep{DateTimeToSystemTime}
  570. \end{function}
  571. \latex{\inputlisting{sysutex/ex22.pp}}
  572. \html{\input{sysutex/ex22.tex}}
  573. \begin{function}{Time}
  574. \Declaration
  575. Function Time: TDateTime;
  576. \Description
  577. \var{Time} returns the current time in \var{TDateTime} format. The date
  578. part of the \var{TDateTimeValue} is set to zero.
  579. \Errors
  580. None.
  581. \SeeAlso
  582. \seef{Now}, \seef{Date}
  583. \end{function}
  584. \latex{\inputlisting{sysutex/ex23.pp}}
  585. \html{\input{sysutex/ex23.tex}}
  586. \begin{function}{TimeStampToDateTime}
  587. \Declaration
  588. Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  589. \Description
  590. \var{TimeStampToDateTime} converts \var{TimeStamp} to a \var{TDateTime}
  591. format variable. It is the inverse operation of \seef{DateTimeToTimeStamp}.
  592. \Errors
  593. None.
  594. \SeeAlso
  595. \seef{DateTimeToTimeStamp}, \seef{TimeStampToMSecs}
  596. \end{function}
  597. \latex{\inputlisting{sysutex/ex24.pp}}
  598. \html{\input{sysutex/ex24.tex}}
  599. \begin{function}{TimeStampToMSecs}
  600. \Declaration
  601. Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  602. \Description
  603. \var{TimeStampToMSecs} converts {TimeStamp} to the number of seconds
  604. since \var{1/1/0001}.
  605. Use \var{TTimeStamp} variables if you need to keep very precise track of
  606. time.
  607. \Errors
  608. None.
  609. \SeeAlso
  610. \seef{MSecsToTimeStamp}, \seef{TimeStampToDateTime}
  611. \end{function}
  612. For an example, see \seef{MSecsToTimeStamp}.
  613. \begin{function}{TimeToStr}
  614. \Declaration
  615. Function TimeToStr(Time: TDateTime): string;
  616. \Description
  617. \var{TimeToStr} converts the time in \var{Time} to a string. It uses
  618. the \var{ShortTimeFormat} variable to see what formatting needs to be
  619. applied. It is therefor entirely equivalent to a
  620. \var{FormatDateTime('t',Time)} call.
  621. \Errors
  622. None.
  623. \SeeAlso
  624. \end{function}
  625. \latex{\inputlisting{sysutex/ex25.pp}}
  626. \html{\input{sysutex/ex25.tex}}
  627. \section{Disk functions}
  628. \begin{functionl}{AddDisk (Linux only)}{AddDisk}
  629. \Declaration
  630. Function AddDisk (Const PAth : String) : Longint;
  631. \Description
  632. On Linux both the \seef{DiskFree} and \seef{DiskSize} functions need a
  633. file on the specified drive, since is required for the statfs system call.
  634. These filenames are set in drivestr[0..26], and the first 4 have been
  635. preset to :
  636. \begin{description}
  637. \item[Disk 0] \var{'.'} default drive - hence current directory is used.
  638. \item[Disk 1] \var{'/fd0/.'} floppy drive 1.
  639. \item[Disk 2] \var{'/fd1/.'} floppy drive 2.
  640. \item[Disk 3] \var{'/'} \file{C:} equivalent of DOS is the root partition.
  641. \end{description}
  642. Drives 4..26 can be set by your own applications with the \var{AddDisk} call.
  643. The \var{AddDisk} call adds \var{Path} to the names of drive files, and
  644. returns the number of the disk that corresponds to this drive. If you
  645. add more than 21 drives, the count is wrapped to 4.
  646. \Errors
  647. None.
  648. \SeeAlso
  649. \seefl{DiskFree}{DiskFreeSys}, \seefl{DiskSize}{DiskSizeSys}
  650. \end{functionl}
  651. \begin{function}{CreateDir}
  652. \Declaration
  653. Function CreateDir(Const NewDir : String) : Boolean;
  654. \Description
  655. \var{CreateDir} creates a new directory with name \var{NewDir}.
  656. If the directory doesn't contain an absolute path, then the directory is
  657. created below the current working directory.
  658. The function returns \var{True} if the directory was successfully
  659. created, \var{False} otherwise.
  660. \Errors
  661. In case of an error, the function returns \var{False}.
  662. \SeeAlso
  663. \seef{RemoveDir}
  664. \end{function}
  665. \latex{\inputlisting{sysutex/ex26.pp}}
  666. \html{\input{sysutex/ex26.tex}}
  667. \begin{functionl}{DiskFree}{DiskFreeSys}
  668. \Declaration
  669. Function DiskFree(Drive : Byte) : Longint;
  670. \Description
  671. \var{DiskFree} returns the free space (in bytes) on disk \var{Drive}.
  672. Drive is the number of the disk drive:
  673. \begin{description}
  674. \item[0] for the current drive.
  675. \item[1] for the first floppy drive.
  676. \item[2] for the second floppy drive.
  677. \item[3] for the first hard-disk parttion.
  678. \item[4-26] for all other drives and partitions.
  679. \end{description}
  680. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  681. different than the \dos one, since the filesystem is seen as one big
  682. directory tree. For this reason, the \var{DiskFree} and \seef{DiskSize}
  683. functions must be mimicked using filenames that reside on the partitions.
  684. For more information, see \seef{AddDisk}
  685. \Errors
  686. On error, \var{-1} is returned.
  687. \SeeAlso
  688. \seefl{DiskSize}{DiskSizeSys}, \seef{AddDisk}
  689. \end{functionl}
  690. \latex{\inputlisting{sysutex/ex27.pp}}
  691. \html{\input{sysutex/ex27.tex}}
  692. \begin{functionl}{DiskSize}{DiskSizeSys}
  693. \Declaration
  694. Function DiskSize(Drive : Byte) : Longint;
  695. \Description
  696. \var{DiskSize} returns the size (in bytes) of disk \var{Drive}.
  697. Drive is the number of the disk drive:
  698. \begin{description}
  699. \item[0] for the current drive.
  700. \item[1] for the first floppy drive.
  701. \item[2] for the second floppy drive.
  702. \item[3] for the first hard-disk parttion.
  703. \item[4-26] for all other drives and partitions.
  704. \end{description}
  705. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  706. different than the \dos one, since the filesystem is seen as one big
  707. directory tree. For this reason, the \seef{DiskFree} and \var{DiskSize}
  708. functions must be mimicked using filenames that reside on the partitions.
  709. For more information, see \seef{AddDisk}
  710. \Errors
  711. On error, \var{-1} is returned.
  712. \SeeAlso
  713. \seefl{DiskFree}{DiskFreeSys}, \seef{AddDisk}
  714. \end{functionl}
  715. For an example, see \seefl{DiskFree}{DiskFreeSys}.
  716. \begin{function}{GetCurrentDir}
  717. \Declaration
  718. Function GetCurrentDir : String;
  719. \Description
  720. \var{GetCurrentDir} returns the current working directory.
  721. \Errors
  722. None.
  723. \SeeAlso
  724. \seef{SetCurrentDir}, \seef{DiskFree}, \seef{DiskSize}
  725. \end{function}
  726. \latex{\inputlisting{sysutex/ex28.pp}}
  727. \html{\input{sysutex/ex28.tex}}
  728. \begin{function}{RemoveDir}
  729. \Declaration
  730. Function RemoveDir(Const Dir : String) : Boolean;
  731. \Description
  732. \var{RemoveDir} removes directory \var{Dir} from the disk.
  733. If the directory is not absolue, it is appended to the current working
  734. directory.
  735. \Errors
  736. In case of error (e.g. the directory isn't empty) the function returns
  737. \var{False}. If successful, \var{True} is returned.
  738. \SeeAlso
  739. \end{function}
  740. For an example, see \seef{CreateDir}.
  741. \begin{function}{SetCurrentDir}
  742. \Declaration
  743. Function SetCurrentDir(Const NewDir : String) : Boolean;
  744. \Description
  745. \var{SetCurrentDir} sets the current working directory of your program
  746. to \var{NewDir}. It returns \var{True} if the function was successfull,
  747. \var{False} otherwise.
  748. \Errors
  749. In case of error, \var{False} is returned.
  750. \SeeAlso
  751. \seef{GetCurrentDir}
  752. \end{function}
  753. \latex{\inputlisting{sysutex/ex29.pp}}
  754. \html{\input{sysutex/ex29.tex}}
  755. \section{File handling functions}
  756. \begin{function}{ChangeFileExt}
  757. \Declaration
  758. Function ChangeFileExt(const FileName, Extension: string): string;
  759. \Description
  760. \var{ChangeFileExt} changes the file extension in \var{FileName} to
  761. \var{Extension}.
  762. The extension \var{Extension} includes the starting \var{.} (dot).
  763. The previous extension of \var{FileName} are all characters after the
  764. last \var{.}, the \var{.} character included.
  765. If \var{FileName} doesn't have an extension, \var{Extension} is just
  766. appended.
  767. \Errors
  768. None.
  769. \SeeAlso
  770. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExpandFileName}
  771. \end{function}
  772. \begin{function}{DeleteFile}
  773. \Declaration
  774. Function DeleteFile(Const FileName : String) : Boolean;
  775. \Description
  776. \var{DeleteFile} deletes file \var{FileName} from disk. The function
  777. returns \var{True} if the file was successfully removed, \var{False}
  778. otherwise.
  779. \Errors
  780. On error, \var{False} is returned.
  781. \SeeAlso
  782. \seef{FileCreate}, \seef{FileExists}
  783. \end{function}
  784. \latex{\inputlisting{sysutex/ex31.pp}}
  785. \html{\input{sysutex/ex31.tex}}
  786. \begin{procedure}{DoDirSeparators}
  787. \Declaration
  788. Procedure DoDirSeparators(Var FileName : String);
  789. \Description
  790. This function replaces all directory separators \var{'\' and '/'}
  791. to the directory separator character for the current system.
  792. \Errors
  793. None.
  794. \SeeAlso
  795. \seef{ExtractFileName}, \seef{ExtractFilePath}
  796. \end{procedure}
  797. \latex{\inputlisting{sysutex/ex32.pp}}
  798. \html{\input{sysutex/ex32.tex}}
  799. \begin{function}{ExpandFileName}
  800. \Declaration
  801. Function ExpandFileName(Const FileName : string): String;
  802. \Description
  803. \var{ExpandFileName} expands the filename to an absolute filename.
  804. It changes all directory separator characters to the one appropriate for the
  805. system first.
  806. \Errors
  807. None.
  808. \SeeAlso
  809. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  810. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  811. \end{function}
  812. \latex{\inputlisting{sysutex/ex33.pp}}
  813. \html{\input{sysutex/ex33.tex}}
  814. \begin{function}{ExpandUNCFileName}
  815. \Declaration
  816. Function ExpandUNCFileName(Const FileName : string): String;
  817. \Description
  818. \var{ExpandUNCFileName} runs \seef{ExpandFileName} on \var{FileName}
  819. and then attempts to replace the driveletter by the name of a shared disk.
  820. \Errors
  821. \SeeAlso
  822. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  823. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  824. \end{function}
  825. \begin{function}{ExtractFileDir}
  826. \Declaration
  827. Function ExtractFileDir(Const FileName : string): string;
  828. \Description
  829. \var{ExtractFileDir} returns only the directory part of \var{FileName},
  830. not including a driveletter. The directory name has NO ending directory
  831. separator, in difference with \seef{ExtractFilePath}.
  832. \Errors
  833. None.
  834. \SeeAlso
  835. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  836. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  837. \end{function}
  838. \latex{\inputlisting{sysutex/ex34.pp}}
  839. \html{\input{sysutex/ex34.tex}}
  840. \begin{function}{ExtractFileDrive}
  841. \Declaration
  842. Function ExtractFileDrive(const FileName: string): string;
  843. \Description
  844. \var{Extract}
  845. \Errors
  846. \SeeAlso
  847. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  848. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  849. \end{function}
  850. For an example, see \seef{ExtractFileDir}.
  851. \begin{function}{ExtractFileExt}
  852. \Declaration
  853. Function ExtractFileExt(const FileName: string): string;
  854. \Description
  855. \var{ExtractFileExt} returns the extension (including the
  856. \var{.}(dot) character) of \var{FileName}.
  857. \Errors
  858. None.
  859. \SeeAlso
  860. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  861. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  862. \end{function}
  863. For an example, see \seef{ExtractFileDir}.
  864. \begin{function}{ExtractFileName}
  865. \Declaration
  866. Function ExtractFileName(const FileName: string): string;
  867. \Description
  868. \var{ExtractFileName} returns the filename part from \var{FileName}.
  869. The filename consists of all characters after the last directory separator
  870. character ('/' or '\') or drive letter.
  871. The full filename can always be reconstucted by concatenating the result
  872. of \seef{ExtractFilePath} and \var{ExtractFileName}.
  873. \Errors
  874. None.
  875. \SeeAlso
  876. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  877. \seef{ExtractFileDrive}, \seef{ExtractFileExt},\seef{ExtractRelativePath}
  878. \end{function}
  879. For an example, see \seef{ExtractFileDir}.
  880. \begin{function}{ExtractFilePath}
  881. \Declaration
  882. Function ExtractFilePath(const FileName: string): string;
  883. \Description
  884. \var{ExtractFilePath} returns the path part (including driveletter) from
  885. \var{FileName}. The path consists of all characters before the last
  886. directory separator character ('/' or '\'), including the directory
  887. separator itself.
  888. In case there is only a drive letter, that will be returned.
  889. The full filename can always be reconstucted by concatenating the result
  890. of \var{ExtractFilePath} and \seef{ExtractFileName}.
  891. \Errors
  892. None.
  893. \SeeAlso
  894. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  895. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  896. \end{function}
  897. For an example, see \seef{ExtractFileDir}.
  898. \begin{function}{ExtractRelativePath}
  899. \Declaration
  900. Function ExtractRelativePath(Const BaseName,DestNAme : String): String;
  901. \Description
  902. \var{ExtractRelativePath} constructs a relative path to go from
  903. \var{BaseName} to \var{DestName}. If \var{DestName} is on another drive
  904. (Not on Linux) then the whole \var{Destname} is returned.
  905. {\em Note:} This function does not exist in the Delphi unit.
  906. \Errors
  907. None.
  908. \SeeAlso
  909. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  910. \seef{ExtractFileDrive}, \seef{ExtractFileExt},
  911. \end{function}
  912. \latex{\inputlisting{sysutex/ex35.pp}}
  913. \html{\input{sysutex/ex35.tex}}
  914. \begin{function}{FileAge}
  915. \Declaration
  916. Function FileAge(Const FileName : String): Longint;
  917. \Description
  918. \var{FileAge} returns the last modification time of file \var{FileName}.
  919. The FileDate format can be transformed to \var{TDateTime} format with the
  920. \seef{FileDateToDateTime} function.
  921. \Errors
  922. In case of errors, \var{-1} is returned.
  923. \SeeAlso
  924. \seef{FileDateToDateTime}, \seef{FileExists}, \seef{FileGetAttr}
  925. \end{function}
  926. \latex{\inputlisting{sysutex/ex36.pp}}
  927. \html{\input{sysutex/ex36.tex}}
  928. \begin{procedure}{FileClose}
  929. \Declaration
  930. Procedure FileClose(Handle : Longint);
  931. \Description
  932. \var{FileClose} closes the file handle \var{Handle}. After this call,
  933. attempting to read or write from the handle will result in an error.
  934. \Errors
  935. None.
  936. \SeeAlso
  937. \seef{FileCreate}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  938. \seef{FileTruncate}, \seef{FileSeek}
  939. \end{procedure}
  940. For an example, see \seef{FileCreate}
  941. \begin{function}{FileCreate}
  942. \Declaration
  943. Function FileCreate(Const FileName : String) : Longint;
  944. \Description
  945. \var{FileCreate} creates a new file with name \var{FileName} on the disk and
  946. returns a file handle which can be used to read or write from the file with
  947. the \seef{FileRead} and \seef{FileWrite} functions.
  948. If a file with name \var{FileName} already existed on the disk, it is
  949. overwritten.
  950. \Errors
  951. If an error occurs (e.g. disk full or non-existent path), the function
  952. returns \var{-1}.
  953. \SeeAlso
  954. \seep{FileClose}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  955. \seef{FileTruncate}, \seef{FileSeek}
  956. \end{function}
  957. \latex{\inputlisting{sysutex/ex37.pp}}
  958. \html{\input{sysutex/ex37.tex}}
  959. \begin{function}{FileExists}
  960. \Declaration
  961. Function FileExists(Const FileName : String) : Boolean;
  962. \Description
  963. \var{FileExists} returns \var{True} if a file with name \var{FileName}
  964. exists on the disk, \var{False} otherwise.
  965. \Errors
  966. None.
  967. \SeeAlso
  968. \seef{FileAge}, \seef{FileGetAttr}, \seef{FileSetAttr}
  969. \end{function}
  970. \latex{\inputlisting{sysutex/ex38.pp}}
  971. \html{\input{sysutex/ex38.tex}}
  972. \begin{function}{FileGetAttr}
  973. \Declaration
  974. Function FileGetAttr(Const FileName : String) : Longint;
  975. \Description
  976. \var{FileGetAttr} returns the attribute settings of file
  977. \var{FileName}. The attribute is a \var{OR}-ed combination
  978. of the following constants:
  979. \begin{description}
  980. \item[faReadOnly] The file is read-only.
  981. \item[faHidden] The file is hidden. (On \linux, this means that the filename
  982. starts with a dot)
  983. \item[faSysFile] The file is a system file (On \linux, this means that the
  984. file is a character, block or FIFO file).
  985. \item[faVolumeId] Volume Label. Not possible under \linux.
  986. \item[faDirectory] File is a directory.
  987. \item[faArchive] file is an archive. Not possible on \linux.
  988. \end{description}
  989. \Errors
  990. In case of error, -1 is returned.
  991. \SeeAlso
  992. \seef{FileSetAttr}, \seef{FileAge}, \seef{FileGetDate}.
  993. \end{function}
  994. \latex{\inputlisting{sysutex/ex40.pp}}
  995. \html{\input{sysutex/ex40.tex}}
  996. \begin{function}{FileGetDate}
  997. \Declaration
  998. Function FileGetDate(Handle : Longint) : Longint;
  999. \Description
  1000. \var{FileGetdate} returns the filetime of the opened file with filehandle
  1001. \var{Handle}. It is the same as \seef{FileAge}, with this difference that
  1002. \var{FileAge} only needs the file name, while \var{FilegetDate} needs an
  1003. open file handle.
  1004. \Errors
  1005. On error, -1 is returned.
  1006. \SeeAlso
  1007. \seef{FileAge}
  1008. \end{function}
  1009. \latex{\inputlisting{sysutex/ex39.pp}}
  1010. \html{\input{sysutex/ex39.tex}}
  1011. \begin{function}{FileOpen}
  1012. \Declaration
  1013. Function FileOpen(Const FileName : string; Mode : Integer) : Longint;
  1014. \Description
  1015. \var{FileOpen} opens a file with name \var{FileName} with mode \var{Mode}.
  1016. \var{Mode} can be one of the following constants:
  1017. \begin{description}
  1018. \item[fmOpenRead] The file is opened for reading.
  1019. \item[fmOpenWrite] The file is opened for writing.
  1020. \item[fmOpenReadWrite] The file is opened for reading and writing.
  1021. \end{description}
  1022. If the file has been successfully opened, it can be read from or written to
  1023. (depending on the \var{Mode} parameter) with the \seef{FileRead} and
  1024. \var{FileWrite} functions.
  1025. Remark that you cannot open a file if it doesn't exist yet, i.e. it will not
  1026. be created for you. If you want tp create a new file, or overwrite an old
  1027. one, use the \seef{FileCreate} function.
  1028. \Errors
  1029. On Error, -1 is returned.
  1030. \SeeAlso
  1031. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileRead},
  1032. \seef{FileTruncate}, \seef{FileSeek}
  1033. \end{function}
  1034. For an example, see \seef{FileRead}
  1035. \begin{function}{FileRead}
  1036. \Declaration
  1037. Function FileRead(Handle : Longint; Var Buffer; Count : longint) : Longint;
  1038. \Description
  1039. \var{FileRead} reads \var{Count} bytes from file-handle \var{Handle} and
  1040. stores them into \var{Buffer}. Buffer must be at least \var{Count} bytes
  1041. long. No checking on this is performed, so be careful not to overwrite any
  1042. memory. \var{Handle} must be the result of a \seef{FileOpen} call.
  1043. \Errors
  1044. On error, -1 is returned.
  1045. \SeeAlso
  1046. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen},
  1047. \seef{FileTruncate}, \seef{FileSeek}
  1048. \end{function}
  1049. For an example, see \seef{FileOpen}
  1050. \begin{function}{FileSearch}
  1051. \Declaration
  1052. Function FileSearch(Const Name, DirList : String) : String;
  1053. \Description
  1054. \var{FileSearch} looks for the file \var{Name} in \var{DirList}, where
  1055. dirlist is a list of directories, separated by semicolons or colons.
  1056. It returns the full filename of the first match found.
  1057. \Errors
  1058. On error, an empty string is returned.
  1059. \SeeAlso
  1060. \seef{ExpandFileName}, \seef{FindFirst}
  1061. \end{function}
  1062. \latex{\inputlisting{sysutex/ex41.pp}}
  1063. \html{\input{sysutex/ex41.tex}}
  1064. \begin{function}{FileSeek}
  1065. \Declaration
  1066. Function FileSeek(Handle,Offset,Origin : Longint) : Longint;
  1067. \Description
  1068. \var{FileSeek} sets the file pointer on position \var{Offset}, starting from
  1069. \var{Origin}. Origin can be one of the following values:
  1070. \begin{description}
  1071. \item[fsFromBeginning] \var{Offset} is relative to the first byte of the file. This
  1072. position is zero-based. i.e. the first byte is at offset 0.
  1073. \item[fsFromCurrent] \var{Offset} is relative to the current position.
  1074. \item[fsFromEnd] \var{Offset} is relative to the end of the file. This means
  1075. that \var{Offset} can only be zero or negative in this case.
  1076. \end{description}
  1077. If successfull, the function returns the new file position, relative to the
  1078. beginning of the file.
  1079. {\em Remark:} The abovementioned constants do not exist in Delphi.
  1080. \Errors
  1081. On error, -1 is returned.
  1082. \SeeAlso
  1083. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  1084. \seef{FileRead}, \seef{FileTruncate}
  1085. \end{function}
  1086. \latex{\inputlisting{sysutex/ex42.pp}}
  1087. \html{\input{sysutex/ex42.tex}}
  1088. For an example, see \seef{FileCreate}
  1089. \begin{functionl}{FileSetAttr (Not on Linux)}{FileSetAttr}
  1090. \Declaration
  1091. Function FileSetAttr(Const Filename : String; Attr: longint) : Longint;
  1092. \Description
  1093. \var{FileSetAttr} sets the attributes of \var{FileName} to \var{Attr}.
  1094. If the function was successful, 0 is returned, -1 otherwise.
  1095. \var{Attr} can be set to an OR-ed combination of the pre-defined
  1096. \var{faXXX} constants.
  1097. \Errors
  1098. On error, -1 is returned (always on linux).
  1099. \SeeAlso
  1100. \seef{FileGetAttr}, \seef{FileGetDate}, \seef{FileSetDate}.
  1101. \end{functionl}
  1102. \begin{functionl}{FileSetDate (Not on Linux)}{FileSetDate}
  1103. \Declaration
  1104. Function FileSetDate(Handle,Age : Longint) : Longint;
  1105. \Description
  1106. \var{FileSetDate} sets the file date of the file with handle \var{Handle}
  1107. to \var{Age}, where \var{Age} is a DOS date-and-time stamp value.
  1108. The function returns zero of successfull.
  1109. \Errors
  1110. On Linux, -1 is always returned, since this is impossible to implement.
  1111. On Windows and DOS, a negative error code is returned.
  1112. \SeeAlso
  1113. \end{functionl}
  1114. \begin{function}{FileTruncate}
  1115. \Declaration
  1116. Function FileTruncate(Handle,Size: Longint) : boolean;
  1117. \Description
  1118. \var{FileTruncate} truncates the file with handle \var{Handle} to
  1119. \var{Size} bytes. The file must have been opened for writing prior
  1120. to this call. The function returns \var{True} is successful, \var{False}
  1121. otherwise.
  1122. \Errors
  1123. On error, the function returns \var{False}.
  1124. \SeeAlso
  1125. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  1126. \seef{FileRead}, \seef{FileSeek}
  1127. \end{function}
  1128. For an example, see \seef{FileCreate}.
  1129. \begin{function}{FileWrite}
  1130. \Declaration
  1131. Function FileWrite(Handle : Longint; Var Buffer; Count : Longint) : Longint;
  1132. \Description
  1133. \var{FileWrite} writes \var{Count} bytes from \var{Buffer} to the file with
  1134. handle \var{Handle}. Prior to this call, the file must have been opened
  1135. for writing. \var{Buffer} must be at least \var{Count} bytes large, or
  1136. a memory access error may occur.
  1137. The function returns the number of bytes written, or -1 in case of an
  1138. error.
  1139. \Errors
  1140. In case of error, -1 is returned.
  1141. \SeeAlso
  1142. \seep{FileClose}, \seef{FileCreate}, \seef{FileOpen}
  1143. \seef{FileRead}, \seef{FileTruncate}, \seef{FileSeek}
  1144. \end{function}
  1145. For an example, see \seef{FileCreate}.
  1146. \begin{procedurel}{FindClose}{FindCloseSys}
  1147. \Declaration
  1148. Procedure FindClose(Var F : TSearchrec);
  1149. \Description
  1150. \var{FindClose} ends a series of \seef{FindFirst}/\seef{FindNext} calls,
  1151. and frees any memory used by these calls. It is {\em absolutely} necessary
  1152. to do this call, or huge memory losses may occur.
  1153. \Errors
  1154. None.
  1155. \SeeAlso
  1156. \seef{FindFirst}, \seef{FindNext}.
  1157. \end{procedurel}
  1158. For an example, see \seef{FindFirst}.
  1159. \begin{function}{FindFirst}
  1160. \Declaration
  1161. Function FindFirst(Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  1162. \Description
  1163. \var{FindFirst} looks for files that match the name (possibly with
  1164. wildcards) in \var{Path} and attributes \var{Attr}. It then fills up the
  1165. \var{Rslt} record with data gathered about the file. It returns 0 if a file
  1166. matching the specified criteria is found, a nonzero value (-1 on linux)
  1167. otherwise.
  1168. The \var{Rslt} record can be fed to subsequent calls to \var{FindNext}, in
  1169. order to find other files matching the specifications.
  1170. {\em remark:} A \var{FindFirst} call must {\em always} be followed by a
  1171. \seepl{FindClose}{FindCloseSys} call with the same \var{Rslt} record. Failure to do so will
  1172. result in memory loss.
  1173. \Errors
  1174. On error the function returns -1 on linux, a nonzero error code on Windows.
  1175. \SeeAlso
  1176. \seep{FindClose}{FindCloseSys}, \seef{FindNext}.
  1177. \end{function}
  1178. \latex{\inputlisting{sysutex/ex43.pp}}
  1179. \html{\input{sysutex/ex43.tex}}
  1180. \begin{function}{FindNext}
  1181. \Declaration
  1182. Function FindNext(Var Rslt : TSearchRec) : Longint;
  1183. \Description
  1184. \var{FindNext} finds a next occurrence of a search sequence initiated by
  1185. \var{FindFirst}. If another record matching the criteria in Rslt is found, 0
  1186. is returned, a nonzero constant is returned otherwise.
  1187. {\em remark:} The last \var{FindNext} call must {\em always} be followed by a
  1188. \var{FindClose} call with the same \var{Rslt} record. Failure to do so will
  1189. result in memory loss.
  1190. \Errors
  1191. On error (no more file is found), a nonzero constant is returned.
  1192. \SeeAlso
  1193. \seef{FindFirst}, \seep{FindClose}
  1194. \end{function}
  1195. For an example, see \seef{FindFirst}
  1196. \begin{function}{GetDirs}
  1197. \Declaration
  1198. Function GetDirs(Var DirName : String; Var Dirs : Array of pchar) : Longint;
  1199. \Description
  1200. \var{GetDirs} splits DirName in a null-byte separated list of directory names,
  1201. \var{Dirs} is an array of \var{PChars}, pointing to these directory names.
  1202. The function returns the number of directories found, or -1 if none were found.
  1203. DirName must contain only OSDirSeparator as Directory separator chars.
  1204. \Errors
  1205. None.
  1206. \SeeAlso
  1207. \seef{ExtractRelativePath}
  1208. \end{function}
  1209. \latex{\inputlisting{sysutex/ex45.pp}}
  1210. \html{\input{sysutex/ex45.tex}}
  1211. \begin{function}{RenameFile}
  1212. \Declaration
  1213. Function RenameFile(Const OldName, NewName : String) : Boolean;
  1214. \Description
  1215. \var{RenameFile} renames a file from \var{OldName} to \var{NewName}. The
  1216. function returns \var{True} if successful, \var{False} otherwise.
  1217. {\em Remark:} you cannot rename across disks or partitions.
  1218. \Errors
  1219. On Error, \var{False} is returned.
  1220. \SeeAlso
  1221. \seef{DeleteFile}
  1222. \end{function}
  1223. \latex{\inputlisting{sysutex/ex44.pp}}
  1224. \html{\input{sysutex/ex44.tex}}
  1225. \begin{function}{SetDirSeparators}
  1226. \Declaration
  1227. Function SetDirSeparators(Const FileName : String) : String;
  1228. \Description
  1229. \var{SetDirSeparators} returns \var{FileName} with all possible
  1230. DirSeparators replaced by \var{OSDirSeparator}.
  1231. \Errors
  1232. None.
  1233. \SeeAlso
  1234. \seef{ExpandFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir}
  1235. \end{function}
  1236. \latex{\inputlisting{sysutex/ex47.pp}}
  1237. \html{\input{sysutex/ex47.tex}}
  1238. \section{PChar functions}
  1239. \subsection{Introduction}
  1240. Most PChar functions are the same as their counterparts in the \file{STRINGS}
  1241. unit. The following functions are the same :
  1242. \begin{enumerate}
  1243. \item \seef{StrCat} : Concatenates two \var{PChar} strings.
  1244. \item \seef{StrComp} : Compares two \var{PChar} strings.
  1245. \item \seef{StrCopy} : Copies a \var{PChar} string.
  1246. \item \seef{StrECopy} : Copies a \var{PChar} string and returns a pointer to
  1247. the terminating null byte.
  1248. \item \seef{StrEnd} : Returns a pointer to the terminating null byte.
  1249. \item \seef{StrIComp} : Case insensitive compare of 2 \var{PChar} strings.
  1250. \item \seef{StrLCat} : Appends at most L characters from one \var{PChar} to
  1251. another \var{PChar}.
  1252. \item \seef{StrLComp} : Case sensitive compare of at most L characters of 2
  1253. \var{PChar} strings.
  1254. \item \seef{StrLCopy} : Copies at most L characters from one \var{PChar} to
  1255. another.
  1256. \item \seef{StrLen} : Returns the length (exclusive terminating null byte)
  1257. of a \var{PChar} string.
  1258. \item \seef{StrLIComp} : Case insensitive compare of at most L characters of 2
  1259. \var{PChar} strings.
  1260. \item \seef{StrLower} : Converts a \var{PChar} to all lowercase letters.
  1261. \item \seef{StrMove} : Moves one \var{PChar} to another.
  1262. \item \seef{StrNew} : Makes a copy of a \var{PChar} on the heap, and returns
  1263. a pointer to this copy.
  1264. \item \seef{StrPos} : Returns the position of one \var{PChar} string in
  1265. another?
  1266. \item \seef{StrRScan} : returns a pointer to the last occurrence of on
  1267. \var{PChar} string in another one.
  1268. \item \seef{StrScan} : returns a pointer to the first occurrence of on
  1269. \var{PChar} string in another one.
  1270. \item \seef{StrUpper} : Converts a \var{PChar} to all uppercase letters.
  1271. \end{enumerate}
  1272. The subsequent functions are different from their counterparts in
  1273. \file{STRINGS}, although the same examples can be used.
  1274. \begin{functionl}{StrAlloc}{StrAllocSys}
  1275. \Declaration
  1276. Function StrAlloc(Size: cardinal): PChar;
  1277. \Description
  1278. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  1279. terminating \var{\#0} included, and returns a pointer to it.
  1280. Additionally, \var{StrAlloc} allocates 4 extra bytes to store the size of
  1281. the allocated memory. Therefore this function is NOT compatible with the
  1282. \seef{StrAlloc} function of the \var{Strings} unit.
  1283. \Errors
  1284. None.
  1285. \SeeAlso
  1286. \seef{StrBufSize}, \seepl{StrDispose}{StrDisposeSys}, \seef{StrAlloc}
  1287. \end{functionl}
  1288. For an example, see \seef{StrBufSize}.
  1289. \begin{function}{StrBufSize}
  1290. \Declaration
  1291. Function StrBufSize(var Str: PChar): cardinal;
  1292. \Description
  1293. \var{StrBufSize} returns the memory allocated for \var{Str}. This function
  1294. ONLY gives the correct result if \var{Str} was allocated using
  1295. \seefl{StrAlloc}{StrAllocSys}.
  1296. \Errors
  1297. If no more memory is available, a runtime error occurs.
  1298. \SeeAlso
  1299. \seefl{StrAlloc}{StrAllocSys}.\seepl{StrDispose}{StrDisposeSys}.
  1300. \end{function}
  1301. \latex{\inputlisting{sysutex/ex46.pp}}
  1302. \html{\input{sysutex/ex46.tex}}
  1303. \begin{procedurel}{StrDispose}{StrDisposeSys}
  1304. \Declaration
  1305. Procedure StrDispose(var Str: PChar);
  1306. \Description
  1307. \var{StrDispose} frees any memory allocated for \var{Str}. This function
  1308. will only function correctly if \var{Str} has been allocated using
  1309. \seefl{StrAlloc}{StrAllocSys} from the \file{SYSUTILS} unit.
  1310. \Errors
  1311. If an invalid pointer is passed, or a pointer not allocated with
  1312. \var{StrAlloc}, an error may occur.
  1313. \SeeAlso
  1314. \seef{StrBufSize}, \seefl{StrAlloc}{StrAllocSys}, \seep{StrDispose}
  1315. \end{procedurel}
  1316. For an example, see \seef{StrBufSize}.
  1317. \begin{functionl}{StrPCopy}{StrPCopySys}
  1318. \Declaration
  1319. Function StrPCopy(Dest: PChar; Source: string): PChar;
  1320. \Description
  1321. \var{StrPCopy} Converts the Ansistring in \var{Source} to a Null-terminated
  1322. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  1323. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  1324. \Errors
  1325. No checking is performed to see whether \var{Dest} points to enough memory
  1326. to contain \var{Source}.
  1327. \SeeAlso
  1328. \seefl{StrPLCopy}{StrPLCopySys}, \seef{StrPCopy}
  1329. \end{functionl}
  1330. For an example, see \seef{StrPCopy}.
  1331. \begin{functionl}{StrPLCopy}{StrPLCopySys}
  1332. \Declaration
  1333. Function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar;
  1334. \Description
  1335. \var{StrPLCopy} Converts maximally \var{MaxLen} characters of the
  1336. Ansistring in \var{Source} to a Null-terminated string, and copies
  1337. it to \var{Dest}. \var{Dest} needs enough room to contain
  1338. the characters.
  1339. \Errors
  1340. No checking is performed to see whether \var{Dest} points to enough memory
  1341. to contain L characters of \var{Source}.
  1342. \Errors
  1343. \SeeAlso
  1344. \seefl{StrPCopy}{StrPCopySys}.
  1345. \end{functionl}
  1346. For an example, see \seef{StrPLCopy}.
  1347. \begin{functionl}{StrPas}{StrPasSys}
  1348. \Declaration
  1349. Function StrPas(Str: PChar): string;
  1350. \Description
  1351. Converts a null terminated string in \var{Str} to an Ansitring, and returns
  1352. this string. This string is NOT truncated at 255 characters as is the
  1353. \Errors
  1354. None.
  1355. \SeeAlso
  1356. \seef{StrPas}.
  1357. \end{functionl}
  1358. For an example, see \seef{StrPas}.
  1359. \section{String handling functions}
  1360. \begin{function}{AdjustLineBreaks}
  1361. \Declaration
  1362. Function AdjustLineBreaks(const S: string): string;
  1363. \Description
  1364. \var{AdjustLineBreaks} will change all \var{\#13} characters with
  1365. \var{\#13\#10} on \windowsnt and \dos. On \linux, all \var{\#13\#10}
  1366. character pairs are converted to \var{#10} and single \var{\#13}
  1367. characters also.
  1368. \Errors
  1369. None.
  1370. \SeeAlso
  1371. \seef{AnsiCompareStr}, \seef{AnsiCompareText}
  1372. \end{function}
  1373. \latex{\inputlisting{sysutex/ex48.pp}}
  1374. \html{\input{sysutex/ex48.tex}}
  1375. \begin{function}{AnsiCompareStr}
  1376. \Declaration
  1377. Function AnsiCompareStr(const S1, S2: string): integer;
  1378. \Description
  1379. \var{AnsiCompareStr} compares two strings and returns the following
  1380. result:
  1381. \begin{description}
  1382. \item[<0] if \var{S1<S2}.
  1383. \item[0] if \var{S1=S2}.
  1384. \item[>0] if \var{S1>S2}.
  1385. \end{description}
  1386. the comparision takes into account Ansi characters, i.e. it takes
  1387. care of strange accented characters. Contrary to \seef{CompareAnsiText},
  1388. the comparision is case sensitive.
  1389. \Errors
  1390. None.
  1391. \SeeAlso
  1392. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  1393. \end{function}
  1394. \latex{\inputlisting{sysutex/ex49.pp}}
  1395. \html{\input{sysutex/ex49.tex}}
  1396. \begin{function}{AnsiCompareText}
  1397. \Declaration
  1398. Function AnsiCompareText(const S1, S2: string): integer;
  1399. \Description
  1400. \Description
  1401. \var{AnsiCompareText} compares two strings and returns the following
  1402. result:
  1403. \begin{description}
  1404. \item[<0] if \var{S1<S2}.
  1405. \item[0] if \var{S1=S2}.
  1406. \item[>0] if \var{S1>S2}.
  1407. \end{description}
  1408. the comparision takes into account Ansi characters, i.e. it takes
  1409. care of strange accented characters. Contrary to \seef{CompareAnsiStr},
  1410. the comparision is case insensitive.
  1411. \Errors
  1412. None.
  1413. \SeeAlso
  1414. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  1415. \end{function}
  1416. \latex{\inputlisting{sysutex/ex50.pp}}
  1417. \html{\input{sysutex/ex50.tex}}
  1418. \begin{function}{AnsiExtractQuotedStr}
  1419. \Declaration
  1420. Function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  1421. \Description
  1422. \var{AnsiExtractQuotedStr} Returns \var{Src} as a string,, with \var{Quute}
  1423. characters removed from the beginning and end of the string, and double
  1424. \var{Quote} characters replaced by a single \var{Quote} characters.
  1425. As such, it revereses the action of \seef{AnsiQuotedStr}.
  1426. \Errors
  1427. None.
  1428. \SeeAlso
  1429. \seef{AnsiQuotedStr}
  1430. \end{function}
  1431. \latex{\inputlisting{sysutex/ex51.pp}}
  1432. \html{\input{sysutex/ex51.tex}}
  1433. \begin{function}{AnsiLastChar}
  1434. \Declaration
  1435. Function AnsiLastChar(const S: string): PChar;
  1436. \Description
  1437. This function returns a pointer to the last character of \var{S}.
  1438. Since multibyte characters are not yet supported, this is the same
  1439. as \var{@S[Length(S)])}.
  1440. \Errors
  1441. None.
  1442. \SeeAlso
  1443. \seef{AnsiStrLastChar}
  1444. \end{function}
  1445. \latex{\inputlisting{sysutex/ex52.pp}}
  1446. \html{\input{sysutex/ex52.tex}}
  1447. \begin{function}{AnsiLowerCase}
  1448. \Declaration
  1449. Function AnsiLowerCase(const s: string): string;
  1450. \Description
  1451. \var{AnsiLowerCase} converts the string \var{S} to lowercase characters
  1452. and returns the resulting string.
  1453. It takes into account the operating system language
  1454. settings when doing this, so spcial characters are converted correctly as
  1455. well.
  1456. {\em Remark} On linux, no language setting is taken in account yet.
  1457. \Errors
  1458. None.
  1459. \SeeAlso
  1460. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiStrUpper}
  1461. \end{function}
  1462. \latex{\inputlisting{sysutex/ex53.pp}}
  1463. \html{\input{sysutex/ex53.tex}}
  1464. \begin{function}{AnsiQuotedStr}
  1465. \Declaration
  1466. Function AnsiQuotedStr(const S: string; Quote: char): string;
  1467. \Description
  1468. \var{AnsiQuotedString} quotes the string \var{S} and returns the result.
  1469. This means that it puts the \var{Quote} character at both the beginning and
  1470. end of the string and replaces any occurrence of \var{Quote} in \var{S}
  1471. with 2 \var{Quote} characters. The action of \var{AnsiQuotedString} can be
  1472. reversed by \seef{AnsiExtractQuotedStr}.
  1473. \Errors
  1474. None.
  1475. \SeeAlso
  1476. \seef{AnsiExtractQuotedStr}
  1477. \end{function}
  1478. For an example, see \seef{AnsiExtractQuotedStr}
  1479. \begin{function}{AnsiStrComp}
  1480. \Declaration
  1481. Function AnsiStrComp(S1, S2: PChar): integer;
  1482. \Description
  1483. \var{AnsiStrComp} compares 2 \var{PChar} strings, and returns the following
  1484. result:
  1485. \begin{description}
  1486. \item[<0] if \var{S1<S2}.
  1487. \item[0] if \var{S1=S2}.
  1488. \item[>0] if \var{S1>S2}.
  1489. \end{description}
  1490. The comparision of the two strings is case-sensitive.
  1491. The function does not yet take internationalization settings into account.
  1492. \Errors
  1493. None.
  1494. \SeeAlso
  1495. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1496. \end{function}
  1497. \latex{\inputlisting{sysutex/ex54.pp}}
  1498. \html{\input{sysutex/ex54.tex}}
  1499. \begin{function}{AnsiStrIComp}
  1500. \Declaration
  1501. Function AnsiStrIComp(S1, S2: PChar): integer;
  1502. \Description
  1503. \var{AnsiStrIComp} compares 2 \var{PChar} strings, and returns the following
  1504. result:
  1505. \begin{description}
  1506. \item[<0] if \var{S1<S2}.
  1507. \item[0] if \var{S1=S2}.
  1508. \item[>0] if \var{S1>S2}.
  1509. \end{description}
  1510. The comparision of the two strings is case-insensitive.
  1511. The function does not yet take internationalization settings into account.
  1512. \Errors
  1513. None.
  1514. \SeeAlso
  1515. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1516. \end{function}
  1517. \latex{\inputlisting{sysutex/ex55.pp}}
  1518. \html{\input{sysutex/ex55.tex}}
  1519. \begin{function}{AnsiStrLastChar}
  1520. \Declaration
  1521. function AnsiStrLastChar(Str: PChar): PChar;
  1522. \Declaration
  1523. \var{AnsiStrLastChar} returns a pointer to the last character of \var{Str}.
  1524. Since multibyte characters are not yet supported, this is the same
  1525. as \var{StrEnd(Str)-1}.
  1526. \Errors
  1527. None.
  1528. \SeeAlso
  1529. \seef{AnsiLastChar}
  1530. \end{function}
  1531. \latex{\inputlisting{sysutex/ex58.pp}}
  1532. \html{\input{sysutex/ex58.tex}}
  1533. \begin{function}{AnsiStrLComp}
  1534. \Declaration
  1535. Function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
  1536. \Description
  1537. \var{AnsiStrLComp} compares the first \var{Maxlen} characters of
  1538. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  1539. result:
  1540. \begin{description}
  1541. \item[<0] if \var{S1<S2}.
  1542. \item[0] if \var{S1=S2}.
  1543. \item[>0] if \var{S1>S2}.
  1544. \end{description}
  1545. The comparision of the two strings is case-sensitive.
  1546. The function does not yet take internationalization settings into account.
  1547. \Errors
  1548. None.
  1549. \SeeAlso
  1550. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1551. \end{function}
  1552. \latex{\inputlisting{sysutex/ex56.pp}}
  1553. \html{\input{sysutex/ex56.tex}}
  1554. \begin{function}{AnsiStrLIComp}
  1555. \Declaration
  1556. Function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
  1557. \Description
  1558. \var{AnsiStrLIComp} compares the first \var{Maxlen} characters of
  1559. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  1560. result:
  1561. \begin{description}
  1562. \item[<0] if \var{S1<S2}.
  1563. \item[0] if \var{S1=S2}.
  1564. \item[>0] if \var{S1>S2}.
  1565. \end{description}
  1566. The comparision of the two strings is case-insensitive.
  1567. The function does not yet take internationalization settings into account.
  1568. \Errors
  1569. None.
  1570. \SeeAlso
  1571. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1572. \end{function}
  1573. \latex{\inputlisting{sysutex/ex57.pp}}
  1574. \html{\input{sysutex/ex57.tex}}
  1575. \begin{function}{AnsiStrLower}
  1576. \Declaration
  1577. Function AnsiStrLower(Str: PChar): PChar;
  1578. \Description
  1579. \var{AnsiStrLower} converts the PChar \var{Str} to lowercase characters
  1580. and returns the resulting pchar. Note that \var{Str} itself is modified,
  1581. not a copy, as in the case of \seef{AnsiLowerCase}.
  1582. It takes into account the operating system language
  1583. settings when doing this, so spcial characters are converted correctly as
  1584. well.
  1585. {\em Remark} On linux, no language setting is taken in account yet.
  1586. \Errors
  1587. None.
  1588. \SeeAlso
  1589. \seef{AnsiStrUpper}, \seef{AnsiLowercase}
  1590. \end{function}
  1591. \Errors
  1592. \SeeAlso
  1593. \end{function}
  1594. \latex{\inputlisting{sysutex/ex59.pp}}
  1595. \html{\input{sysutex/ex59.tex}}
  1596. \begin{function}{AnsiStrUpper}
  1597. \Declaration
  1598. Function AnsiStrUpper(Str: PChar): PChar;
  1599. \Description
  1600. \var{AnsiStrUpper} converts the \var{PChar} \var{Str} to uppercase characters
  1601. and returns the resulting string. Note that \var{Str} itself is modified,
  1602. not a copy, as in the case of \seef{AnsiUpperCase}.
  1603. It takes into account the operating system language
  1604. settings when doing this, so spcial characters are converted correctly as
  1605. well.
  1606. {\em Remark} On linux, no language setting is taken in account yet.
  1607. \Errors
  1608. None.
  1609. \SeeAlso
  1610. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  1611. \end{function}
  1612. \latex{\inputlisting{sysutex/ex60.pp}}
  1613. \html{\input{sysutex/ex60.tex}}
  1614. \begin{function}{AnsiUpperCase}
  1615. \Declaration
  1616. Function AnsiUpperCase(const s: string): string;
  1617. \Description
  1618. \var{AnsiUpperCase} converts the string \var{S} to uppercase characters
  1619. and returns the resulting string.
  1620. It takes into account the operating system language
  1621. settings when doing this, so spcial characters are converted correctly as
  1622. well.
  1623. {\em Remark} On linux, no language setting is taken in account yet.
  1624. \Errors
  1625. None.
  1626. \SeeAlso
  1627. \seef{AnsiStrUpper}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  1628. \end{function}
  1629. \latex{\inputlisting{sysutex/ex61.pp}}
  1630. \html{\input{sysutex/ex61.tex}}
  1631. \begin{procedure}{AppendStr}
  1632. \Declaration
  1633. Procedure AppendStr(var Dest: PString; const S: string);
  1634. \Description
  1635. \var{AppendStr}
  1636. \Errors
  1637. \SeeAlso
  1638. \end{procedure}
  1639. \begin{procedure}{AssignStr}
  1640. \Declaration
  1641. Procedure AssignStr(var P: PString; const S: string);
  1642. \Description
  1643. \Errors
  1644. \SeeAlso
  1645. \end{procedure}
  1646. \begin{function}{BCDToInt}
  1647. \Declaration
  1648. Function BCDToInt(Value: integer): integer;
  1649. \Description
  1650. \Errors
  1651. \SeeAlso
  1652. \end{function}
  1653. \begin{function}{CompareMem}
  1654. \Declaration
  1655. Function CompareMem(P1, P2: Pointer; Length: cardinal): integer;
  1656. \Description
  1657. \Errors
  1658. \SeeAlso
  1659. \end{function}
  1660. \begin{function}{CompareStr}
  1661. \Declaration
  1662. Function CompareStr(const S1, S2: string): Integer;
  1663. \Description
  1664. \Errors
  1665. \SeeAlso
  1666. \end{function}
  1667. \begin{function}{CompareText}
  1668. \Declaration
  1669. Function CompareText(const S1, S2: string): integer;
  1670. \Description
  1671. \Errors
  1672. \SeeAlso
  1673. \end{function}
  1674. \begin{procedurel}{DisposeStr}{DisposeStrSys}
  1675. \Declaration
  1676. Procedure DisposeStr(S: PString);
  1677. \Description
  1678. \Errors
  1679. \SeeAlso
  1680. \end{procedurel}
  1681. \begin{function}{FloatToStr}
  1682. \Declaration
  1683. Function FloatToStr(Value: Extended): String;
  1684. \Description
  1685. \Errors
  1686. \SeeAlso
  1687. \end{function}
  1688. \begin{function}{FloatToStrF}
  1689. \Declaration
  1690. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  1691. \Description
  1692. \Errors
  1693. \SeeAlso
  1694. \end{function}
  1695. \begin{procedure}{FmtStr}
  1696. \Declaration
  1697. Procedure (Var Res: String; Const Fmt : String; Const args: Array of const);
  1698. \Description
  1699. \Errors
  1700. \SeeAlso
  1701. \end{procedure}
  1702. \begin{function}{Format}
  1703. \Declaration
  1704. Function Format(Const Fmt : String; const Args : Array of const) : String;
  1705. \Description
  1706. \Errors
  1707. \SeeAlso
  1708. \end{function}
  1709. \begin{function}{FormatBuf}
  1710. \Declaration
  1711. Function FormatBuf(Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const) : Cardinal;
  1712. \Description
  1713. \Errors
  1714. \SeeAlso
  1715. \end{function}
  1716. \begin{function}{IntToHex}
  1717. \Declaration
  1718. Function IntToHex(Value: integer; Digits: integer): string;
  1719. \Description
  1720. \Errors
  1721. \SeeAlso
  1722. \end{function}
  1723. \begin{function}{IntToStr}
  1724. \Declaration
  1725. Function IntToStr(Value: integer): string;
  1726. \Description
  1727. \Errors
  1728. \SeeAlso
  1729. \end{function}
  1730. \begin{function}{IsValidIdent}
  1731. \Declaration
  1732. Function IsValidIdent(const Ident: string): boolean;
  1733. \Description
  1734. \Errors
  1735. \SeeAlso
  1736. \end{function}
  1737. \begin{function}{LeftStr}
  1738. \Declaration
  1739. Function LeftStr(const S: string; Count: integer): string;
  1740. \Description
  1741. \Errors
  1742. \SeeAlso
  1743. \end{function}
  1744. \begin{function}{LoadStr}
  1745. \Declaration
  1746. Function LoadStr(Ident: integer): string;
  1747. \Description
  1748. \Errors
  1749. \SeeAlso
  1750. \end{function}
  1751. \begin{function}{LowerCase}
  1752. \Declaration
  1753. Function LowerCase(const s: string): string;
  1754. \Description
  1755. \Errors
  1756. \SeeAlso
  1757. \end{function}
  1758. \begin{functionl}{NewStr}{NewStrSys}
  1759. \Declaration
  1760. Function NewStr(const S: string): PString;
  1761. \Description
  1762. \Errors
  1763. \SeeAlso
  1764. \end{functionl}
  1765. \begin{function}{QuotedStr}
  1766. \Declaration
  1767. Function QuotedStr(const S: string): string;
  1768. \Description
  1769. \Errors
  1770. \SeeAlso
  1771. \end{function}
  1772. \begin{function}{RightStr}
  1773. \Declaration
  1774. Function RightStr(const S: string; Count: integer): string;
  1775. \Description
  1776. \Errors
  1777. \SeeAlso
  1778. \end{function}
  1779. \begin{function}{StrFmt}
  1780. \Declaration
  1781. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  1782. \Description
  1783. \Errors
  1784. \SeeAlso
  1785. \end{function}
  1786. \begin{function}{StrLFmt}
  1787. \Declaration
  1788. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  1789. \Description
  1790. \Errors
  1791. \SeeAlso
  1792. \end{function}
  1793. \begin{function}{StrToInt}
  1794. \Declaration
  1795. Function StrToInt(const s: string): integer;
  1796. \Description
  1797. \Errors
  1798. \SeeAlso
  1799. \end{function}
  1800. \begin{function}{StrToIntDef}
  1801. \Declaration
  1802. Function StrToIntDef(const S: string; Default: integer): integer;
  1803. \Description
  1804. \Errors
  1805. \SeeAlso
  1806. \end{function}
  1807. \begin{function}{Trim}
  1808. \Declaration
  1809. Function Trim(const S: string): string;
  1810. \Description
  1811. \Errors
  1812. \SeeAlso
  1813. \end{function}
  1814. \begin{function}{TrimLeft}
  1815. \Declaration
  1816. Function TrimLeft(const S: string): string;
  1817. \Description
  1818. \Errors
  1819. \SeeAlso
  1820. \end{function}
  1821. \begin{function}{TrimRight}
  1822. \Declaration
  1823. Function TrimRight(const S: string): string;
  1824. \Description
  1825. \Errors
  1826. \SeeAlso
  1827. \end{function}
  1828. \begin{function}{UpperCase}
  1829. \Declaration
  1830. Function UpperCase(const s: string): string;
  1831. \Description
  1832. \Errors
  1833. \SeeAlso
  1834. \end{function}
  1835. *** Modified files in JOE when it aborted on Wed May 26 13:43:43 1999
  1836. *** JOE was aborted because the terminal closed
  1837. *** File '(Unnamed)'
  1838. sysutils.tex
  1839. *** File 'sysutils.tex'
  1840. %
  1841. % $Id$
  1842. % This file is part of the FPC documentation.
  1843. % Copyright (C) 1999, by Michael Van Canneyt
  1844. %
  1845. % The FPC documentation is free text; you can redistribute it and/or
  1846. % modify it under the terms of the GNU Library General Public License as
  1847. % published by the Free Software Foundation; either version 2 of the
  1848. % License, or (at your option) any later version.
  1849. %
  1850. % The FPC Documentation is distributed in the hope that it will be useful,
  1851. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  1852. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  1853. % Library General Public License for more details.
  1854. %
  1855. % You should have received a copy of the GNU Library General Public
  1856. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  1857. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  1858. % Boston, MA 02111-1307, USA.
  1859. %
  1860. \chapter{The SYSUTILS unit.}
  1861. This chapter describes the \file{sysutils} unit. The \var{sysutils} unit
  1862. was largely written by Gertjan Schouten, and completed by michael Van Canneyt.
  1863. It aims to be compatible to the Delphi sysutils unit, but in contrast with
  1864. the latter, it is designed to work on multiple platforms.
  1865. This chapter starts out with a definition of all types and constants
  1866. that are defined, followed by a complete explanation of each function.
  1867. \section{Constants and types}
  1868. The following general-purpose constants are defined:
  1869. \begin{verbatim}
  1870. const
  1871. SecsPerDay = 24 * 60 * 60; // Seconds and milliseconds per day
  1872. MSecsPerDay = SecsPerDay * 1000;
  1873. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  1874. Eoln = #10;
  1875. \end{verbatim}
  1876. The following types are used frequently in date and time functions.
  1877. They are the same on all platforms.
  1878. \begin{verbatim}
  1879. type
  1880. TSystemTime = record
  1881. Year, Month, Day: word;
  1882. Hour, Minute, Second, MilliSecond: word;
  1883. end ;
  1884. TDateTime = double;
  1885. TTimeStamp = record
  1886. Time: integer; { Number of milliseconds since midnight }
  1887. Date: integer; { One plus number of days since 1/1/0001 }
  1888. end ;
  1889. \end{verbatim}
  1890. The following type is used in the \seef{FindFirst},\seef{FindNext}
  1891. and \seepl{FindClose}{FindCloseSys} functions. The \var{win32} version differs from
  1892. the other versions. If code is to be portable, that part shouldn't
  1893. be used.
  1894. \begin{verbatim}
  1895. Type
  1896. THandle = Longint;
  1897. TSearchRec = Record
  1898. Time,Size, Attr : Longint;
  1899. Name : TFileName;
  1900. ExcludeAttr : Longint;
  1901. FindHandle : THandle;
  1902. {$ifdef Win32}
  1903. FindData : TWin32FindData;
  1904. {$endif}
  1905. end;
  1906. \end{verbatim}
  1907. The following constants are file-attributes that need to be matched in the
  1908. findfirst call.
  1909. \begin{verbatim}
  1910. Const
  1911. faReadOnly = $00000001;
  1912. faHidden = $00000002;
  1913. faSysFile = $00000004;
  1914. faVolumeId = $00000008;
  1915. faDirectory = $00000010;
  1916. faArchive = $00000020;
  1917. faAnyFile = $0000003f;
  1918. \end{verbatim}
  1919. The following constants can be used in the \seef{FileOpen} call.
  1920. \begin{verbatim}
  1921. Const
  1922. fmOpenRead = $0000;
  1923. fmOpenWrite = $0001;
  1924. fmOpenReadWrite = $0002;
  1925. \end{verbatim}
  1926. The following constants can be used in the \seef{FileSeek} call.
  1927. \begin{verbatim}
  1928. Const
  1929. fsFromBeginning = 0;
  1930. fsFromCurrent = 1;
  1931. fsFromEnd = 2;
  1932. \end{verbatim}
  1933. The following variables are used in the case translation routines.
  1934. \begin{verbatim}
  1935. type
  1936. TCaseTranslationTable = array[0..255] of char;
  1937. var
  1938. UpperCaseTable: TCaseTranslationTable;
  1939. LowerCaseTable: TCaseTranslationTable;
  1940. \end{verbatim}
  1941. The initialization code of the \file{sysutils} unit fills these
  1942. tables with the appropriate values. For the win32 and go32v2
  1943. versions, this information is obtained from the operating system.
  1944. The following constants control the formatting of dates.
  1945. For the Win32 version of the \file{sysutils} unit, these
  1946. constants are set according to the internationalization
  1947. settings of Windows by the initialization code of the unit.
  1948. \begin{verbatim}
  1949. Const
  1950. DateSeparator: char = '-';
  1951. ShortDateFormat: string = 'd/m/y';
  1952. LongDateFormat: string = 'dd" "mmmm" "yyyy';
  1953. ShortMonthNames: array[1..12] of string[128] =
  1954. ('Jan','Feb','Mar','Apr','May','Jun',
  1955. 'Jul','Aug','Sep','Oct','Nov','Dec');
  1956. LongMonthNames: array[1..12] of string[128] =
  1957. ('January','February','March','April',
  1958. 'May','June','July','August',
  1959. 'September','October','November','December');
  1960. ShortDayNames: array[1..7] of string[128] =
  1961. ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  1962. LongDayNames: array[1..7] of string[128] =
  1963. ('Sunday','Monday','Tuesday','Wednesday',
  1964. 'Thursday','Friday','Saturday');
  1965. \end{verbatim}
  1966. The following constants control the formatting of times.
  1967. For the Win32 version of the \file{sysutils} unit, these
  1968. constants are set according to the internationalization
  1969. settings of Windows by the initialization code of the unit.
  1970. \begin{verbatim}
  1971. Const
  1972. ShortTimeFormat: string = 'hh:nn';
  1973. LongTimeFormat: string = 'hh:nn:ss';
  1974. TimeSeparator: char = ':';
  1975. TimeAMString: string[7] = 'AM';
  1976. TimePMString: string[7] = 'PM';
  1977. \end{verbatim}
  1978. The following constants control the formatting of currencies
  1979. and numbers. For the Win32 version of the \file{sysutils} unit,
  1980. these constants are set according to the internationalization
  1981. settings of Windows by the initialization code of the unit.
  1982. \begin{verbatim}
  1983. Const
  1984. DecimalSeparator : Char = '.';
  1985. ThousandSeparator : Char = ',';
  1986. CurrencyDecimals : Byte = 2;
  1987. CurrencyString : String[7] = '$';
  1988. { Format to use when formatting currency :
  1989. 0 = $1 1 = 1$ 2 = $ 1 3 = 1 $
  1990. 4 = Currency string replaces decimal indicator.
  1991. e.g. 1$50
  1992. }
  1993. CurrencyFormat : Byte = 1;
  1994. { Same as above, only for negative currencies:
  1995. 0 = ($1)
  1996. 1 = -$1
  1997. 2 = $-1
  1998. 3 = $1-
  1999. 4 = (1$)
  2000. 5 = -1$
  2001. 6 = 1-$
  2002. 7 = 1$-
  2003. 8 = -1 $
  2004. 9 = -$ 1
  2005. 10 = $ 1-
  2006. }
  2007. NegCurrFormat : Byte = 5;
  2008. \end{verbatim}
  2009. The following types are used in various string functions.
  2010. \begin{verbatim}
  2011. type
  2012. PString = ^String;
  2013. TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  2014. \end{verbatim}
  2015. The following constants are used in the file name handling routines. Do not
  2016. use a slash of backslash character directly as a path separator; instead
  2017. use the \var{OsDirSeparator} character.
  2018. \begin{verbatim}
  2019. Const
  2020. DirSeparators : set of char = ['/','\'];
  2021. {$ifdef Linux}
  2022. OSDirSeparator = '/';
  2023. {$else}
  2024. OsDirSeparator = '\';
  2025. {$endif}
  2026. \end{verbatim}
  2027. \section{Date and time functions}
  2028. \subsection{Date and time formatting characters}
  2029. \label{se:formatchars}
  2030. Various date and time formatting routines accept a format string.
  2031. to format the date and or time. The following characters can be used
  2032. to control the date and time formatting:
  2033. \begin{description}
  2034. \item[c] : shortdateformat + ' ' + shorttimeformat
  2035. \item[d] : day of month
  2036. \item[dd] : day of month (leading zero)
  2037. \item[ddd] : day of week (abbreviation)
  2038. \item[dddd] : day of week (full)
  2039. \item[ddddd] : shortdateformat
  2040. \item[dddddd] : longdateformat
  2041. \item[m] : month
  2042. \item[mm] : month (leading zero)
  2043. \item[mmm] : month (abbreviation)
  2044. \item[mmmm] : month (full)
  2045. \item[y] : year (four digits)
  2046. \item[yy] : year (two digits)
  2047. \item[yyyy] : year (with century)
  2048. \item[h] : hour
  2049. \item[hh] : hour (leading zero)
  2050. \item[n] : minute
  2051. \item[nn] : minute (leading zero)
  2052. \item[s] : second
  2053. \item[ss] : second (leading zero)
  2054. \item[t] : shorttimeformat
  2055. \item[tt] : longtimeformat
  2056. \item[am/pm] : use 12 hour clock and display am and pm accordingly
  2057. \item[a/p] : use 12 hour clock and display a and p accordingly
  2058. \item[/] : insert date seperator
  2059. \item[:] : insert time seperator
  2060. \item["xx"] : literal text
  2061. \item['xx'] : literal text
  2062. \end{description}
  2063. \begin{type}{TDateTime}
  2064. \Declaration
  2065. TDateTime = Double;
  2066. \Description
  2067. Many functions return or require a \var{TDateTime} type, which contains
  2068. a date and time in encoded form. The date and time are converted to a double
  2069. as follows:
  2070. \end{type}
  2071. \begin{function}{Date}
  2072. \Declaration
  2073. Function Date: TDateTime;
  2074. \Description
  2075. \var{Date} returns the current date in \var{TDateTime} format.
  2076. For more information about the \var{TDateTime} type, see \seety{TDateTime}.
  2077. \Errors
  2078. None.
  2079. \SeeAlso
  2080. \seef{Time},\seef{Now}, \seety{TDateTime}.
  2081. \end{function}
  2082. \latex{\inputlisting{sysutex/ex1.pp}}
  2083. \html{\input{sysutex/ex1.tex}}
  2084. \begin{function}{DateTimeToFileDate}
  2085. \Declaration
  2086. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  2087. \Description
  2088. \var{DateTimeToFileDate} function converts a date/time indication in
  2089. \var{TDateTime} format to a filedate function, such as returned for
  2090. instance by the \seef{FileAge} function.
  2091. \Errors
  2092. None.
  2093. \SeeAlso
  2094. \seef{Time}, \seef{Date}, \seef{FileDateToDateTime},
  2095. \seep{DateTimeToSystemTime}, \seef{DateTimeToTimeStamp}
  2096. \end{function}
  2097. \latex{\inputlisting{sysutex/ex2.pp}}
  2098. \html{\input{sysutex/ex2.tex}}
  2099. \begin{function}{DateTimeToStr}
  2100. \Declaration
  2101. Function DateTimeToStr(DateTime: TDateTime): string;
  2102. \Description
  2103. \var{DateTimeToStr} returns a string representation of
  2104. \var{DateTime} using the formatting specified in
  2105. \var{ShortDateTimeFormat}. It corresponds to a call to
  2106. \var{FormatDateTime('c',DateTime)} (see \sees{formatchars}).
  2107. \Errors
  2108. None.
  2109. \SeeAlso
  2110. \seef{FormatDateTime}, \seety{TDateTime}.
  2111. \end{function}
  2112. \latex{\inputlisting{sysutex/ex3.pp}}
  2113. \html{\input{sysutex/ex3.tex}}
  2114. \begin{procedure}{DateTimeToString}
  2115. \Declaration
  2116. Procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  2117. \Description
  2118. \var{DateTimeToString} returns in \var{Result} a string representation of
  2119. \var{DateTime} using the formatting specified in \var{FormatStr}.
  2120. for a list of characters that can be used in the \var{FormatStr} formatting
  2121. string, see \sees{formatchars}.
  2122. \Errors
  2123. In case a wrong formatting character is found, an \var{EConvertError} is
  2124. raised.
  2125. \SeeAlso
  2126. \seef{FormatDateTime}, \sees{formatchars}.
  2127. \end{procedure}
  2128. \latex{\inputlisting{sysutex/ex4.pp}}
  2129. \html{\input{sysutex/ex4.tex}}
  2130. \begin{procedure}{DateTimeToSystemTime}
  2131. \Declaration
  2132. Procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  2133. \Description
  2134. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  2135. \var{TDateTime} format to a system time \var{SystemTime}.
  2136. \Errors
  2137. None.
  2138. \SeeAlso
  2139. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  2140. \seef{DateTimeToTimeStamp}
  2141. \end{procedure}
  2142. \latex{\inputlisting{sysutex/ex5.pp}}
  2143. \html{\input{sysutex/ex5.tex}}
  2144. \begin{function}{DateTimeToTimeStamp}
  2145. \Declaration
  2146. Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  2147. \Description
  2148. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  2149. \var{TDateTime} format to a \var{TTimeStamp} format.
  2150. \Errors
  2151. None.
  2152. \SeeAlso
  2153. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  2154. \seep{DateTimeToSystemTime}
  2155. \end{function}
  2156. \latex{\inputlisting{sysutex/ex6.pp}}
  2157. \html{\input{sysutex/ex6.tex}}
  2158. \begin{function}{DateToStr}
  2159. \Declaration
  2160. Function DateToStr(Date: TDateTime): string;
  2161. \Description
  2162. \var{DateToStr} converts \var{Date} to a string representation. It uses
  2163. \var{ShortDateFormat} as it's formatting string. It is hence completely
  2164. equivalent to a \var{FormatDateTime('ddddd', Date)}.
  2165. \Errors
  2166. None.
  2167. \SeeAlso
  2168. \seef{TimeToStr}, \seef{DateTimeToStr}, \seef{FormatDateTime},
  2169. \seef{StrToDate}
  2170. \end{function}
  2171. \latex{\inputlisting{sysutex/ex7.pp}}
  2172. \html{\input{sysutex/ex7.tex}}
  2173. \begin{function}{DayOfWeek}
  2174. \Declaration
  2175. Function DayOfWeek(DateTime: TDateTime): integer;
  2176. \Description
  2177. \var{DayOfWeek} returns the day of the week from \var{DateTime}.
  2178. \var{Sunday} is counted as day 1, \var{Saturday} is counted as
  2179. day 7. The result of \var{DayOfWeek} can serve as an index to
  2180. the \var{LongDayNames} constant array, to retrieve the name of
  2181. the day.
  2182. \Errors
  2183. None.
  2184. \SeeAlso
  2185. \seef{Date}, \seef{DateToStr}
  2186. \end{function}
  2187. \latex{\inputlisting{sysutex/ex8.pp}}
  2188. \html{\input{sysutex/ex8.tex}}
  2189. \begin{procedure}{DecodeDate}
  2190. \Declaration
  2191. Procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  2192. \Description
  2193. \var{DecodeDate} decodes the Year, Month and Day stored in \var{Date},
  2194. and returns them in the \var{Year}, \var{Month} and \var{Day} variables.
  2195. \Errors
  2196. None.
  2197. \SeeAlso
  2198. \seef{EncodeDate}, \seep{DecodeTime}.
  2199. \end{procedure}
  2200. \latex{\inputlisting{sysutex/ex9.pp}}
  2201. \html{\input{sysutex/ex9.tex}}
  2202. \begin{procedure}{DecodeTime}
  2203. \Declaration
  2204. Procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  2205. \Description
  2206. \var{DecodeDate} decodes the hours, minutes, second and milliseconds stored
  2207. in \var{Time}, and returns them in the \var{Hour}, \var{Minute} and
  2208. \var{Second} and \var{MilliSecond} variables.
  2209. \Errors
  2210. None.
  2211. \SeeAlso
  2212. \seef{EncodeTime}, \seep{DecodeDate}.
  2213. \end{procedure}
  2214. \latex{\inputlisting{sysutex/ex10.pp}}
  2215. \html{\input{sysutex/ex10.tex}}
  2216. \begin{function}{EncodeDate}
  2217. \Declaration
  2218. Function EncodeDate(Year, Month, Day :word): TDateTime;
  2219. \Description
  2220. \var{EncodeDate} encodes the \var{Year}, \var{Month} and \var{Day} variables to
  2221. a date in \var{TDateTime} format. It does the opposite of the
  2222. \seep{DecodeDate} procedure.
  2223. The parameters must lie withing valid ranges (boundaries included):
  2224. \begin{description}
  2225. \item[Year] must be between 1 and 9999.
  2226. \item[Month] must be within the range 1-12.
  2227. \item[Day] msut be between 1 and 31.
  2228. \end{description}
  2229. \Errors
  2230. In case one of the parameters is out of it's valid range, 0 is returned.
  2231. \SeeAlso
  2232. \seef{EncodeTime}, \seep{DecodeDate}.
  2233. \end{function}
  2234. \latex{\inputlisting{sysutex/ex11.pp}}
  2235. \html{\input{sysutex/ex11.tex}}
  2236. \begin{function}{EncodeTime}
  2237. \Declaration
  2238. Function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  2239. \Description
  2240. \var{EncodeTime} encodes the \var{Hour}, \var{Minute}, \var{Second},
  2241. \var{MilliSecond} variables to a \var{TDateTime} format result.
  2242. It does the opposite of the \seep{DecodeTime} procedure.
  2243. The parameters must have a valid range (boundaries included):
  2244. \begin{description}
  2245. \item[Hour] must be between 0 and 23.
  2246. \item[Minute,second] must both be between 0 and 59.
  2247. \item[Millisecond] must be between 0 and 999.
  2248. \end{description}
  2249. \Errors
  2250. In case one of the parameters is outside of it's valid range, 0 is returned.
  2251. \SeeAlso
  2252. \seef{EncodeDate}, \seep{DecodeTime}.
  2253. \end{function}
  2254. \latex{\inputlisting{sysutex/ex12.pp}}
  2255. \html{\input{sysutex/ex12.tex}}
  2256. \begin{function}{FileDateToDateTime}
  2257. \Declaration
  2258. Function FileDateToDateTime(Filedate : Longint) : TDateTime;
  2259. \Description
  2260. \var{FileDateToDateTime} converts the date/time encoded in \var{filedate}
  2261. to a \var{TDateTime} encoded form. It can be used to convert date/time values
  2262. returned by the \seef{FileAge} or \seef{FindFirst}/\seef{FindNext}
  2263. functions to \var{TDateTime} form.
  2264. \Errors
  2265. None.
  2266. \SeeAlso
  2267. \seef{DateTimeToFileDate}
  2268. \end{function}
  2269. \latex{\inputlisting{sysutex/ex13.pp}}
  2270. \html{\input{sysutex/ex13.tex}}
  2271. \begin{function}{FormatDateTime}
  2272. \Declaration
  2273. Function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  2274. \Description
  2275. \var{FormatDateTime} formats the date and time encoded in \var{DateTime}
  2276. according to the formatting given in \var{FormatStr}. The complete list
  2277. of formatting characters can be found in \sees{formatchars}.
  2278. \Errors
  2279. On error (such as an invalid character in the formatting string), and
  2280. \var{EConvertError} exception is raised.
  2281. \SeeAlso
  2282. \seef{DateTimeToStr}, \seef{DateToStr}, \seef{TimeToStr},
  2283. \seef{StrToDateTime}
  2284. \end{function}
  2285. \latex{\inputlisting{sysutex/ex14.pp}}
  2286. \html{\input{sysutex/ex14.tex}}
  2287. \begin{function}{IncMonth}
  2288. \Declaration
  2289. Function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  2290. \Description
  2291. \var{IncMonth} increases the month number in \var{DateTime} with
  2292. \var{NumberOfMonths}. It wraps the result as to get a month between 1 and
  2293. 12, and updates the year accordingly. \var{NumberOfMonths} can be negative,
  2294. and can be larger than 12 (in absolute value).
  2295. \Errors
  2296. None.
  2297. \SeeAlso
  2298. \seef{Date}, \seef{Time}, \seef{Now}
  2299. \end{function}
  2300. \latex{\inputlisting{sysutex/ex15.pp}}
  2301. \html{\input{sysutex/ex15.tex}}
  2302. \begin{function}{IsLeapYear}
  2303. \Declaration
  2304. Function IsLeapYear(Year: Word): boolean;
  2305. \Description
  2306. \var{IsLeapYear} returns \var{True} if \var{Year} is a leap year,
  2307. \var{False} otherwise.
  2308. \Errors
  2309. None.
  2310. \SeeAlso
  2311. \seef{IncMonth}, \seef{Date}
  2312. \end{function}
  2313. \latex{\inputlisting{sysutex/ex16.pp}}
  2314. \html{\input{sysutex/ex16.tex}}
  2315. \begin{function}{MSecsToTimeStamp}
  2316. \Declaration
  2317. Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  2318. \Description
  2319. \var{MSecsTiTimeStamp} converts the given number of milliseconds to
  2320. a \var{TTimeStamp} date/time notation.
  2321. Use \var{TTimeStamp} variables if you need to keep very precise track of
  2322. time.
  2323. \Errors
  2324. None.
  2325. \SeeAlso
  2326. \seef{TimeStampToMSecs}, \seef{DateTimeToTimeStamp},
  2327. \end{function}
  2328. \latex{\inputlisting{sysutex/ex17.pp}}
  2329. \html{\input{sysutex/ex17.tex}}
  2330. \begin{function}{Now}
  2331. \Declaration
  2332. Function Now: TDateTime;
  2333. \Description
  2334. \var{Now} returns the current date and time. It is equivalent to
  2335. \var{Date+Time}.
  2336. \Errors
  2337. None.
  2338. \SeeAlso
  2339. \seef{Date}, \seef{Time}
  2340. \end{function}
  2341. \latex{\inputlisting{sysutex/ex18.pp}}
  2342. \html{\input{sysutex/ex18.tex}}
  2343. \begin{function}{StrToDate}
  2344. \Declaration
  2345. Function StrToDate(const S: string): TDateTime;
  2346. \Description
  2347. \var{StrToDate} converts the string \var{S} to a \var{TDateTime} date
  2348. value. The Date must consist of 1 to three digits, separated by the
  2349. \var{DateSeparator} character. If two numbers are given, they
  2350. are supposed to form the day and month of the current year. If only
  2351. one number is given, it is supposed to represent the day of the
  2352. current month. (This is \em{not} supported in Delphi)
  2353. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  2354. \var{ShortDateFormat} variable.
  2355. \Errors
  2356. On error (e.g. an invalid date or invalid character),
  2357. an \var{EConvertError} exception is raised.
  2358. \SeeAlso
  2359. \seef{StrToTime}, \seef{DateToStr}n \seef{TimeToStr}.
  2360. \end{function}
  2361. \latex{\inputlisting{sysutex/ex19.pp}}
  2362. \html{\input{sysutex/ex19.tex}}
  2363. \begin{function}{StrToDateTime}
  2364. \Declaration
  2365. Function StrToDateTime(const S: string): TDateTime;
  2366. \Description
  2367. \var{StrToDateTime} converts the string \var{S} to a \var{TDateTime} date
  2368. and time value. The Date must consist of 1 to three digits, separated by the
  2369. \var{DateSeparator} character. If two numbers are given, they
  2370. are supposed to form the day and month of the current year. If only
  2371. one number is given, it is supposed to represent the day of the
  2372. current month. (This is \em{not} supported in Delphi)
  2373. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  2374. \var{ShortDateFormat} variable.
  2375. \Errors
  2376. On error (e.g. an invalid date or invalid character),
  2377. an \var{EConvertError} exception is raised.
  2378. \SeeAlso
  2379. \seef{StrToDate}, \seef{StrToTime}, \seef{DateTimeToStr}
  2380. \end{function}
  2381. \latex{\inputlisting{sysutex/ex20.pp}}
  2382. \html{\input{sysutex/ex20.tex}}
  2383. \begin{function}{StrToTime}
  2384. \Declaration
  2385. Function StrToTime(const S: string): TDateTime;
  2386. \Description
  2387. \var{StrToTime} converts the string \var{S} to a \var{TDateTime} time
  2388. value. The time must consist of 1 to 4 digits, separated by the
  2389. \var{TimeSeparator} character. If two numbers are given, they
  2390. are supposed to form the hour and minutes.
  2391. \Errors
  2392. On error (e.g. an invalid date or invalid character),
  2393. an \var{EConvertError} exception is raised.
  2394. \SeeAlso
  2395. \seef{StrToDate}, \seef{StrToDateTime}, \seef{TimeToStr}
  2396. \end{function}
  2397. \latex{\inputlisting{sysutex/ex21.pp}}
  2398. \html{\input{sysutex/ex21.tex}}
  2399. \begin{function}{SystemTimeToDateTime}
  2400. \Declaration
  2401. Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  2402. \Description
  2403. \var{SystemTimeToDateTime} converts a \var{TSystemTime} record to a
  2404. \var{TDateTime} style date/time indication.
  2405. \Errors
  2406. None.
  2407. \SeeAlso
  2408. \seep{DateTimeToSystemTime}
  2409. \end{function}
  2410. \latex{\inputlisting{sysutex/ex22.pp}}
  2411. \html{\input{sysutex/ex22.tex}}
  2412. \begin{function}{Time}
  2413. \Declaration
  2414. Function Time: TDateTime;
  2415. \Description
  2416. \var{Time} returns the current time in \var{TDateTime} format. The date
  2417. part of the \var{TDateTimeValue} is set to zero.
  2418. \Errors
  2419. None.
  2420. \SeeAlso
  2421. \seef{Now}, \seef{Date}
  2422. \end{function}
  2423. \latex{\inputlisting{sysutex/ex23.pp}}
  2424. \html{\input{sysutex/ex23.tex}}
  2425. \begin{function}{TimeStampToDateTime}
  2426. \Declaration
  2427. Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  2428. \Description
  2429. \var{TimeStampToDateTime} converts \var{TimeStamp} to a \var{TDateTime}
  2430. format variable. It is the inverse operation of \seef{DateTimeToTimeStamp}.
  2431. \Errors
  2432. None.
  2433. \SeeAlso
  2434. \seef{DateTimeToTimeStamp}, \seef{TimeStampToMSecs}
  2435. \end{function}
  2436. \latex{\inputlisting{sysutex/ex24.pp}}
  2437. \html{\input{sysutex/ex24.tex}}
  2438. \begin{function}{TimeStampToMSecs}
  2439. \Declaration
  2440. Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  2441. \Description
  2442. \var{TimeStampToMSecs} converts {TimeStamp} to the number of seconds
  2443. since \var{1/1/0001}.
  2444. Use \var{TTimeStamp} variables if you need to keep very precise track of
  2445. time.
  2446. \Errors
  2447. None.
  2448. \SeeAlso
  2449. \seef{MSecsToTimeStamp}, \seef{TimeStampToDateTime}
  2450. \end{function}
  2451. For an example, see \seef{MSecsToTimeStamp}.
  2452. \begin{function}{TimeToStr}
  2453. \Declaration
  2454. Function TimeToStr(Time: TDateTime): string;
  2455. \Description
  2456. \var{TimeToStr} converts the time in \var{Time} to a string. It uses
  2457. the \var{ShortTimeFormat} variable to see what formatting needs to be
  2458. applied. It is therefor entirely equivalent to a
  2459. \var{FormatDateTime('t',Time)} call.
  2460. \Errors
  2461. None.
  2462. \SeeAlso
  2463. \end{function}
  2464. \latex{\inputlisting{sysutex/ex25.pp}}
  2465. \html{\input{sysutex/ex25.tex}}
  2466. \section{Disk functions}
  2467. \begin{functionl}{AddDisk (Linux only)}{AddDisk}
  2468. \Declaration
  2469. Function AddDisk (Const PAth : String) : Longint;
  2470. \Description
  2471. On Linux both the \seef{DiskFree} and \seef{DiskSize} functions need a
  2472. file on the specified drive, since is required for the statfs system call.
  2473. These filenames are set in drivestr[0..26], and the first 4 have been
  2474. preset to :
  2475. \begin{description}
  2476. \item[Disk 0] \var{'.'} default drive - hence current directory is used.
  2477. \item[Disk 1] \var{'/fd0/.'} floppy drive 1.
  2478. \item[Disk 2] \var{'/fd1/.'} floppy drive 2.
  2479. \item[Disk 3] \var{'/'} \file{C:} equivalent of DOS is the root partition.
  2480. \end{description}
  2481. Drives 4..26 can be set by your own applications with the \var{AddDisk} call.
  2482. The \var{AddDisk} call adds \var{Path} to the names of drive files, and
  2483. returns the number of the disk that corresponds to this drive. If you
  2484. add more than 21 drives, the count is wrapped to 4.
  2485. \Errors
  2486. None.
  2487. \SeeAlso
  2488. \seefl{DiskFree}{DiskFreeSys}, \seefl{DiskSize}{DiskSizeSys}
  2489. \end{functionl}
  2490. \begin{function}{CreateDir}
  2491. \Declaration
  2492. Function CreateDir(Const NewDir : String) : Boolean;
  2493. \Description
  2494. \var{CreateDir} creates a new directory with name \var{NewDir}.
  2495. If the directory doesn't contain an absolute path, then the directory is
  2496. created below the current working directory.
  2497. The function returns \var{True} if the directory was successfully
  2498. created, \var{False} otherwise.
  2499. \Errors
  2500. In case of an error, the function returns \var{False}.
  2501. \SeeAlso
  2502. \seef{RemoveDir}
  2503. \end{function}
  2504. \latex{\inputlisting{sysutex/ex26.pp}}
  2505. \html{\input{sysutex/ex26.tex}}
  2506. \begin{functionl}{DiskFree}{DiskFreeSys}
  2507. \Declaration
  2508. Function DiskFree(Drive : Byte) : Longint;
  2509. \Description
  2510. \var{DiskFree} returns the free space (in bytes) on disk \var{Drive}.
  2511. Drive is the number of the disk drive:
  2512. \begin{description}
  2513. \item[0] for the current drive.
  2514. \item[1] for the first floppy drive.
  2515. \item[2] for the second floppy drive.
  2516. \item[3] for the first hard-disk parttion.
  2517. \item[4-26] for all other drives and partitions.
  2518. \end{description}
  2519. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  2520. different than the \dos one, since the filesystem is seen as one big
  2521. directory tree. For this reason, the \var{DiskFree} and \seef{DiskSize}
  2522. functions must be mimicked using filenames that reside on the partitions.
  2523. For more information, see \seef{AddDisk}
  2524. \Errors
  2525. On error, \var{-1} is returned.
  2526. \SeeAlso
  2527. \seefl{DiskSize}{DiskSizeSys}, \seef{AddDisk}
  2528. \end{functionl}
  2529. \latex{\inputlisting{sysutex/ex27.pp}}
  2530. \html{\input{sysutex/ex27.tex}}
  2531. \begin{functionl}{DiskSize}{DiskSizeSys}
  2532. \Declaration
  2533. Function DiskSize(Drive : Byte) : Longint;
  2534. \Description
  2535. \var{DiskSize} returns the size (in bytes) of disk \var{Drive}.
  2536. Drive is the number of the disk drive:
  2537. \begin{description}
  2538. \item[0] for the current drive.
  2539. \item[1] for the first floppy drive.
  2540. \item[2] for the second floppy drive.
  2541. \item[3] for the first hard-disk parttion.
  2542. \item[4-26] for all other drives and partitions.
  2543. \end{description}
  2544. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  2545. different than the \dos one, since the filesystem is seen as one big
  2546. directory tree. For this reason, the \seef{DiskFree} and \var{DiskSize}
  2547. functions must be mimicked using filenames that reside on the partitions.
  2548. For more information, see \seef{AddDisk}
  2549. \Errors
  2550. On error, \var{-1} is returned.
  2551. \SeeAlso
  2552. \seefl{DiskFree}{DiskFreeSys}, \seef{AddDisk}
  2553. \end{functionl}
  2554. For an example, see \seefl{DiskFree}{DiskFreeSys}.
  2555. \begin{function}{GetCurrentDir}
  2556. \Declaration
  2557. Function GetCurrentDir : String;
  2558. \Description
  2559. \var{GetCurrentDir} returns the current working directory.
  2560. \Errors
  2561. None.
  2562. \SeeAlso
  2563. \seef{SetCurrentDir}, \seef{DiskFree}, \seef{DiskSize}
  2564. \end{function}
  2565. \latex{\inputlisting{sysutex/ex28.pp}}
  2566. \html{\input{sysutex/ex28.tex}}
  2567. \begin{function}{RemoveDir}
  2568. \Declaration
  2569. Function RemoveDir(Const Dir : String) : Boolean;
  2570. \Description
  2571. \var{RemoveDir} removes directory \var{Dir} from the disk.
  2572. If the directory is not absolue, it is appended to the current working
  2573. directory.
  2574. \Errors
  2575. In case of error (e.g. the directory isn't empty) the function returns
  2576. \var{False}. If successful, \var{True} is returned.
  2577. \SeeAlso
  2578. \end{function}
  2579. For an example, see \seef{CreateDir}.
  2580. \begin{function}{SetCurrentDir}
  2581. \Declaration
  2582. Function SetCurrentDir(Const NewDir : String) : Boolean;
  2583. \Description
  2584. \var{SetCurrentDir} sets the current working directory of your program
  2585. to \var{NewDir}. It returns \var{True} if the function was successfull,
  2586. \var{False} otherwise.
  2587. \Errors
  2588. In case of error, \var{False} is returned.
  2589. \SeeAlso
  2590. \seef{GetCurrentDir}
  2591. \end{function}
  2592. \latex{\inputlisting{sysutex/ex29.pp}}
  2593. \html{\input{sysutex/ex29.tex}}
  2594. \section{File handling functions}
  2595. \begin{function}{ChangeFileExt}
  2596. \Declaration
  2597. Function ChangeFileExt(const FileName, Extension: string): string;
  2598. \Description
  2599. \var{ChangeFileExt} changes the file extension in \var{FileName} to
  2600. \var{Extension}.
  2601. The extension \var{Extension} includes the starting \var{.} (dot).
  2602. The previous extension of \var{FileName} are all characters after the
  2603. last \var{.}, the \var{.} character included.
  2604. If \var{FileName} doesn't have an extension, \var{Extension} is just
  2605. appended.
  2606. \Errors
  2607. None.
  2608. \SeeAlso
  2609. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExpandFileName}
  2610. \end{function}
  2611. \begin{function}{DeleteFile}
  2612. \Declaration
  2613. Function DeleteFile(Const FileName : String) : Boolean;
  2614. \Description
  2615. \var{DeleteFile} deletes file \var{FileName} from disk. The function
  2616. returns \var{True} if the file was successfully removed, \var{False}
  2617. otherwise.
  2618. \Errors
  2619. On error, \var{False} is returned.
  2620. \SeeAlso
  2621. \seef{FileCreate}, \seef{FileExists}
  2622. \end{function}
  2623. \latex{\inputlisting{sysutex/ex31.pp}}
  2624. \html{\input{sysutex/ex31.tex}}
  2625. \begin{procedure}{DoDirSeparators}
  2626. \Declaration
  2627. Procedure DoDirSeparators(Var FileName : String);
  2628. \Description
  2629. This function replaces all directory separators \var{'\' and '/'}
  2630. to the directory separator character for the current system.
  2631. \Errors
  2632. None.
  2633. \SeeAlso
  2634. \seef{ExtractFileName}, \seef{ExtractFilePath}
  2635. \end{procedure}
  2636. \latex{\inputlisting{sysutex/ex32.pp}}
  2637. \html{\input{sysutex/ex32.tex}}
  2638. \begin{function}{ExpandFileName}
  2639. \Declaration
  2640. Function ExpandFileName(Const FileName : string): String;
  2641. \Description
  2642. \var{ExpandFileName} expands the filename to an absolute filename.
  2643. It changes all directory separator characters to the one appropriate for the
  2644. system first.
  2645. \Errors
  2646. None.
  2647. \SeeAlso
  2648. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2649. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2650. \end{function}
  2651. \latex{\inputlisting{sysutex/ex33.pp}}
  2652. \html{\input{sysutex/ex33.tex}}
  2653. \begin{function}{ExpandUNCFileName}
  2654. \Declaration
  2655. Function ExpandUNCFileName(Const FileName : string): String;
  2656. \Description
  2657. \var{ExpandUNCFileName} runs \seef{ExpandFileName} on \var{FileName}
  2658. and then attempts to replace the driveletter by the name of a shared disk.
  2659. \Errors
  2660. \SeeAlso
  2661. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2662. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2663. \end{function}
  2664. \begin{function}{ExtractFileDir}
  2665. \Declaration
  2666. Function ExtractFileDir(Const FileName : string): string;
  2667. \Description
  2668. \var{ExtractFileDir} returns only the directory part of \var{FileName},
  2669. not including a driveletter. The directory name has NO ending directory
  2670. separator, in difference with \seef{ExtractFilePath}.
  2671. \Errors
  2672. None.
  2673. \SeeAlso
  2674. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2675. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2676. \end{function}
  2677. \latex{\inputlisting{sysutex/ex34.pp}}
  2678. \html{\input{sysutex/ex34.tex}}
  2679. \begin{function}{ExtractFileDrive}
  2680. \Declaration
  2681. Function ExtractFileDrive(const FileName: string): string;
  2682. \Description
  2683. \var{Extract}
  2684. \Errors
  2685. \SeeAlso
  2686. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2687. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2688. \end{function}
  2689. For an example, see \seef{ExtractFileDir}.
  2690. \begin{function}{ExtractFileExt}
  2691. \Declaration
  2692. Function ExtractFileExt(const FileName: string): string;
  2693. \Description
  2694. \var{ExtractFileExt} returns the extension (including the
  2695. \var{.}(dot) character) of \var{FileName}.
  2696. \Errors
  2697. None.
  2698. \SeeAlso
  2699. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2700. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2701. \end{function}
  2702. For an example, see \seef{ExtractFileDir}.
  2703. \begin{function}{ExtractFileName}
  2704. \Declaration
  2705. Function ExtractFileName(const FileName: string): string;
  2706. \Description
  2707. \var{ExtractFileName} returns the filename part from \var{FileName}.
  2708. The filename consists of all characters after the last directory separator
  2709. character ('/' or '\') or drive letter.
  2710. The full filename can always be reconstucted by concatenating the result
  2711. of \seef{ExtractFilePath} and \var{ExtractFileName}.
  2712. \Errors
  2713. None.
  2714. \SeeAlso
  2715. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2716. \seef{ExtractFileDrive}, \seef{ExtractFileExt},\seef{ExtractRelativePath}
  2717. \end{function}
  2718. For an example, see \seef{ExtractFileDir}.
  2719. \begin{function}{ExtractFilePath}
  2720. \Declaration
  2721. Function ExtractFilePath(const FileName: string): string;
  2722. \Description
  2723. \var{ExtractFilePath} returns the path part (including driveletter) from
  2724. \var{FileName}. The path consists of all characters before the last
  2725. directory separator character ('/' or '\'), including the directory
  2726. separator itself.
  2727. In case there is only a drive letter, that will be returned.
  2728. The full filename can always be reconstucted by concatenating the result
  2729. of \var{ExtractFilePath} and \seef{ExtractFileName}.
  2730. \Errors
  2731. None.
  2732. \SeeAlso
  2733. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2734. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  2735. \end{function}
  2736. For an example, see \seef{ExtractFileDir}.
  2737. \begin{function}{ExtractRelativePath}
  2738. \Declaration
  2739. Function ExtractRelativePath(Const BaseName,DestNAme : String): String;
  2740. \Description
  2741. \var{ExtractRelativePath} constructs a relative path to go from
  2742. \var{BaseName} to \var{DestName}. If \var{DestName} is on another drive
  2743. (Not on Linux) then the whole \var{Destname} is returned.
  2744. {\em Note:} This function does not exist in the Delphi unit.
  2745. \Errors
  2746. None.
  2747. \SeeAlso
  2748. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  2749. \seef{ExtractFileDrive}, \seef{ExtractFileExt},
  2750. \end{function}
  2751. \latex{\inputlisting{sysutex/ex35.pp}}
  2752. \html{\input{sysutex/ex35.tex}}
  2753. \begin{function}{FileAge}
  2754. \Declaration
  2755. Function FileAge(Const FileName : String): Longint;
  2756. \Description
  2757. \var{FileAge} returns the last modification time of file \var{FileName}.
  2758. The FileDate format can be transformed to \var{TDateTime} format with the
  2759. \seef{FileDateToDateTime} function.
  2760. \Errors
  2761. In case of errors, \var{-1} is returned.
  2762. \SeeAlso
  2763. \seef{FileDateToDateTime}, \seef{FileExists}, \seef{FileGetAttr}
  2764. \end{function}
  2765. \latex{\inputlisting{sysutex/ex36.pp}}
  2766. \html{\input{sysutex/ex36.tex}}
  2767. \begin{procedure}{FileClose}
  2768. \Declaration
  2769. Procedure FileClose(Handle : Longint);
  2770. \Description
  2771. \var{FileClose} closes the file handle \var{Handle}. After this call,
  2772. attempting to read or write from the handle will result in an error.
  2773. \Errors
  2774. None.
  2775. \SeeAlso
  2776. \seef{FileCreate}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  2777. \seef{FileTruncate}, \seef{FileSeek}
  2778. \end{procedure}
  2779. For an example, see \seef{FileCreate}
  2780. \begin{function}{FileCreate}
  2781. \Declaration
  2782. Function FileCreate(Const FileName : String) : Longint;
  2783. \Description
  2784. \var{FileCreate} creates a new file with name \var{FileName} on the disk and
  2785. returns a file handle which can be used to read or write from the file with
  2786. the \seef{FileRead} and \seef{FileWrite} functions.
  2787. If a file with name \var{FileName} already existed on the disk, it is
  2788. overwritten.
  2789. \Errors
  2790. If an error occurs (e.g. disk full or non-existent path), the function
  2791. returns \var{-1}.
  2792. \SeeAlso
  2793. \seep{FileClose}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  2794. \seef{FileTruncate}, \seef{FileSeek}
  2795. \end{function}
  2796. \latex{\inputlisting{sysutex/ex37.pp}}
  2797. \html{\input{sysutex/ex37.tex}}
  2798. \begin{function}{FileExists}
  2799. \Declaration
  2800. Function FileExists(Const FileName : String) : Boolean;
  2801. \Description
  2802. \var{FileExists} returns \var{True} if a file with name \var{FileName}
  2803. exists on the disk, \var{False} otherwise.
  2804. \Errors
  2805. None.
  2806. \SeeAlso
  2807. \seef{FileAge}, \seef{FileGetAttr}, \seef{FileSetAttr}
  2808. \end{function}
  2809. \latex{\inputlisting{sysutex/ex38.pp}}
  2810. \html{\input{sysutex/ex38.tex}}
  2811. \begin{function}{FileGetAttr}
  2812. \Declaration
  2813. Function FileGetAttr(Const FileName : String) : Longint;
  2814. \Description
  2815. \var{FileGetAttr} returns the attribute settings of file
  2816. \var{FileName}. The attribute is a \var{OR}-ed combination
  2817. of the following constants:
  2818. \begin{description}
  2819. \item[faReadOnly] The file is read-only.
  2820. \item[faHidden] The file is hidden. (On \linux, this means that the filename
  2821. starts with a dot)
  2822. \item[faSysFile] The file is a system file (On \linux, this means that the
  2823. file is a character, block or FIFO file).
  2824. \item[faVolumeId] Volume Label. Not possible under \linux.
  2825. \item[faDirectory] File is a directory.
  2826. \item[faArchive] file is an archive. Not possible on \linux.
  2827. \end{description}
  2828. \Errors
  2829. In case of error, -1 is returned.
  2830. \SeeAlso
  2831. \seef{FileSetAttr}, \seef{FileAge}, \seef{FileGetDate}.
  2832. \end{function}
  2833. \latex{\inputlisting{sysutex/ex40.pp}}
  2834. \html{\input{sysutex/ex40.tex}}
  2835. \begin{function}{FileGetDate}
  2836. \Declaration
  2837. Function FileGetDate(Handle : Longint) : Longint;
  2838. \Description
  2839. \var{FileGetdate} returns the filetime of the opened file with filehandle
  2840. \var{Handle}. It is the same as \seef{FileAge}, with this difference that
  2841. \var{FileAge} only needs the file name, while \var{FilegetDate} needs an
  2842. open file handle.
  2843. \Errors
  2844. On error, -1 is returned.
  2845. \SeeAlso
  2846. \seef{FileAge}
  2847. \end{function}
  2848. \latex{\inputlisting{sysutex/ex39.pp}}
  2849. \html{\input{sysutex/ex39.tex}}
  2850. \begin{function}{FileOpen}
  2851. \Declaration
  2852. Function FileOpen(Const FileName : string; Mode : Integer) : Longint;
  2853. \Description
  2854. \var{FileOpen} opens a file with name \var{FileName} with mode \var{Mode}.
  2855. \var{Mode} can be one of the following constants:
  2856. \begin{description}
  2857. \item[fmOpenRead] The file is opened for reading.
  2858. \item[fmOpenWrite] The file is opened for writing.
  2859. \item[fmOpenReadWrite] The file is opened for reading and writing.
  2860. \end{description}
  2861. If the file has been successfully opened, it can be read from or written to
  2862. (depending on the \var{Mode} parameter) with the \seef{FileRead} and
  2863. \var{FileWrite} functions.
  2864. Remark that you cannot open a file if it doesn't exist yet, i.e. it will not
  2865. be created for you. If you want tp create a new file, or overwrite an old
  2866. one, use the \seef{FileCreate} function.
  2867. \Errors
  2868. On Error, -1 is returned.
  2869. \SeeAlso
  2870. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileRead},
  2871. \seef{FileTruncate}, \seef{FileSeek}
  2872. \end{function}
  2873. For an example, see \seef{FileRead}
  2874. \begin{function}{FileRead}
  2875. \Declaration
  2876. Function FileRead(Handle : Longint; Var Buffer; Count : longint) : Longint;
  2877. \Description
  2878. \var{FileRead} reads \var{Count} bytes from file-handle \var{Handle} and
  2879. stores them into \var{Buffer}. Buffer must be at least \var{Count} bytes
  2880. long. No checking on this is performed, so be careful not to overwrite any
  2881. memory. \var{Handle} must be the result of a \seef{FileOpen} call.
  2882. \Errors
  2883. On error, -1 is returned.
  2884. \SeeAlso
  2885. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen},
  2886. \seef{FileTruncate}, \seef{FileSeek}
  2887. \end{function}
  2888. For an example, see \seef{FileOpen}
  2889. \begin{function}{FileSearch}
  2890. \Declaration
  2891. Function FileSearch(Const Name, DirList : String) : String;
  2892. \Description
  2893. \var{FileSearch} looks for the file \var{Name} in \var{DirList}, where
  2894. dirlist is a list of directories, separated by semicolons or colons.
  2895. It returns the full filename of the first match found.
  2896. \Errors
  2897. On error, an empty string is returned.
  2898. \SeeAlso
  2899. \seef{ExpandFileName}, \seef{FindFirst}
  2900. \end{function}
  2901. \latex{\inputlisting{sysutex/ex41.pp}}
  2902. \html{\input{sysutex/ex41.tex}}
  2903. \begin{function}{FileSeek}
  2904. \Declaration
  2905. Function FileSeek(Handle,Offset,Origin : Longint) : Longint;
  2906. \Description
  2907. \var{FileSeek} sets the file pointer on position \var{Offset}, starting from
  2908. \var{Origin}. Origin can be one of the following values:
  2909. \begin{description}
  2910. \item[fsFromBeginning] \var{Offset} is relative to the first byte of the file. This
  2911. position is zero-based. i.e. the first byte is at offset 0.
  2912. \item[fsFromCurrent] \var{Offset} is relative to the current position.
  2913. \item[fsFromEnd] \var{Offset} is relative to the end of the file. This means
  2914. that \var{Offset} can only be zero or negative in this case.
  2915. \end{description}
  2916. If successfull, the function returns the new file position, relative to the
  2917. beginning of the file.
  2918. {\em Remark:} The abovementioned constants do not exist in Delphi.
  2919. \Errors
  2920. On error, -1 is returned.
  2921. \SeeAlso
  2922. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  2923. \seef{FileRead}, \seef{FileTruncate}
  2924. \end{function}
  2925. \latex{\inputlisting{sysutex/ex42.pp}}
  2926. \html{\input{sysutex/ex42.tex}}
  2927. For an example, see \seef{FileCreate}
  2928. \begin{functionl}{FileSetAttr (Not on Linux)}{FileSetAttr}
  2929. \Declaration
  2930. Function FileSetAttr(Const Filename : String; Attr: longint) : Longint;
  2931. \Description
  2932. \var{FileSetAttr} sets the attributes of \var{FileName} to \var{Attr}.
  2933. If the function was successful, 0 is returned, -1 otherwise.
  2934. \var{Attr} can be set to an OR-ed combination of the pre-defined
  2935. \var{faXXX} constants.
  2936. \Errors
  2937. On error, -1 is returned (always on linux).
  2938. \SeeAlso
  2939. \seef{FileGetAttr}, \seef{FileGetDate}, \seef{FileSetDate}.
  2940. \end{functionl}
  2941. \begin{functionl}{FileSetDate (Not on Linux)}{FileSetDate}
  2942. \Declaration
  2943. Function FileSetDate(Handle,Age : Longint) : Longint;
  2944. \Description
  2945. \var{FileSetDate} sets the file date of the file with handle \var{Handle}
  2946. to \var{Age}, where \var{Age} is a DOS date-and-time stamp value.
  2947. The function returns zero of successfull.
  2948. \Errors
  2949. On Linux, -1 is always returned, since this is impossible to implement.
  2950. On Windows and DOS, a negative error code is returned.
  2951. \SeeAlso
  2952. \end{functionl}
  2953. \begin{function}{FileTruncate}
  2954. \Declaration
  2955. Function FileTruncate(Handle,Size: Longint) : boolean;
  2956. \Description
  2957. \var{FileTruncate} truncates the file with handle \var{Handle} to
  2958. \var{Size} bytes. The file must have been opened for writing prior
  2959. to this call. The function returns \var{True} is successful, \var{False}
  2960. otherwise.
  2961. \Errors
  2962. On error, the function returns \var{False}.
  2963. \SeeAlso
  2964. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  2965. \seef{FileRead}, \seef{FileSeek}
  2966. \end{function}
  2967. For an example, see \seef{FileCreate}.
  2968. \begin{function}{FileWrite}
  2969. \Declaration
  2970. Function FileWrite(Handle : Longint; Var Buffer; Count : Longint) : Longint;
  2971. \Description
  2972. \var{FileWrite} writes \var{Count} bytes from \var{Buffer} to the file with
  2973. handle \var{Handle}. Prior to this call, the file must have been opened
  2974. for writing. \var{Buffer} must be at least \var{Count} bytes large, or
  2975. a memory access error may occur.
  2976. The function returns the number of bytes written, or -1 in case of an
  2977. error.
  2978. \Errors
  2979. In case of error, -1 is returned.
  2980. \SeeAlso
  2981. \seep{FileClose}, \seef{FileCreate}, \seef{FileOpen}
  2982. \seef{FileRead}, \seef{FileTruncate}, \seef{FileSeek}
  2983. \end{function}
  2984. For an example, see \seef{FileCreate}.
  2985. \begin{procedurel}{FindClose}{FindCloseSys}
  2986. \Declaration
  2987. Procedure FindClose(Var F : TSearchrec);
  2988. \Description
  2989. \var{FindClose} ends a series of \seef{FindFirst}/\seef{FindNext} calls,
  2990. and frees any memory used by these calls. It is {\em absolutely} necessary
  2991. to do this call, or huge memory losses may occur.
  2992. \Errors
  2993. None.
  2994. \SeeAlso
  2995. \seef{FindFirst}, \seef{FindNext}.
  2996. \end{procedurel}
  2997. For an example, see \seef{FindFirst}.
  2998. \begin{function}{FindFirst}
  2999. \Declaration
  3000. Function FindFirst(Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  3001. \Description
  3002. \var{FindFirst} looks for files that match the name (possibly with
  3003. wildcards) in \var{Path} and attributes \var{Attr}. It then fills up the
  3004. \var{Rslt} record with data gathered about the file. It returns 0 if a file
  3005. matching the specified criteria is found, a nonzero value (-1 on linux)
  3006. otherwise.
  3007. The \var{Rslt} record can be fed to subsequent calls to \var{FindNext}, in
  3008. order to find other files matching the specifications.
  3009. {\em remark:} A \var{FindFirst} call must {\em always} be followed by a
  3010. \seepl{FindClose}{FindCloseSys} call with the same \var{Rslt} record. Failure to do so will
  3011. result in memory loss.
  3012. \Errors
  3013. On error the function returns -1 on linux, a nonzero error code on Windows.
  3014. \SeeAlso
  3015. \seep{FindClose}{FindCloseSys}, \seef{FindNext}.
  3016. \end{function}
  3017. \latex{\inputlisting{sysutex/ex43.pp}}
  3018. \html{\input{sysutex/ex43.tex}}
  3019. \begin{function}{FindNext}
  3020. \Declaration
  3021. Function FindNext(Var Rslt : TSearchRec) : Longint;
  3022. \Description
  3023. \var{FindNext} finds a next occurrence of a search sequence initiated by
  3024. \var{FindFirst}. If another record matching the criteria in Rslt is found, 0
  3025. is returned, a nonzero constant is returned otherwise.
  3026. {\em remark:} The last \var{FindNext} call must {\em always} be followed by a
  3027. \var{FindClose} call with the same \var{Rslt} record. Failure to do so will
  3028. result in memory loss.
  3029. \Errors
  3030. On error (no more file is found), a nonzero constant is returned.
  3031. \SeeAlso
  3032. \seef{FindFirst}, \seep{FindClose}
  3033. \end{function}
  3034. For an example, see \seef{FindFirst}
  3035. \begin{function}{GetDirs}
  3036. \Declaration
  3037. Function GetDirs(Var DirName : String; Var Dirs : Array of pchar) : Longint;
  3038. \Description
  3039. \var{GetDirs} splits DirName in a null-byte separated list of directory names,
  3040. \var{Dirs} is an array of \var{PChars}, pointing to these directory names.
  3041. The function returns the number of directories found, or -1 if none were found.
  3042. DirName must contain only OSDirSeparator as Directory separator chars.
  3043. \Errors
  3044. None.
  3045. \SeeAlso
  3046. \seef{ExtractRelativePath}
  3047. \end{function}
  3048. \latex{\inputlisting{sysutex/ex45.pp}}
  3049. \html{\input{sysutex/ex45.tex}}
  3050. \begin{function}{RenameFile}
  3051. \Declaration
  3052. Function RenameFile(Const OldName, NewName : String) : Boolean;
  3053. \Description
  3054. \var{RenameFile} renames a file from \var{OldName} to \var{NewName}. The
  3055. function returns \var{True} if successful, \var{False} otherwise.
  3056. {\em Remark:} you cannot rename across disks or partitions.
  3057. \Errors
  3058. On Error, \var{False} is returned.
  3059. \SeeAlso
  3060. \seef{DeleteFile}
  3061. \end{function}
  3062. \latex{\inputlisting{sysutex/ex44.pp}}
  3063. \html{\input{sysutex/ex44.tex}}
  3064. \begin{function}{SetDirSeparators}
  3065. \Declaration
  3066. Function SetDirSeparators(Const FileName : String) : String;
  3067. \Description
  3068. \var{SetDirSeparators} returns \var{FileName} with all possible
  3069. DirSeparators replaced by \var{OSDirSeparator}.
  3070. \Errors
  3071. None.
  3072. \SeeAlso
  3073. \seef{ExpandFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir}
  3074. \end{function}
  3075. \latex{\inputlisting{sysutex/ex47.pp}}
  3076. \html{\input{sysutex/ex47.tex}}
  3077. \section{PChar functions}
  3078. \subsection{Introduction}
  3079. Most PChar functions are the same as their counterparts in the \file{STRINGS}
  3080. unit. The following functions are the same :
  3081. \begin{enumerate}
  3082. \item \seef{StrCat} : Concatenates two \var{PChar} strings.
  3083. \item \seef{StrComp} : Compares two \var{PChar} strings.
  3084. \item \seef{StrCopy} : Copies a \var{PChar} string.
  3085. \item \seef{StrECopy} : Copies a \var{PChar} string and returns a pointer to
  3086. the terminating null byte.
  3087. \item \seef{StrEnd} : Returns a pointer to the terminating null byte.
  3088. \item \seef{StrIComp} : Case insensitive compare of 2 \var{PChar} strings.
  3089. \item \seef{StrLCat} : Appends at most L characters from one \var{PChar} to
  3090. another \var{PChar}.
  3091. \item \seef{StrLComp} : Case sensitive compare of at most L characters of 2
  3092. \var{PChar} strings.
  3093. \item \seef{StrLCopy} : Copies at most L characters from one \var{PChar} to
  3094. another.
  3095. \item \seef{StrLen} : Returns the length (exclusive terminating null byte)
  3096. of a \var{PChar} string.
  3097. \item \seef{StrLIComp} : Case insensitive compare of at most L characters of 2
  3098. \var{PChar} strings.
  3099. \item \seef{StrLower} : Converts a \var{PChar} to all lowercase letters.
  3100. \item \seef{StrMove} : Moves one \var{PChar} to another.
  3101. \item \seef{StrNew} : Makes a copy of a \var{PChar} on the heap, and returns
  3102. a pointer to this copy.
  3103. \item \seef{StrPos} : Returns the position of one \var{PChar} string in
  3104. another?
  3105. \item \seef{StrRScan} : returns a pointer to the last occurrence of on
  3106. \var{PChar} string in another one.
  3107. \item \seef{StrScan} : returns a pointer to the first occurrence of on
  3108. \var{PChar} string in another one.
  3109. \item \seef{StrUpper} : Converts a \var{PChar} to all uppercase letters.
  3110. \end{enumerate}
  3111. The subsequent functions are different from their counterparts in
  3112. \file{STRINGS}, although the same examples can be used.
  3113. \begin{functionl}{StrAlloc}{StrAllocSys}
  3114. \Declaration
  3115. Function StrAlloc(Size: cardinal): PChar;
  3116. \Description
  3117. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  3118. terminating \var{\#0} included, and returns a pointer to it.
  3119. Additionally, \var{StrAlloc} allocates 4 extra bytes to store the size of
  3120. the allocated memory. Therefore this function is NOT compatible with the
  3121. \seef{StrAlloc} function of the \var{Strings} unit.
  3122. \Errors
  3123. None.
  3124. \SeeAlso
  3125. \seef{StrBufSize}, \seepl{StrDispose}{StrDisposeSys}, \seef{StrAlloc}
  3126. \end{functionl}
  3127. For an example, see \seef{StrBufSize}.
  3128. \begin{function}{StrBufSize}
  3129. \Declaration
  3130. Function StrBufSize(var Str: PChar): cardinal;
  3131. \Description
  3132. \var{StrBufSize} returns the memory allocated for \var{Str}. This function
  3133. ONLY gives the correct result if \var{Str} was allocated using
  3134. \seefl{StrAlloc}{StrAllocSys}.
  3135. \Errors
  3136. If no more memory is available, a runtime error occurs.
  3137. \SeeAlso
  3138. \seefl{StrAlloc}{StrAllocSys}.\seepl{StrDispose}{StrDisposeSys}.
  3139. \end{function}
  3140. \latex{\inputlisting{sysutex/ex46.pp}}
  3141. \html{\input{sysutex/ex46.tex}}
  3142. \begin{procedurel}{StrDispose}{StrDisposeSys}
  3143. \Declaration
  3144. Procedure StrDispose(var Str: PChar);
  3145. \Description
  3146. \var{StrDispose} frees any memory allocated for \var{Str}. This function
  3147. will only function correctly if \var{Str} has been allocated using
  3148. \seefl{StrAlloc}{StrAllocSys} from the \file{SYSUTILS} unit.
  3149. \Errors
  3150. If an invalid pointer is passed, or a pointer not allocated with
  3151. \var{StrAlloc}, an error may occur.
  3152. \SeeAlso
  3153. \seef{StrBufSize}, \seefl{StrAlloc}{StrAllocSys}, \seep{StrDispose}
  3154. \end{procedurel}
  3155. For an example, see \seef{StrBufSize}.
  3156. \begin{functionl}{StrPCopy}{StrPCopySys}
  3157. \Declaration
  3158. Function StrPCopy(Dest: PChar; Source: string): PChar;
  3159. \Description
  3160. \var{StrPCopy} Converts the Ansistring in \var{Source} to a Null-terminated
  3161. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  3162. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  3163. \Errors
  3164. No checking is performed to see whether \var{Dest} points to enough memory
  3165. to contain \var{Source}.
  3166. \SeeAlso
  3167. \seefl{StrPLCopy}{StrPLCopySys}, \seef{StrPCopy}
  3168. \end{functionl}
  3169. For an example, see \seef{StrPCopy}.
  3170. \begin{functionl}{StrPLCopy}{StrPLCopySys}
  3171. \Declaration
  3172. Function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar;
  3173. \Description
  3174. \var{StrPLCopy} Converts maximally \var{MaxLen} characters of the
  3175. Ansistring in \var{Source} to a Null-terminated string, and copies
  3176. it to \var{Dest}. \var{Dest} needs enough room to contain
  3177. the characters.
  3178. \Errors
  3179. No checking is performed to see whether \var{Dest} points to enough memory
  3180. to contain L characters of \var{Source}.
  3181. \Errors
  3182. \SeeAlso
  3183. \seefl{StrPCopy}{StrPCopySys}.
  3184. \end{functionl}
  3185. For an example, see \seef{StrPLCopy}.
  3186. \begin{functionl}{StrPas}{StrPasSys}
  3187. \Declaration
  3188. Function StrPas(Str: PChar): string;
  3189. \Description
  3190. Converts a null terminated string in \var{Str} to an Ansitring, and returns
  3191. this string. This string is NOT truncated at 255 characters as is the
  3192. \Errors
  3193. None.
  3194. \SeeAlso
  3195. \seef{StrPas}.
  3196. \end{functionl}
  3197. For an example, see \seef{StrPas}.
  3198. \section{String handling functions}
  3199. \begin{function}{AdjustLineBreaks}
  3200. \Declaration
  3201. Function AdjustLineBreaks(const S: string): string;
  3202. \Description
  3203. \var{AdjustLineBreaks} will change all \var{\#13} characters with
  3204. \var{\#13\#10} on \windowsnt and \dos. On \linux, all \var{\#13\#10}
  3205. character pairs are converted to \var{#10} and single \var{\#13}
  3206. characters also.
  3207. \Errors
  3208. None.
  3209. \SeeAlso
  3210. \seef{AnsiCompareStr}, \seef{AnsiCompareText}
  3211. \end{function}
  3212. \latex{\inputlisting{sysutex/ex48.pp}}
  3213. \html{\input{sysutex/ex48.tex}}
  3214. \begin{function}{AnsiCompareStr}
  3215. \Declaration
  3216. Function AnsiCompareStr(const S1, S2: string): integer;
  3217. \Description
  3218. \var{AnsiCompareStr} compares two strings and returns the following
  3219. result:
  3220. \begin{description}
  3221. \item[<0] if \var{S1<S2}.
  3222. \item[0] if \var{S1=S2}.
  3223. \item[>0] if \var{S1>S2}.
  3224. \end{description}
  3225. the comparision takes into account Ansi characters, i.e. it takes
  3226. care of strange accented characters. Contrary to \seef{CompareAnsiText},
  3227. the comparision is case sensitive.
  3228. \Errors
  3229. None.
  3230. \SeeAlso
  3231. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  3232. \end{function}
  3233. \latex{\inputlisting{sysutex/ex49.pp}}
  3234. \html{\input{sysutex/ex49.tex}}
  3235. \begin{function}{AnsiCompareText}
  3236. \Declaration
  3237. Function AnsiCompareText(const S1, S2: string): integer;
  3238. \Description
  3239. \Description
  3240. \var{AnsiCompareText} compares two strings and returns the following
  3241. result:
  3242. \begin{description}
  3243. \item[<0] if \var{S1<S2}.
  3244. \item[0] if \var{S1=S2}.
  3245. \item[>0] if \var{S1>S2}.
  3246. \end{description}
  3247. the comparision takes into account Ansi characters, i.e. it takes
  3248. care of strange accented characters. Contrary to \seef{CompareAnsiStr},
  3249. the comparision is case insensitive.
  3250. \Errors
  3251. None.
  3252. \SeeAlso
  3253. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  3254. \end{function}
  3255. \latex{\inputlisting{sysutex/ex50.pp}}
  3256. \html{\input{sysutex/ex50.tex}}
  3257. \begin{function}{AnsiExtractQuotedStr}
  3258. \Declaration
  3259. Function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  3260. \Description
  3261. \var{AnsiExtractQuotedStr} Returns \var{Src} as a string,, with \var{Quute}
  3262. characters removed from the beginning and end of the string, and double
  3263. \var{Quote} characters replaced by a single \var{Quote} characters.
  3264. As such, it revereses the action of \seef{AnsiQuotedStr}.
  3265. \Errors
  3266. None.
  3267. \SeeAlso
  3268. \seef{AnsiQuotedStr}
  3269. \end{function}
  3270. \latex{\inputlisting{sysutex/ex51.pp}}
  3271. \html{\input{sysutex/ex51.tex}}
  3272. \begin{function}{AnsiLastChar}
  3273. \Declaration
  3274. Function AnsiLastChar(const S: string): PChar;
  3275. \Description
  3276. This function returns a pointer to the last character of \var{S}.
  3277. Since multibyte characters are not yet supported, this is the same
  3278. as \var{@S[Length(S)])}.
  3279. \Errors
  3280. None.
  3281. \SeeAlso
  3282. \seef{AnsiStrLastChar}
  3283. \end{function}
  3284. \latex{\inputlisting{sysutex/ex52.pp}}
  3285. \html{\input{sysutex/ex52.tex}}
  3286. \begin{function}{AnsiLowerCase}
  3287. \Declaration
  3288. Function AnsiLowerCase(const s: string): string;
  3289. \Description
  3290. \var{AnsiLowerCase} converts the string \var{S} to lowercase characters
  3291. and returns the resulting string.
  3292. It takes into account the operating system language
  3293. settings when doing this, so spcial characters are converted correctly as
  3294. well.
  3295. {\em Remark} On linux, no language setting is taken in account yet.
  3296. \Errors
  3297. None.
  3298. \SeeAlso
  3299. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiStrUpper}
  3300. \end{function}
  3301. \latex{\inputlisting{sysutex/ex53.pp}}
  3302. \html{\input{sysutex/ex53.tex}}
  3303. \begin{function}{AnsiQuotedStr}
  3304. \Declaration
  3305. Function AnsiQuotedStr(const S: string; Quote: char): string;
  3306. \Description
  3307. \var{AnsiQuotedString} quotes the string \var{S} and returns the result.
  3308. This means that it puts the \var{Quote} character at both the beginning and
  3309. end of the string and replaces any occurrence of \var{Quote} in \var{S}
  3310. with 2 \var{Quote} characters. The action of \var{AnsiQuotedString} can be
  3311. reversed by \seef{AnsiExtractQuotedStr}.
  3312. \Errors
  3313. None.
  3314. \SeeAlso
  3315. \seef{AnsiExtractQuotedStr}
  3316. \end{function}
  3317. For an example, see \seef{AnsiExtractQuotedStr}
  3318. \begin{function}{AnsiStrComp}
  3319. \Declaration
  3320. Function AnsiStrComp(S1, S2: PChar): integer;
  3321. \Description
  3322. \var{AnsiStrComp} compares 2 \var{PChar} strings, and returns the following
  3323. result:
  3324. \begin{description}
  3325. \item[<0] if \var{S1<S2}.
  3326. \item[0] if \var{S1=S2}.
  3327. \item[>0] if \var{S1>S2}.
  3328. \end{description}
  3329. The comparision of the two strings is case-sensitive.
  3330. The function does not yet take internationalization settings into account.
  3331. \Errors
  3332. None.
  3333. \SeeAlso
  3334. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  3335. \end{function}
  3336. \latex{\inputlisting{sysutex/ex54.pp}}
  3337. \html{\input{sysutex/ex54.tex}}
  3338. \begin{function}{AnsiStrIComp}
  3339. \Declaration
  3340. Function AnsiStrIComp(S1, S2: PChar): integer;
  3341. \Description
  3342. \var{AnsiStrIComp} compares 2 \var{PChar} strings, and returns the following
  3343. result:
  3344. \begin{description}
  3345. \item[<0] if \var{S1<S2}.
  3346. \item[0] if \var{S1=S2}.
  3347. \item[>0] if \var{S1>S2}.
  3348. \end{description}
  3349. The comparision of the two strings is case-insensitive.
  3350. The function does not yet take internationalization settings into account.
  3351. \Errors
  3352. None.
  3353. \SeeAlso
  3354. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  3355. \end{function}
  3356. \latex{\inputlisting{sysutex/ex55.pp}}
  3357. \html{\input{sysutex/ex55.tex}}
  3358. \begin{function}{AnsiStrLastChar}
  3359. \Declaration
  3360. function AnsiStrLastChar(Str: PChar): PChar;
  3361. \Declaration
  3362. \var{AnsiStrLastChar} returns a pointer to the last character of \var{Str}.
  3363. Since multibyte characters are not yet supported, this is the same
  3364. as \var{StrEnd(Str)-1}.
  3365. \Errors
  3366. None.
  3367. \SeeAlso
  3368. \seef{AnsiLastChar}
  3369. \end{function}
  3370. \latex{\inputlisting{sysutex/ex58.pp}}
  3371. \html{\input{sysutex/ex58.tex}}
  3372. \begin{function}{AnsiStrLComp}
  3373. \Declaration
  3374. Function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
  3375. \Description
  3376. \var{AnsiStrLComp} compares the first \var{Maxlen} characters of
  3377. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  3378. result:
  3379. \begin{description}
  3380. \item[<0] if \var{S1<S2}.
  3381. \item[0] if \var{S1=S2}.
  3382. \item[>0] if \var{S1>S2}.
  3383. \end{description}
  3384. The comparision of the two strings is case-sensitive.
  3385. The function does not yet take internationalization settings into account.
  3386. \Errors
  3387. None.
  3388. \SeeAlso
  3389. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  3390. \end{function}
  3391. \latex{\inputlisting{sysutex/ex56.pp}}
  3392. \html{\input{sysutex/ex56.tex}}
  3393. \begin{function}{AnsiStrLIComp}
  3394. \Declaration
  3395. Function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
  3396. \Description
  3397. \var{AnsiStrLIComp} compares the first \var{Maxlen} characters of
  3398. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  3399. result:
  3400. \begin{description}
  3401. \item[<0] if \var{S1<S2}.
  3402. \item[0] if \var{S1=S2}.
  3403. \item[>0] if \var{S1>S2}.
  3404. \end{description}
  3405. The comparision of the two strings is case-insensitive.
  3406. The function does not yet take internationalization settings into account.
  3407. \Errors
  3408. None.
  3409. \SeeAlso
  3410. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  3411. \end{function}
  3412. \latex{\inputlisting{sysutex/ex57.pp}}
  3413. \html{\input{sysutex/ex57.tex}}
  3414. \begin{function}{AnsiStrLower}
  3415. \Declaration
  3416. Function AnsiStrLower(Str: PChar): PChar;
  3417. \Description
  3418. \var{AnsiStrLower} converts the PChar \var{Str} to lowercase characters
  3419. and returns the resulting pchar. Note that \var{Str} itself is modified,
  3420. not a copy, as in the case of \seef{AnsiLowerCase}.
  3421. It takes into account the operating system language
  3422. settings when doing this, so spcial characters are converted correctly as
  3423. well.
  3424. {\em Remark} On linux, no language setting is taken in account yet.
  3425. \Errors
  3426. None.
  3427. \SeeAlso
  3428. \seef{AnsiStrUpper}, \seef{AnsiLowercase}
  3429. \end{function}
  3430. \Errors
  3431. \SeeAlso
  3432. \end{function}
  3433. \latex{\inputlisting{sysutex/ex59.pp}}
  3434. \html{\input{sysutex/ex59.tex}}
  3435. \begin{function}{AnsiStrUpper}
  3436. \Declaration
  3437. Function AnsiStrUpper(Str: PChar): PChar;
  3438. \Description
  3439. \var{AnsiStrUpper} converts the \var{PChar} \var{Str} to uppercase characters
  3440. and returns the resulting string. Note that \var{Str} itself is modified,
  3441. not a copy, as in the case of \seef{AnsiUpperCase}.
  3442. It takes into account the operating system language
  3443. settings when doing this, so spcial characters are converted correctly as
  3444. well.
  3445. {\em Remark} On linux, no language setting is taken in account yet.
  3446. \Errors
  3447. None.
  3448. \SeeAlso
  3449. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  3450. \end{function}
  3451. \latex{\inputlisting{sysutex/ex60.pp}}
  3452. \html{\input{sysutex/ex60.tex}}
  3453. \begin{function}{AnsiUpperCase}
  3454. \Declaration
  3455. Function AnsiUpperCase(const s: string): string;
  3456. \Description
  3457. \var{AnsiUpperCase} converts the string \var{S} to uppercase characters
  3458. and returns the resulting string.
  3459. It takes into account the operating system language
  3460. settings when doing this, so spcial characters are converted correctly as
  3461. well.
  3462. {\em Remark} On linux, no language setting is taken in account yet.
  3463. \Errors
  3464. None.
  3465. \SeeAlso
  3466. \seef{AnsiStrUpper}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  3467. \end{function}
  3468. \latex{\inputlisting{sysutex/ex61.pp}}
  3469. \html{\input{sysutex/ex61.tex}}
  3470. \begin{procedure}{AppendStr}
  3471. \Declaration
  3472. Procedure AppendStr(var Dest: String; const S: string);
  3473. \Description
  3474. \var{AppendStr} appends \var{S} to Dest.
  3475. This function is provided for Delphi
  3476. compatibility only, since it is completely equivalent to \var{Dest:=Dest+S}.
  3477. \Errors
  3478. None.
  3479. \SeeAlso
  3480. \seep{AssignStr},\seef{NewStr}, \seep{DisposeStr}
  3481. \end{procedure}
  3482. \latex{\inputlisting{sysutex/ex62.pp}}
  3483. \html{\input{sysutex/ex62.tex}}
  3484. \begin{procedure}{AssignStr}
  3485. \Declaration
  3486. Procedure AssignStr(var P: PString; const S: string);
  3487. \Description
  3488. \var{AssignStr} allocates \var{S} to P. The old value of \var{P} is
  3489. disposed of.
  3490. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  3491. are managed on the heap and should be preferred to the mechanism of
  3492. dynamically allocated strings.
  3493. \Errors
  3494. None.
  3495. \SeeAlso
  3496. \seef{NewStr}, \seep{AppendStr}, \seep{DisposeStr}
  3497. \end{procedure}
  3498. \latex{\inputlisting{sysutex/ex63.pp}}
  3499. \html{\input{sysutex/ex63.tex}}
  3500. \begin{function}{BCDToInt}
  3501. \Declaration
  3502. Function BCDToInt(Value: integer): integer;
  3503. \Description
  3504. \var{BCDToInt} converts a \var{BCD} coded integer to a normal integer.
  3505. \Errors
  3506. None.
  3507. \SeeAlso
  3508. \seef{StrToInt}, \seef{IntToStr}
  3509. \end{function}
  3510. \latex{\inputlisting{sysutex/ex64.pp}}
  3511. \html{\input{sysutex/ex64.tex}}
  3512. \begin{function}{CompareMem}
  3513. \Declaration
  3514. Function CompareMem(P1, P2: Pointer; Length: cardinal): integer;
  3515. \Description
  3516. \var{CompareMem} compares, byte by byte, 2 memory areas pointed
  3517. to by \var{P1} and \var{P2}, for a length of \var{L} bytes.
  3518. It returns the following values:
  3519. \begin{description}
  3520. \item[<0] if at some position the byte at \var{P1} is less than the byte at the
  3521. same postion at \var{P2}.
  3522. \item[0] if all \var{L} bytes are the same.
  3523. \item[3]
  3524. \end{description}
  3525. \Errors
  3526. \SeeAlso
  3527. \end{function}
  3528. \begin{function}{CompareStr}
  3529. \Declaration
  3530. Function CompareStr(const S1, S2: string): Integer;
  3531. \Description
  3532. \var{CompareStr} compares two strings, \var{S1} and \var{S2},
  3533. and returns the following
  3534. result:
  3535. \begin{description}
  3536. \item[<0] if \var{S1<S2}.
  3537. \item[0] if \var{S1=S2}.
  3538. \item[>0] if \var{S1>S2}.
  3539. \end{description}
  3540. The comparision of the two strings is case-sensitive.
  3541. The function does not take internationalization settings into account, it
  3542. simply compares ASCII values.
  3543. \Errors
  3544. None.
  3545. \SeeAlso
  3546. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareText}
  3547. \end{function}
  3548. \begin{function}{CompareText}
  3549. \Declaration
  3550. Function CompareText(const S1, S2: string): integer;
  3551. \Description
  3552. \var{CompareText} compares two strings, \var{S1} and \var{S2},
  3553. and returns the following
  3554. result:
  3555. \begin{description}
  3556. \item[<0] if \var{S1<S2}.
  3557. \item[0] if \var{S1=S2}.
  3558. \item[>0] if \var{S1>S2}.
  3559. \end{description}
  3560. The comparision of the two strings is case-insensitive.
  3561. The function does not take internationalization settings into account, it
  3562. simply compares ASCII values.
  3563. \Errors
  3564. None.
  3565. \SeeAlso
  3566. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareStr}
  3567. \end{function}
  3568. \begin{procedurel}{DisposeStr}{DisposeStrSys}
  3569. \Declaration
  3570. Procedure DisposeStr(S: PString);
  3571. \Description
  3572. \var{DisposeStr} removes the dynamically allocated string \var{S} from the
  3573. heap, and releases the occupied memory.
  3574. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  3575. are managed on the heap and should be preferred to the mechanism of
  3576. dynamically allocated strings.
  3577. \Errors
  3578. None.
  3579. \SeeAlso
  3580. \seef{NewStr}, \seep{AppendStr}, \seep{AssignStr}
  3581. \end{procedurel}
  3582. \begin{function}{FloatToStr}
  3583. \Declaration
  3584. Function FloatToStr( Value: Extended): String;
  3585. \Description
  3586. \Errors
  3587. \SeeAlso
  3588. \end{function}
  3589. \begin{function}{FloatToStrF}
  3590. \Declaration
  3591. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  3592. \Description
  3593. \Errors
  3594. \SeeAlso
  3595. \end{function}
  3596. \begin{procedure}{FmtStr}
  3597. \Declaration
  3598. Procedure (Var Res: String; Const Fmt : String; Const args: Array of const);
  3599. \Description
  3600. \Errors
  3601. \SeeAlso
  3602. \end{procedure}
  3603. \begin{function}{Format}
  3604. \Declaration
  3605. Function Format(Const Fmt : String; const Args : Array of const) : String;
  3606. \Description
  3607. \Errors
  3608. \SeeAlso
  3609. \end{function}
  3610. \begin{function}{FormatBuf}
  3611. \Declaration
  3612. Function FormatBuf(Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const) : Cardinal;
  3613. \Description
  3614. \Errors
  3615. \SeeAlso
  3616. \end{function}
  3617. \begin{function}{IntToHex}
  3618. \Declaration
  3619. Function IntToHex(Value: integer; Digits: integer): string;
  3620. \Description
  3621. \Errors
  3622. \SeeAlso
  3623. \end{function}
  3624. \begin{function}{IntToStr}
  3625. \Declaration
  3626. Function IntToStr(Value: integer): string;
  3627. \Description
  3628. \Errors
  3629. \SeeAlso
  3630. \end{function}
  3631. \begin{function}{IsValidIdent}
  3632. \Declaration
  3633. Function IsValidIdent(const Ident: string): boolean;
  3634. \Description
  3635. \Errors
  3636. \SeeAlso
  3637. \end{function}
  3638. \begin{function}{LeftStr}
  3639. \Declaration
  3640. Function LeftStr(const S: string; Count: integer): string;
  3641. \Description
  3642. \Errors
  3643. \SeeAlso
  3644. \end{function}
  3645. \begin{function}{LoadStr}
  3646. \Declaration
  3647. Function LoadStr(Ident: integer): string;
  3648. \Description
  3649. \Errors
  3650. \SeeAlso
  3651. \end{function}
  3652. \begin{function}{LowerCase}
  3653. \Declaration
  3654. Function LowerCase(const s: string): string;
  3655. \Description
  3656. \Errors
  3657. \SeeAlso
  3658. \end{function}
  3659. \begin{functionl}{NewStr}{NewStrSys}
  3660. \Declaration
  3661. Function NewStr(const S: string): PString;
  3662. \Description
  3663. \Errors
  3664. \SeeAlso
  3665. \end{functionl}
  3666. \begin{function}{QuotedStr}
  3667. \Declaration
  3668. Function QuotedStr(const S: string): string;
  3669. \Description
  3670. \Errors
  3671. \SeeAlso
  3672. \end{function}
  3673. \begin{function}{RightStr}
  3674. \Declaration
  3675. Function RightStr(const S: string; Count: integer): string;
  3676. \Description
  3677. \Errors
  3678. \SeeAlso
  3679. \end{function}
  3680. \begin{function}{StrFmt}
  3681. \Declaration
  3682. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  3683. \Description
  3684. \Errors
  3685. \SeeAlso
  3686. \end{function}
  3687. \begin{function}{StrLFmt}
  3688. \Declaration
  3689. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  3690. \Description
  3691. \Errors
  3692. \SeeAlso
  3693. \end{function}
  3694. \begin{function}{StrToInt}
  3695. \Declaration
  3696. Function StrToInt(const s: string): integer;
  3697. \Description
  3698. \Errors
  3699. \SeeAlso
  3700. \end{function}
  3701. \begin{function}{StrToIntDef}
  3702. \Declaration
  3703. Function StrToIntDef(const S: string; Default: integer): integer;
  3704. \Description
  3705. \Errors
  3706. \SeeAlso
  3707. \end{function}
  3708. \begin{function}{Trim}
  3709. \Declaration
  3710. Function Trim(const S: string): string;
  3711. \Description
  3712. \Errors
  3713. \SeeAlso
  3714. \end{function}
  3715. \begin{function}{TrimLeft}
  3716. \Declaration
  3717. Function TrimLeft(const S: string): string;
  3718. \Description
  3719. \Errors
  3720. \SeeAlso
  3721. \end{function}
  3722. \begin{function}{TrimRight}
  3723. \Declaration
  3724. Function TrimRight(const S: string): string;
  3725. \Description
  3726. \Errors
  3727. \SeeAlso
  3728. \end{function}
  3729. \begin{function}{UpperCase}
  3730. \Declaration
  3731. Function UpperCase(const s: string): string;
  3732. \Description
  3733. \Errors
  3734. \SeeAlso
  3735. \end{function}
  3736. *** Modified files in JOE when it aborted on Thu May 27 09:57:40 1999
  3737. *** JOE was aborted because the terminal closed
  3738. *** File '(Unnamed)'
  3739. DEADJOE
  3740. ex66.pp
  3741. *** File '(Unnamed)'
  3742. comparemem
  3743. *** File 'sysutils.tex'
  3744. %
  3745. % $Id$
  3746. % This file is part of the FPC documentation.
  3747. % Copyright (C) 1999, by Michael Van Canneyt
  3748. %
  3749. % The FPC documentation is free text; you can redistribute it and/or
  3750. % modify it under the terms of the GNU Library General Public License as
  3751. % published by the Free Software Foundation; either version 2 of the
  3752. % License, or (at your option) any later version.
  3753. %
  3754. % The FPC Documentation is distributed in the hope that it will be useful,
  3755. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  3756. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  3757. % Library General Public License for more details.
  3758. %
  3759. % You should have received a copy of the GNU Library General Public
  3760. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  3761. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  3762. % Boston, MA 02111-1307, USA.
  3763. %
  3764. \chapter{The SYSUTILS unit.}
  3765. This chapter describes the \file{sysutils} unit. The \var{sysutils} unit
  3766. was largely written by Gertjan Schouten, and completed by michael Van Canneyt.
  3767. It aims to be compatible to the Delphi sysutils unit, but in contrast with
  3768. the latter, it is designed to work on multiple platforms.
  3769. This chapter starts out with a definition of all types and constants
  3770. that are defined, followed by a complete explanation of each function.
  3771. \section{Constants and types}
  3772. The following general-purpose constants are defined:
  3773. \begin{verbatim}
  3774. const
  3775. SecsPerDay = 24 * 60 * 60; // Seconds and milliseconds per day
  3776. MSecsPerDay = SecsPerDay * 1000;
  3777. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  3778. Eoln = #10;
  3779. \end{verbatim}
  3780. The following types are used frequently in date and time functions.
  3781. They are the same on all platforms.
  3782. \begin{verbatim}
  3783. type
  3784. TSystemTime = record
  3785. Year, Month, Day: word;
  3786. Hour, Minute, Second, MilliSecond: word;
  3787. end ;
  3788. TDateTime = double;
  3789. TTimeStamp = record
  3790. Time: integer; { Number of milliseconds since midnight }
  3791. Date: integer; { One plus number of days since 1/1/0001 }
  3792. end ;
  3793. \end{verbatim}
  3794. The following type is used in the \seef{FindFirst},\seef{FindNext}
  3795. and \seepl{FindClose}{FindCloseSys} functions. The \var{win32} version differs from
  3796. the other versions. If code is to be portable, that part shouldn't
  3797. be used.
  3798. \begin{verbatim}
  3799. Type
  3800. THandle = Longint;
  3801. TSearchRec = Record
  3802. Time,Size, Attr : Longint;
  3803. Name : TFileName;
  3804. ExcludeAttr : Longint;
  3805. FindHandle : THandle;
  3806. {$ifdef Win32}
  3807. FindData : TWin32FindData;
  3808. {$endif}
  3809. end;
  3810. \end{verbatim}
  3811. The following constants are file-attributes that need to be matched in the
  3812. findfirst call.
  3813. \begin{verbatim}
  3814. Const
  3815. faReadOnly = $00000001;
  3816. faHidden = $00000002;
  3817. faSysFile = $00000004;
  3818. faVolumeId = $00000008;
  3819. faDirectory = $00000010;
  3820. faArchive = $00000020;
  3821. faAnyFile = $0000003f;
  3822. \end{verbatim}
  3823. The following constants can be used in the \seef{FileOpen} call.
  3824. \begin{verbatim}
  3825. Const
  3826. fmOpenRead = $0000;
  3827. fmOpenWrite = $0001;
  3828. fmOpenReadWrite = $0002;
  3829. \end{verbatim}
  3830. The following constants can be used in the \seef{FileSeek} call.
  3831. \begin{verbatim}
  3832. Const
  3833. fsFromBeginning = 0;
  3834. fsFromCurrent = 1;
  3835. fsFromEnd = 2;
  3836. \end{verbatim}
  3837. The following variables are used in the case translation routines.
  3838. \begin{verbatim}
  3839. type
  3840. TCaseTranslationTable = array[0..255] of char;
  3841. var
  3842. UpperCaseTable: TCaseTranslationTable;
  3843. LowerCaseTable: TCaseTranslationTable;
  3844. \end{verbatim}
  3845. The initialization code of the \file{sysutils} unit fills these
  3846. tables with the appropriate values. For the win32 and go32v2
  3847. versions, this information is obtained from the operating system.
  3848. The following constants control the formatting of dates.
  3849. For the Win32 version of the \file{sysutils} unit, these
  3850. constants are set according to the internationalization
  3851. settings of Windows by the initialization code of the unit.
  3852. \begin{verbatim}
  3853. Const
  3854. DateSeparator: char = '-';
  3855. ShortDateFormat: string = 'd/m/y';
  3856. LongDateFormat: string = 'dd" "mmmm" "yyyy';
  3857. ShortMonthNames: array[1..12] of string[128] =
  3858. ('Jan','Feb','Mar','Apr','May','Jun',
  3859. 'Jul','Aug','Sep','Oct','Nov','Dec');
  3860. LongMonthNames: array[1..12] of string[128] =
  3861. ('January','February','March','April',
  3862. 'May','June','July','August',
  3863. 'September','October','November','December');
  3864. ShortDayNames: array[1..7] of string[128] =
  3865. ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  3866. LongDayNames: array[1..7] of string[128] =
  3867. ('Sunday','Monday','Tuesday','Wednesday',
  3868. 'Thursday','Friday','Saturday');
  3869. \end{verbatim}
  3870. The following constants control the formatting of times.
  3871. For the Win32 version of the \file{sysutils} unit, these
  3872. constants are set according to the internationalization
  3873. settings of Windows by the initialization code of the unit.
  3874. \begin{verbatim}
  3875. Const
  3876. ShortTimeFormat: string = 'hh:nn';
  3877. LongTimeFormat: string = 'hh:nn:ss';
  3878. TimeSeparator: char = ':';
  3879. TimeAMString: string[7] = 'AM';
  3880. TimePMString: string[7] = 'PM';
  3881. \end{verbatim}
  3882. The following constants control the formatting of currencies
  3883. and numbers. For the Win32 version of the \file{sysutils} unit,
  3884. these constants are set according to the internationalization
  3885. settings of Windows by the initialization code of the unit.
  3886. \begin{verbatim}
  3887. Const
  3888. DecimalSeparator : Char = '.';
  3889. ThousandSeparator : Char = ',';
  3890. CurrencyDecimals : Byte = 2;
  3891. CurrencyString : String[7] = '$';
  3892. { Format to use when formatting currency :
  3893. 0 = $1 1 = 1$ 2 = $ 1 3 = 1 $
  3894. 4 = Currency string replaces decimal indicator.
  3895. e.g. 1$50
  3896. }
  3897. CurrencyFormat : Byte = 1;
  3898. { Same as above, only for negative currencies:
  3899. 0 = ($1)
  3900. 1 = -$1
  3901. 2 = $-1
  3902. 3 = $1-
  3903. 4 = (1$)
  3904. 5 = -1$
  3905. 6 = 1-$
  3906. 7 = 1$-
  3907. 8 = -1 $
  3908. 9 = -$ 1
  3909. 10 = $ 1-
  3910. }
  3911. NegCurrFormat : Byte = 5;
  3912. \end{verbatim}
  3913. The following types are used in various string functions.
  3914. \begin{verbatim}
  3915. type
  3916. PString = ^String;
  3917. TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  3918. \end{verbatim}
  3919. The following constants are used in the file name handling routines. Do not
  3920. use a slash of backslash character directly as a path separator; instead
  3921. use the \var{OsDirSeparator} character.
  3922. \begin{verbatim}
  3923. Const
  3924. DirSeparators : set of char = ['/','\'];
  3925. {$ifdef Linux}
  3926. OSDirSeparator = '/';
  3927. {$else}
  3928. OsDirSeparator = '\';
  3929. {$endif}
  3930. \end{verbatim}
  3931. \section{Date and time functions}
  3932. \subsection{Date and time formatting characters}
  3933. \label{se:formatchars}
  3934. Various date and time formatting routines accept a format string.
  3935. to format the date and or time. The following characters can be used
  3936. to control the date and time formatting:
  3937. \begin{description}
  3938. \item[c] : shortdateformat + ' ' + shorttimeformat
  3939. \item[d] : day of month
  3940. \item[dd] : day of month (leading zero)
  3941. \item[ddd] : day of week (abbreviation)
  3942. \item[dddd] : day of week (full)
  3943. \item[ddddd] : shortdateformat
  3944. \item[dddddd] : longdateformat
  3945. \item[m] : month
  3946. \item[mm] : month (leading zero)
  3947. \item[mmm] : month (abbreviation)
  3948. \item[mmmm] : month (full)
  3949. \item[y] : year (four digits)
  3950. \item[yy] : year (two digits)
  3951. \item[yyyy] : year (with century)
  3952. \item[h] : hour
  3953. \item[hh] : hour (leading zero)
  3954. \item[n] : minute
  3955. \item[nn] : minute (leading zero)
  3956. \item[s] : second
  3957. \item[ss] : second (leading zero)
  3958. \item[t] : shorttimeformat
  3959. \item[tt] : longtimeformat
  3960. \item[am/pm] : use 12 hour clock and display am and pm accordingly
  3961. \item[a/p] : use 12 hour clock and display a and p accordingly
  3962. \item[/] : insert date seperator
  3963. \item[:] : insert time seperator
  3964. \item["xx"] : literal text
  3965. \item['xx'] : literal text
  3966. \end{description}
  3967. \begin{type}{TDateTime}
  3968. \Declaration
  3969. TDateTime = Double;
  3970. \Description
  3971. Many functions return or require a \var{TDateTime} type, which contains
  3972. a date and time in encoded form. The date and time are converted to a double
  3973. as follows:
  3974. \end{type}
  3975. \begin{function}{Date}
  3976. \Declaration
  3977. Function Date: TDateTime;
  3978. \Description
  3979. \var{Date} returns the current date in \var{TDateTime} format.
  3980. For more information about the \var{TDateTime} type, see \seety{TDateTime}.
  3981. \Errors
  3982. None.
  3983. \SeeAlso
  3984. \seef{Time},\seef{Now}, \seety{TDateTime}.
  3985. \end{function}
  3986. \latex{\inputlisting{sysutex/ex1.pp}}
  3987. \html{\input{sysutex/ex1.tex}}
  3988. \begin{function}{DateTimeToFileDate}
  3989. \Declaration
  3990. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  3991. \Description
  3992. \var{DateTimeToFileDate} function converts a date/time indication in
  3993. \var{TDateTime} format to a filedate function, such as returned for
  3994. instance by the \seef{FileAge} function.
  3995. \Errors
  3996. None.
  3997. \SeeAlso
  3998. \seef{Time}, \seef{Date}, \seef{FileDateToDateTime},
  3999. \seep{DateTimeToSystemTime}, \seef{DateTimeToTimeStamp}
  4000. \end{function}
  4001. \latex{\inputlisting{sysutex/ex2.pp}}
  4002. \html{\input{sysutex/ex2.tex}}
  4003. \begin{function}{DateTimeToStr}
  4004. \Declaration
  4005. Function DateTimeToStr(DateTime: TDateTime): string;
  4006. \Description
  4007. \var{DateTimeToStr} returns a string representation of
  4008. \var{DateTime} using the formatting specified in
  4009. \var{ShortDateTimeFormat}. It corresponds to a call to
  4010. \var{FormatDateTime('c',DateTime)} (see \sees{formatchars}).
  4011. \Errors
  4012. None.
  4013. \SeeAlso
  4014. \seef{FormatDateTime}, \seety{TDateTime}.
  4015. \end{function}
  4016. \latex{\inputlisting{sysutex/ex3.pp}}
  4017. \html{\input{sysutex/ex3.tex}}
  4018. \begin{procedure}{DateTimeToString}
  4019. \Declaration
  4020. Procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  4021. \Description
  4022. \var{DateTimeToString} returns in \var{Result} a string representation of
  4023. \var{DateTime} using the formatting specified in \var{FormatStr}.
  4024. for a list of characters that can be used in the \var{FormatStr} formatting
  4025. string, see \sees{formatchars}.
  4026. \Errors
  4027. In case a wrong formatting character is found, an \var{EConvertError} is
  4028. raised.
  4029. \SeeAlso
  4030. \seef{FormatDateTime}, \sees{formatchars}.
  4031. \end{procedure}
  4032. \latex{\inputlisting{sysutex/ex4.pp}}
  4033. \html{\input{sysutex/ex4.tex}}
  4034. \begin{procedure}{DateTimeToSystemTime}
  4035. \Declaration
  4036. Procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  4037. \Description
  4038. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  4039. \var{TDateTime} format to a system time \var{SystemTime}.
  4040. \Errors
  4041. None.
  4042. \SeeAlso
  4043. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  4044. \seef{DateTimeToTimeStamp}
  4045. \end{procedure}
  4046. \latex{\inputlisting{sysutex/ex5.pp}}
  4047. \html{\input{sysutex/ex5.tex}}
  4048. \begin{function}{DateTimeToTimeStamp}
  4049. \Declaration
  4050. Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  4051. \Description
  4052. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  4053. \var{TDateTime} format to a \var{TTimeStamp} format.
  4054. \Errors
  4055. None.
  4056. \SeeAlso
  4057. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  4058. \seep{DateTimeToSystemTime}
  4059. \end{function}
  4060. \latex{\inputlisting{sysutex/ex6.pp}}
  4061. \html{\input{sysutex/ex6.tex}}
  4062. \begin{function}{DateToStr}
  4063. \Declaration
  4064. Function DateToStr(Date: TDateTime): string;
  4065. \Description
  4066. \var{DateToStr} converts \var{Date} to a string representation. It uses
  4067. \var{ShortDateFormat} as it's formatting string. It is hence completely
  4068. equivalent to a \var{FormatDateTime('ddddd', Date)}.
  4069. \Errors
  4070. None.
  4071. \SeeAlso
  4072. \seef{TimeToStr}, \seef{DateTimeToStr}, \seef{FormatDateTime},
  4073. \seef{StrToDate}
  4074. \end{function}
  4075. \latex{\inputlisting{sysutex/ex7.pp}}
  4076. \html{\input{sysutex/ex7.tex}}
  4077. \begin{function}{DayOfWeek}
  4078. \Declaration
  4079. Function DayOfWeek(DateTime: TDateTime): integer;
  4080. \Description
  4081. \var{DayOfWeek} returns the day of the week from \var{DateTime}.
  4082. \var{Sunday} is counted as day 1, \var{Saturday} is counted as
  4083. day 7. The result of \var{DayOfWeek} can serve as an index to
  4084. the \var{LongDayNames} constant array, to retrieve the name of
  4085. the day.
  4086. \Errors
  4087. None.
  4088. \SeeAlso
  4089. \seef{Date}, \seef{DateToStr}
  4090. \end{function}
  4091. \latex{\inputlisting{sysutex/ex8.pp}}
  4092. \html{\input{sysutex/ex8.tex}}
  4093. \begin{procedure}{DecodeDate}
  4094. \Declaration
  4095. Procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  4096. \Description
  4097. \var{DecodeDate} decodes the Year, Month and Day stored in \var{Date},
  4098. and returns them in the \var{Year}, \var{Month} and \var{Day} variables.
  4099. \Errors
  4100. None.
  4101. \SeeAlso
  4102. \seef{EncodeDate}, \seep{DecodeTime}.
  4103. \end{procedure}
  4104. \latex{\inputlisting{sysutex/ex9.pp}}
  4105. \html{\input{sysutex/ex9.tex}}
  4106. \begin{procedure}{DecodeTime}
  4107. \Declaration
  4108. Procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  4109. \Description
  4110. \var{DecodeDate} decodes the hours, minutes, second and milliseconds stored
  4111. in \var{Time}, and returns them in the \var{Hour}, \var{Minute} and
  4112. \var{Second} and \var{MilliSecond} variables.
  4113. \Errors
  4114. None.
  4115. \SeeAlso
  4116. \seef{EncodeTime}, \seep{DecodeDate}.
  4117. \end{procedure}
  4118. \latex{\inputlisting{sysutex/ex10.pp}}
  4119. \html{\input{sysutex/ex10.tex}}
  4120. \begin{function}{EncodeDate}
  4121. \Declaration
  4122. Function EncodeDate(Year, Month, Day :word): TDateTime;
  4123. \Description
  4124. \var{EncodeDate} encodes the \var{Year}, \var{Month} and \var{Day} variables to
  4125. a date in \var{TDateTime} format. It does the opposite of the
  4126. \seep{DecodeDate} procedure.
  4127. The parameters must lie withing valid ranges (boundaries included):
  4128. \begin{description}
  4129. \item[Year] must be between 1 and 9999.
  4130. \item[Month] must be within the range 1-12.
  4131. \item[Day] msut be between 1 and 31.
  4132. \end{description}
  4133. \Errors
  4134. In case one of the parameters is out of it's valid range, 0 is returned.
  4135. \SeeAlso
  4136. \seef{EncodeTime}, \seep{DecodeDate}.
  4137. \end{function}
  4138. \latex{\inputlisting{sysutex/ex11.pp}}
  4139. \html{\input{sysutex/ex11.tex}}
  4140. \begin{function}{EncodeTime}
  4141. \Declaration
  4142. Function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  4143. \Description
  4144. \var{EncodeTime} encodes the \var{Hour}, \var{Minute}, \var{Second},
  4145. \var{MilliSecond} variables to a \var{TDateTime} format result.
  4146. It does the opposite of the \seep{DecodeTime} procedure.
  4147. The parameters must have a valid range (boundaries included):
  4148. \begin{description}
  4149. \item[Hour] must be between 0 and 23.
  4150. \item[Minute,second] must both be between 0 and 59.
  4151. \item[Millisecond] must be between 0 and 999.
  4152. \end{description}
  4153. \Errors
  4154. In case one of the parameters is outside of it's valid range, 0 is returned.
  4155. \SeeAlso
  4156. \seef{EncodeDate}, \seep{DecodeTime}.
  4157. \end{function}
  4158. \latex{\inputlisting{sysutex/ex12.pp}}
  4159. \html{\input{sysutex/ex12.tex}}
  4160. \begin{function}{FileDateToDateTime}
  4161. \Declaration
  4162. Function FileDateToDateTime(Filedate : Longint) : TDateTime;
  4163. \Description
  4164. \var{FileDateToDateTime} converts the date/time encoded in \var{filedate}
  4165. to a \var{TDateTime} encoded form. It can be used to convert date/time values
  4166. returned by the \seef{FileAge} or \seef{FindFirst}/\seef{FindNext}
  4167. functions to \var{TDateTime} form.
  4168. \Errors
  4169. None.
  4170. \SeeAlso
  4171. \seef{DateTimeToFileDate}
  4172. \end{function}
  4173. \latex{\inputlisting{sysutex/ex13.pp}}
  4174. \html{\input{sysutex/ex13.tex}}
  4175. \begin{function}{FormatDateTime}
  4176. \Declaration
  4177. Function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  4178. \Description
  4179. \var{FormatDateTime} formats the date and time encoded in \var{DateTime}
  4180. according to the formatting given in \var{FormatStr}. The complete list
  4181. of formatting characters can be found in \sees{formatchars}.
  4182. \Errors
  4183. On error (such as an invalid character in the formatting string), and
  4184. \var{EConvertError} exception is raised.
  4185. \SeeAlso
  4186. \seef{DateTimeToStr}, \seef{DateToStr}, \seef{TimeToStr},
  4187. \seef{StrToDateTime}
  4188. \end{function}
  4189. \latex{\inputlisting{sysutex/ex14.pp}}
  4190. \html{\input{sysutex/ex14.tex}}
  4191. \begin{function}{IncMonth}
  4192. \Declaration
  4193. Function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  4194. \Description
  4195. \var{IncMonth} increases the month number in \var{DateTime} with
  4196. \var{NumberOfMonths}. It wraps the result as to get a month between 1 and
  4197. 12, and updates the year accordingly. \var{NumberOfMonths} can be negative,
  4198. and can be larger than 12 (in absolute value).
  4199. \Errors
  4200. None.
  4201. \SeeAlso
  4202. \seef{Date}, \seef{Time}, \seef{Now}
  4203. \end{function}
  4204. \latex{\inputlisting{sysutex/ex15.pp}}
  4205. \html{\input{sysutex/ex15.tex}}
  4206. \begin{function}{IsLeapYear}
  4207. \Declaration
  4208. Function IsLeapYear(Year: Word): boolean;
  4209. \Description
  4210. \var{IsLeapYear} returns \var{True} if \var{Year} is a leap year,
  4211. \var{False} otherwise.
  4212. \Errors
  4213. None.
  4214. \SeeAlso
  4215. \seef{IncMonth}, \seef{Date}
  4216. \end{function}
  4217. \latex{\inputlisting{sysutex/ex16.pp}}
  4218. \html{\input{sysutex/ex16.tex}}
  4219. \begin{function}{MSecsToTimeStamp}
  4220. \Declaration
  4221. Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  4222. \Description
  4223. \var{MSecsTiTimeStamp} converts the given number of milliseconds to
  4224. a \var{TTimeStamp} date/time notation.
  4225. Use \var{TTimeStamp} variables if you need to keep very precise track of
  4226. time.
  4227. \Errors
  4228. None.
  4229. \SeeAlso
  4230. \seef{TimeStampToMSecs}, \seef{DateTimeToTimeStamp},
  4231. \end{function}
  4232. \latex{\inputlisting{sysutex/ex17.pp}}
  4233. \html{\input{sysutex/ex17.tex}}
  4234. \begin{function}{Now}
  4235. \Declaration
  4236. Function Now: TDateTime;
  4237. \Description
  4238. \var{Now} returns the current date and time. It is equivalent to
  4239. \var{Date+Time}.
  4240. \Errors
  4241. None.
  4242. \SeeAlso
  4243. \seef{Date}, \seef{Time}
  4244. \end{function}
  4245. \latex{\inputlisting{sysutex/ex18.pp}}
  4246. \html{\input{sysutex/ex18.tex}}
  4247. \begin{function}{StrToDate}
  4248. \Declaration
  4249. Function StrToDate(const S: string): TDateTime;
  4250. \Description
  4251. \var{StrToDate} converts the string \var{S} to a \var{TDateTime} date
  4252. value. The Date must consist of 1 to three digits, separated by the
  4253. \var{DateSeparator} character. If two numbers are given, they
  4254. are supposed to form the day and month of the current year. If only
  4255. one number is given, it is supposed to represent the day of the
  4256. current month. (This is \em{not} supported in Delphi)
  4257. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  4258. \var{ShortDateFormat} variable.
  4259. \Errors
  4260. On error (e.g. an invalid date or invalid character),
  4261. an \var{EConvertError} exception is raised.
  4262. \SeeAlso
  4263. \seef{StrToTime}, \seef{DateToStr}n \seef{TimeToStr}.
  4264. \end{function}
  4265. \latex{\inputlisting{sysutex/ex19.pp}}
  4266. \html{\input{sysutex/ex19.tex}}
  4267. \begin{function}{StrToDateTime}
  4268. \Declaration
  4269. Function StrToDateTime(const S: string): TDateTime;
  4270. \Description
  4271. \var{StrToDateTime} converts the string \var{S} to a \var{TDateTime} date
  4272. and time value. The Date must consist of 1 to three digits, separated by the
  4273. \var{DateSeparator} character. If two numbers are given, they
  4274. are supposed to form the day and month of the current year. If only
  4275. one number is given, it is supposed to represent the day of the
  4276. current month. (This is \em{not} supported in Delphi)
  4277. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  4278. \var{ShortDateFormat} variable.
  4279. \Errors
  4280. On error (e.g. an invalid date or invalid character),
  4281. an \var{EConvertError} exception is raised.
  4282. \SeeAlso
  4283. \seef{StrToDate}, \seef{StrToTime}, \seef{DateTimeToStr}
  4284. \end{function}
  4285. \latex{\inputlisting{sysutex/ex20.pp}}
  4286. \html{\input{sysutex/ex20.tex}}
  4287. \begin{function}{StrToTime}
  4288. \Declaration
  4289. Function StrToTime(const S: string): TDateTime;
  4290. \Description
  4291. \var{StrToTime} converts the string \var{S} to a \var{TDateTime} time
  4292. value. The time must consist of 1 to 4 digits, separated by the
  4293. \var{TimeSeparator} character. If two numbers are given, they
  4294. are supposed to form the hour and minutes.
  4295. \Errors
  4296. On error (e.g. an invalid date or invalid character),
  4297. an \var{EConvertError} exception is raised.
  4298. \SeeAlso
  4299. \seef{StrToDate}, \seef{StrToDateTime}, \seef{TimeToStr}
  4300. \end{function}
  4301. \latex{\inputlisting{sysutex/ex21.pp}}
  4302. \html{\input{sysutex/ex21.tex}}
  4303. \begin{function}{SystemTimeToDateTime}
  4304. \Declaration
  4305. Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  4306. \Description
  4307. \var{SystemTimeToDateTime} converts a \var{TSystemTime} record to a
  4308. \var{TDateTime} style date/time indication.
  4309. \Errors
  4310. None.
  4311. \SeeAlso
  4312. \seep{DateTimeToSystemTime}
  4313. \end{function}
  4314. \latex{\inputlisting{sysutex/ex22.pp}}
  4315. \html{\input{sysutex/ex22.tex}}
  4316. \begin{function}{Time}
  4317. \Declaration
  4318. Function Time: TDateTime;
  4319. \Description
  4320. \var{Time} returns the current time in \var{TDateTime} format. The date
  4321. part of the \var{TDateTimeValue} is set to zero.
  4322. \Errors
  4323. None.
  4324. \SeeAlso
  4325. \seef{Now}, \seef{Date}
  4326. \end{function}
  4327. \latex{\inputlisting{sysutex/ex23.pp}}
  4328. \html{\input{sysutex/ex23.tex}}
  4329. \begin{function}{TimeStampToDateTime}
  4330. \Declaration
  4331. Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  4332. \Description
  4333. \var{TimeStampToDateTime} converts \var{TimeStamp} to a \var{TDateTime}
  4334. format variable. It is the inverse operation of \seef{DateTimeToTimeStamp}.
  4335. \Errors
  4336. None.
  4337. \SeeAlso
  4338. \seef{DateTimeToTimeStamp}, \seef{TimeStampToMSecs}
  4339. \end{function}
  4340. \latex{\inputlisting{sysutex/ex24.pp}}
  4341. \html{\input{sysutex/ex24.tex}}
  4342. \begin{function}{TimeStampToMSecs}
  4343. \Declaration
  4344. Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  4345. \Description
  4346. \var{TimeStampToMSecs} converts {TimeStamp} to the number of seconds
  4347. since \var{1/1/0001}.
  4348. Use \var{TTimeStamp} variables if you need to keep very precise track of
  4349. time.
  4350. \Errors
  4351. None.
  4352. \SeeAlso
  4353. \seef{MSecsToTimeStamp}, \seef{TimeStampToDateTime}
  4354. \end{function}
  4355. For an example, see \seef{MSecsToTimeStamp}.
  4356. \begin{function}{TimeToStr}
  4357. \Declaration
  4358. Function TimeToStr(Time: TDateTime): string;
  4359. \Description
  4360. \var{TimeToStr} converts the time in \var{Time} to a string. It uses
  4361. the \var{ShortTimeFormat} variable to see what formatting needs to be
  4362. applied. It is therefor entirely equivalent to a
  4363. \var{FormatDateTime('t',Time)} call.
  4364. \Errors
  4365. None.
  4366. \SeeAlso
  4367. \end{function}
  4368. \latex{\inputlisting{sysutex/ex25.pp}}
  4369. \html{\input{sysutex/ex25.tex}}
  4370. \section{Disk functions}
  4371. \begin{functionl}{AddDisk (Linux only)}{AddDisk}
  4372. \Declaration
  4373. Function AddDisk (Const PAth : String) : Longint;
  4374. \Description
  4375. On Linux both the \seef{DiskFree} and \seef{DiskSize} functions need a
  4376. file on the specified drive, since is required for the statfs system call.
  4377. These filenames are set in drivestr[0..26], and the first 4 have been
  4378. preset to :
  4379. \begin{description}
  4380. \item[Disk 0] \var{'.'} default drive - hence current directory is used.
  4381. \item[Disk 1] \var{'/fd0/.'} floppy drive 1.
  4382. \item[Disk 2] \var{'/fd1/.'} floppy drive 2.
  4383. \item[Disk 3] \var{'/'} \file{C:} equivalent of DOS is the root partition.
  4384. \end{description}
  4385. Drives 4..26 can be set by your own applications with the \var{AddDisk} call.
  4386. The \var{AddDisk} call adds \var{Path} to the names of drive files, and
  4387. returns the number of the disk that corresponds to this drive. If you
  4388. add more than 21 drives, the count is wrapped to 4.
  4389. \Errors
  4390. None.
  4391. \SeeAlso
  4392. \seefl{DiskFree}{DiskFreeSys}, \seefl{DiskSize}{DiskSizeSys}
  4393. \end{functionl}
  4394. \begin{function}{CreateDir}
  4395. \Declaration
  4396. Function CreateDir(Const NewDir : String) : Boolean;
  4397. \Description
  4398. \var{CreateDir} creates a new directory with name \var{NewDir}.
  4399. If the directory doesn't contain an absolute path, then the directory is
  4400. created below the current working directory.
  4401. The function returns \var{True} if the directory was successfully
  4402. created, \var{False} otherwise.
  4403. \Errors
  4404. In case of an error, the function returns \var{False}.
  4405. \SeeAlso
  4406. \seef{RemoveDir}
  4407. \end{function}
  4408. \latex{\inputlisting{sysutex/ex26.pp}}
  4409. \html{\input{sysutex/ex26.tex}}
  4410. \begin{functionl}{DiskFree}{DiskFreeSys}
  4411. \Declaration
  4412. Function DiskFree(Drive : Byte) : Longint;
  4413. \Description
  4414. \var{DiskFree} returns the free space (in bytes) on disk \var{Drive}.
  4415. Drive is the number of the disk drive:
  4416. \begin{description}
  4417. \item[0] for the current drive.
  4418. \item[1] for the first floppy drive.
  4419. \item[2] for the second floppy drive.
  4420. \item[3] for the first hard-disk parttion.
  4421. \item[4-26] for all other drives and partitions.
  4422. \end{description}
  4423. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  4424. different than the \dos one, since the filesystem is seen as one big
  4425. directory tree. For this reason, the \var{DiskFree} and \seef{DiskSize}
  4426. functions must be mimicked using filenames that reside on the partitions.
  4427. For more information, see \seef{AddDisk}
  4428. \Errors
  4429. On error, \var{-1} is returned.
  4430. \SeeAlso
  4431. \seefl{DiskSize}{DiskSizeSys}, \seef{AddDisk}
  4432. \end{functionl}
  4433. \latex{\inputlisting{sysutex/ex27.pp}}
  4434. \html{\input{sysutex/ex27.tex}}
  4435. \begin{functionl}{DiskSize}{DiskSizeSys}
  4436. \Declaration
  4437. Function DiskSize(Drive : Byte) : Longint;
  4438. \Description
  4439. \var{DiskSize} returns the size (in bytes) of disk \var{Drive}.
  4440. Drive is the number of the disk drive:
  4441. \begin{description}
  4442. \item[0] for the current drive.
  4443. \item[1] for the first floppy drive.
  4444. \item[2] for the second floppy drive.
  4445. \item[3] for the first hard-disk parttion.
  4446. \item[4-26] for all other drives and partitions.
  4447. \end{description}
  4448. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  4449. different than the \dos one, since the filesystem is seen as one big
  4450. directory tree. For this reason, the \seef{DiskFree} and \var{DiskSize}
  4451. functions must be mimicked using filenames that reside on the partitions.
  4452. For more information, see \seef{AddDisk}
  4453. \Errors
  4454. On error, \var{-1} is returned.
  4455. \SeeAlso
  4456. \seefl{DiskFree}{DiskFreeSys}, \seef{AddDisk}
  4457. \end{functionl}
  4458. For an example, see \seefl{DiskFree}{DiskFreeSys}.
  4459. \begin{function}{GetCurrentDir}
  4460. \Declaration
  4461. Function GetCurrentDir : String;
  4462. \Description
  4463. \var{GetCurrentDir} returns the current working directory.
  4464. \Errors
  4465. None.
  4466. \SeeAlso
  4467. \seef{SetCurrentDir}, \seef{DiskFree}, \seef{DiskSize}
  4468. \end{function}
  4469. \latex{\inputlisting{sysutex/ex28.pp}}
  4470. \html{\input{sysutex/ex28.tex}}
  4471. \begin{function}{RemoveDir}
  4472. \Declaration
  4473. Function RemoveDir(Const Dir : String) : Boolean;
  4474. \Description
  4475. \var{RemoveDir} removes directory \var{Dir} from the disk.
  4476. If the directory is not absolue, it is appended to the current working
  4477. directory.
  4478. \Errors
  4479. In case of error (e.g. the directory isn't empty) the function returns
  4480. \var{False}. If successful, \var{True} is returned.
  4481. \SeeAlso
  4482. \end{function}
  4483. For an example, see \seef{CreateDir}.
  4484. \begin{function}{SetCurrentDir}
  4485. \Declaration
  4486. Function SetCurrentDir(Const NewDir : String) : Boolean;
  4487. \Description
  4488. \var{SetCurrentDir} sets the current working directory of your program
  4489. to \var{NewDir}. It returns \var{True} if the function was successfull,
  4490. \var{False} otherwise.
  4491. \Errors
  4492. In case of error, \var{False} is returned.
  4493. \SeeAlso
  4494. \seef{GetCurrentDir}
  4495. \end{function}
  4496. \latex{\inputlisting{sysutex/ex29.pp}}
  4497. \html{\input{sysutex/ex29.tex}}
  4498. \section{File handling functions}
  4499. \begin{function}{ChangeFileExt}
  4500. \Declaration
  4501. Function ChangeFileExt(const FileName, Extension: string): string;
  4502. \Description
  4503. \var{ChangeFileExt} changes the file extension in \var{FileName} to
  4504. \var{Extension}.
  4505. The extension \var{Extension} includes the starting \var{.} (dot).
  4506. The previous extension of \var{FileName} are all characters after the
  4507. last \var{.}, the \var{.} character included.
  4508. If \var{FileName} doesn't have an extension, \var{Extension} is just
  4509. appended.
  4510. \Errors
  4511. None.
  4512. \SeeAlso
  4513. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExpandFileName}
  4514. \end{function}
  4515. \begin{function}{DeleteFile}
  4516. \Declaration
  4517. Function DeleteFile(Const FileName : String) : Boolean;
  4518. \Description
  4519. \var{DeleteFile} deletes file \var{FileName} from disk. The function
  4520. returns \var{True} if the file was successfully removed, \var{False}
  4521. otherwise.
  4522. \Errors
  4523. On error, \var{False} is returned.
  4524. \SeeAlso
  4525. \seef{FileCreate}, \seef{FileExists}
  4526. \end{function}
  4527. \latex{\inputlisting{sysutex/ex31.pp}}
  4528. \html{\input{sysutex/ex31.tex}}
  4529. \begin{procedure}{DoDirSeparators}
  4530. \Declaration
  4531. Procedure DoDirSeparators(Var FileName : String);
  4532. \Description
  4533. This function replaces all directory separators \var{'\' and '/'}
  4534. to the directory separator character for the current system.
  4535. \Errors
  4536. None.
  4537. \SeeAlso
  4538. \seef{ExtractFileName}, \seef{ExtractFilePath}
  4539. \end{procedure}
  4540. \latex{\inputlisting{sysutex/ex32.pp}}
  4541. \html{\input{sysutex/ex32.tex}}
  4542. \begin{function}{ExpandFileName}
  4543. \Declaration
  4544. Function ExpandFileName(Const FileName : string): String;
  4545. \Description
  4546. \var{ExpandFileName} expands the filename to an absolute filename.
  4547. It changes all directory separator characters to the one appropriate for the
  4548. system first.
  4549. \Errors
  4550. None.
  4551. \SeeAlso
  4552. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4553. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4554. \end{function}
  4555. \latex{\inputlisting{sysutex/ex33.pp}}
  4556. \html{\input{sysutex/ex33.tex}}
  4557. \begin{function}{ExpandUNCFileName}
  4558. \Declaration
  4559. Function ExpandUNCFileName(Const FileName : string): String;
  4560. \Description
  4561. \var{ExpandUNCFileName} runs \seef{ExpandFileName} on \var{FileName}
  4562. and then attempts to replace the driveletter by the name of a shared disk.
  4563. \Errors
  4564. \SeeAlso
  4565. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4566. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4567. \end{function}
  4568. \begin{function}{ExtractFileDir}
  4569. \Declaration
  4570. Function ExtractFileDir(Const FileName : string): string;
  4571. \Description
  4572. \var{ExtractFileDir} returns only the directory part of \var{FileName},
  4573. not including a driveletter. The directory name has NO ending directory
  4574. separator, in difference with \seef{ExtractFilePath}.
  4575. \Errors
  4576. None.
  4577. \SeeAlso
  4578. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4579. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4580. \end{function}
  4581. \latex{\inputlisting{sysutex/ex34.pp}}
  4582. \html{\input{sysutex/ex34.tex}}
  4583. \begin{function}{ExtractFileDrive}
  4584. \Declaration
  4585. Function ExtractFileDrive(const FileName: string): string;
  4586. \Description
  4587. \var{Extract}
  4588. \Errors
  4589. \SeeAlso
  4590. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4591. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4592. \end{function}
  4593. For an example, see \seef{ExtractFileDir}.
  4594. \begin{function}{ExtractFileExt}
  4595. \Declaration
  4596. Function ExtractFileExt(const FileName: string): string;
  4597. \Description
  4598. \var{ExtractFileExt} returns the extension (including the
  4599. \var{.}(dot) character) of \var{FileName}.
  4600. \Errors
  4601. None.
  4602. \SeeAlso
  4603. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4604. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4605. \end{function}
  4606. For an example, see \seef{ExtractFileDir}.
  4607. \begin{function}{ExtractFileName}
  4608. \Declaration
  4609. Function ExtractFileName(const FileName: string): string;
  4610. \Description
  4611. \var{ExtractFileName} returns the filename part from \var{FileName}.
  4612. The filename consists of all characters after the last directory separator
  4613. character ('/' or '\') or drive letter.
  4614. The full filename can always be reconstucted by concatenating the result
  4615. of \seef{ExtractFilePath} and \var{ExtractFileName}.
  4616. \Errors
  4617. None.
  4618. \SeeAlso
  4619. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4620. \seef{ExtractFileDrive}, \seef{ExtractFileExt},\seef{ExtractRelativePath}
  4621. \end{function}
  4622. For an example, see \seef{ExtractFileDir}.
  4623. \begin{function}{ExtractFilePath}
  4624. \Declaration
  4625. Function ExtractFilePath(const FileName: string): string;
  4626. \Description
  4627. \var{ExtractFilePath} returns the path part (including driveletter) from
  4628. \var{FileName}. The path consists of all characters before the last
  4629. directory separator character ('/' or '\'), including the directory
  4630. separator itself.
  4631. In case there is only a drive letter, that will be returned.
  4632. The full filename can always be reconstucted by concatenating the result
  4633. of \var{ExtractFilePath} and \seef{ExtractFileName}.
  4634. \Errors
  4635. None.
  4636. \SeeAlso
  4637. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4638. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  4639. \end{function}
  4640. For an example, see \seef{ExtractFileDir}.
  4641. \begin{function}{ExtractRelativePath}
  4642. \Declaration
  4643. Function ExtractRelativePath(Const BaseName,DestNAme : String): String;
  4644. \Description
  4645. \var{ExtractRelativePath} constructs a relative path to go from
  4646. \var{BaseName} to \var{DestName}. If \var{DestName} is on another drive
  4647. (Not on Linux) then the whole \var{Destname} is returned.
  4648. {\em Note:} This function does not exist in the Delphi unit.
  4649. \Errors
  4650. None.
  4651. \SeeAlso
  4652. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  4653. \seef{ExtractFileDrive}, \seef{ExtractFileExt},
  4654. \end{function}
  4655. \latex{\inputlisting{sysutex/ex35.pp}}
  4656. \html{\input{sysutex/ex35.tex}}
  4657. \begin{function}{FileAge}
  4658. \Declaration
  4659. Function FileAge(Const FileName : String): Longint;
  4660. \Description
  4661. \var{FileAge} returns the last modification time of file \var{FileName}.
  4662. The FileDate format can be transformed to \var{TDateTime} format with the
  4663. \seef{FileDateToDateTime} function.
  4664. \Errors
  4665. In case of errors, \var{-1} is returned.
  4666. \SeeAlso
  4667. \seef{FileDateToDateTime}, \seef{FileExists}, \seef{FileGetAttr}
  4668. \end{function}
  4669. \latex{\inputlisting{sysutex/ex36.pp}}
  4670. \html{\input{sysutex/ex36.tex}}
  4671. \begin{procedure}{FileClose}
  4672. \Declaration
  4673. Procedure FileClose(Handle : Longint);
  4674. \Description
  4675. \var{FileClose} closes the file handle \var{Handle}. After this call,
  4676. attempting to read or write from the handle will result in an error.
  4677. \Errors
  4678. None.
  4679. \SeeAlso
  4680. \seef{FileCreate}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  4681. \seef{FileTruncate}, \seef{FileSeek}
  4682. \end{procedure}
  4683. For an example, see \seef{FileCreate}
  4684. \begin{function}{FileCreate}
  4685. \Declaration
  4686. Function FileCreate(Const FileName : String) : Longint;
  4687. \Description
  4688. \var{FileCreate} creates a new file with name \var{FileName} on the disk and
  4689. returns a file handle which can be used to read or write from the file with
  4690. the \seef{FileRead} and \seef{FileWrite} functions.
  4691. If a file with name \var{FileName} already existed on the disk, it is
  4692. overwritten.
  4693. \Errors
  4694. If an error occurs (e.g. disk full or non-existent path), the function
  4695. returns \var{-1}.
  4696. \SeeAlso
  4697. \seep{FileClose}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  4698. \seef{FileTruncate}, \seef{FileSeek}
  4699. \end{function}
  4700. \latex{\inputlisting{sysutex/ex37.pp}}
  4701. \html{\input{sysutex/ex37.tex}}
  4702. \begin{function}{FileExists}
  4703. \Declaration
  4704. Function FileExists(Const FileName : String) : Boolean;
  4705. \Description
  4706. \var{FileExists} returns \var{True} if a file with name \var{FileName}
  4707. exists on the disk, \var{False} otherwise.
  4708. \Errors
  4709. None.
  4710. \SeeAlso
  4711. \seef{FileAge}, \seef{FileGetAttr}, \seef{FileSetAttr}
  4712. \end{function}
  4713. \latex{\inputlisting{sysutex/ex38.pp}}
  4714. \html{\input{sysutex/ex38.tex}}
  4715. \begin{function}{FileGetAttr}
  4716. \Declaration
  4717. Function FileGetAttr(Const FileName : String) : Longint;
  4718. \Description
  4719. \var{FileGetAttr} returns the attribute settings of file
  4720. \var{FileName}. The attribute is a \var{OR}-ed combination
  4721. of the following constants:
  4722. \begin{description}
  4723. \item[faReadOnly] The file is read-only.
  4724. \item[faHidden] The file is hidden. (On \linux, this means that the filename
  4725. starts with a dot)
  4726. \item[faSysFile] The file is a system file (On \linux, this means that the
  4727. file is a character, block or FIFO file).
  4728. \item[faVolumeId] Volume Label. Not possible under \linux.
  4729. \item[faDirectory] File is a directory.
  4730. \item[faArchive] file is an archive. Not possible on \linux.
  4731. \end{description}
  4732. \Errors
  4733. In case of error, -1 is returned.
  4734. \SeeAlso
  4735. \seef{FileSetAttr}, \seef{FileAge}, \seef{FileGetDate}.
  4736. \end{function}
  4737. \latex{\inputlisting{sysutex/ex40.pp}}
  4738. \html{\input{sysutex/ex40.tex}}
  4739. \begin{function}{FileGetDate}
  4740. \Declaration
  4741. Function FileGetDate(Handle : Longint) : Longint;
  4742. \Description
  4743. \var{FileGetdate} returns the filetime of the opened file with filehandle
  4744. \var{Handle}. It is the same as \seef{FileAge}, with this difference that
  4745. \var{FileAge} only needs the file name, while \var{FilegetDate} needs an
  4746. open file handle.
  4747. \Errors
  4748. On error, -1 is returned.
  4749. \SeeAlso
  4750. \seef{FileAge}
  4751. \end{function}
  4752. \latex{\inputlisting{sysutex/ex39.pp}}
  4753. \html{\input{sysutex/ex39.tex}}
  4754. \begin{function}{FileOpen}
  4755. \Declaration
  4756. Function FileOpen(Const FileName : string; Mode : Integer) : Longint;
  4757. \Description
  4758. \var{FileOpen} opens a file with name \var{FileName} with mode \var{Mode}.
  4759. \var{Mode} can be one of the following constants:
  4760. \begin{description}
  4761. \item[fmOpenRead] The file is opened for reading.
  4762. \item[fmOpenWrite] The file is opened for writing.
  4763. \item[fmOpenReadWrite] The file is opened for reading and writing.
  4764. \end{description}
  4765. If the file has been successfully opened, it can be read from or written to
  4766. (depending on the \var{Mode} parameter) with the \seef{FileRead} and
  4767. \var{FileWrite} functions.
  4768. Remark that you cannot open a file if it doesn't exist yet, i.e. it will not
  4769. be created for you. If you want tp create a new file, or overwrite an old
  4770. one, use the \seef{FileCreate} function.
  4771. \Errors
  4772. On Error, -1 is returned.
  4773. \SeeAlso
  4774. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileRead},
  4775. \seef{FileTruncate}, \seef{FileSeek}
  4776. \end{function}
  4777. For an example, see \seef{FileRead}
  4778. \begin{function}{FileRead}
  4779. \Declaration
  4780. Function FileRead(Handle : Longint; Var Buffer; Count : longint) : Longint;
  4781. \Description
  4782. \var{FileRead} reads \var{Count} bytes from file-handle \var{Handle} and
  4783. stores them into \var{Buffer}. Buffer must be at least \var{Count} bytes
  4784. long. No checking on this is performed, so be careful not to overwrite any
  4785. memory. \var{Handle} must be the result of a \seef{FileOpen} call.
  4786. \Errors
  4787. On error, -1 is returned.
  4788. \SeeAlso
  4789. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen},
  4790. \seef{FileTruncate}, \seef{FileSeek}
  4791. \end{function}
  4792. For an example, see \seef{FileOpen}
  4793. \begin{function}{FileSearch}
  4794. \Declaration
  4795. Function FileSearch(Const Name, DirList : String) : String;
  4796. \Description
  4797. \var{FileSearch} looks for the file \var{Name} in \var{DirList}, where
  4798. dirlist is a list of directories, separated by semicolons or colons.
  4799. It returns the full filename of the first match found.
  4800. \Errors
  4801. On error, an empty string is returned.
  4802. \SeeAlso
  4803. \seef{ExpandFileName}, \seef{FindFirst}
  4804. \end{function}
  4805. \latex{\inputlisting{sysutex/ex41.pp}}
  4806. \html{\input{sysutex/ex41.tex}}
  4807. \begin{function}{FileSeek}
  4808. \Declaration
  4809. Function FileSeek(Handle,Offset,Origin : Longint) : Longint;
  4810. \Description
  4811. \var{FileSeek} sets the file pointer on position \var{Offset}, starting from
  4812. \var{Origin}. Origin can be one of the following values:
  4813. \begin{description}
  4814. \item[fsFromBeginning] \var{Offset} is relative to the first byte of the file. This
  4815. position is zero-based. i.e. the first byte is at offset 0.
  4816. \item[fsFromCurrent] \var{Offset} is relative to the current position.
  4817. \item[fsFromEnd] \var{Offset} is relative to the end of the file. This means
  4818. that \var{Offset} can only be zero or negative in this case.
  4819. \end{description}
  4820. If successfull, the function returns the new file position, relative to the
  4821. beginning of the file.
  4822. {\em Remark:} The abovementioned constants do not exist in Delphi.
  4823. \Errors
  4824. On error, -1 is returned.
  4825. \SeeAlso
  4826. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  4827. \seef{FileRead}, \seef{FileTruncate}
  4828. \end{function}
  4829. \latex{\inputlisting{sysutex/ex42.pp}}
  4830. \html{\input{sysutex/ex42.tex}}
  4831. For an example, see \seef{FileCreate}
  4832. \begin{functionl}{FileSetAttr (Not on Linux)}{FileSetAttr}
  4833. \Declaration
  4834. Function FileSetAttr(Const Filename : String; Attr: longint) : Longint;
  4835. \Description
  4836. \var{FileSetAttr} sets the attributes of \var{FileName} to \var{Attr}.
  4837. If the function was successful, 0 is returned, -1 otherwise.
  4838. \var{Attr} can be set to an OR-ed combination of the pre-defined
  4839. \var{faXXX} constants.
  4840. \Errors
  4841. On error, -1 is returned (always on linux).
  4842. \SeeAlso
  4843. \seef{FileGetAttr}, \seef{FileGetDate}, \seef{FileSetDate}.
  4844. \end{functionl}
  4845. \begin{functionl}{FileSetDate (Not on Linux)}{FileSetDate}
  4846. \Declaration
  4847. Function FileSetDate(Handle,Age : Longint) : Longint;
  4848. \Description
  4849. \var{FileSetDate} sets the file date of the file with handle \var{Handle}
  4850. to \var{Age}, where \var{Age} is a DOS date-and-time stamp value.
  4851. The function returns zero of successfull.
  4852. \Errors
  4853. On Linux, -1 is always returned, since this is impossible to implement.
  4854. On Windows and DOS, a negative error code is returned.
  4855. \SeeAlso
  4856. \end{functionl}
  4857. \begin{function}{FileTruncate}
  4858. \Declaration
  4859. Function FileTruncate(Handle,Size: Longint) : boolean;
  4860. \Description
  4861. \var{FileTruncate} truncates the file with handle \var{Handle} to
  4862. \var{Size} bytes. The file must have been opened for writing prior
  4863. to this call. The function returns \var{True} is successful, \var{False}
  4864. otherwise.
  4865. \Errors
  4866. On error, the function returns \var{False}.
  4867. \SeeAlso
  4868. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  4869. \seef{FileRead}, \seef{FileSeek}
  4870. \end{function}
  4871. For an example, see \seef{FileCreate}.
  4872. \begin{function}{FileWrite}
  4873. \Declaration
  4874. Function FileWrite(Handle : Longint; Var Buffer; Count : Longint) : Longint;
  4875. \Description
  4876. \var{FileWrite} writes \var{Count} bytes from \var{Buffer} to the file with
  4877. handle \var{Handle}. Prior to this call, the file must have been opened
  4878. for writing. \var{Buffer} must be at least \var{Count} bytes large, or
  4879. a memory access error may occur.
  4880. The function returns the number of bytes written, or -1 in case of an
  4881. error.
  4882. \Errors
  4883. In case of error, -1 is returned.
  4884. \SeeAlso
  4885. \seep{FileClose}, \seef{FileCreate}, \seef{FileOpen}
  4886. \seef{FileRead}, \seef{FileTruncate}, \seef{FileSeek}
  4887. \end{function}
  4888. For an example, see \seef{FileCreate}.
  4889. \begin{procedurel}{FindClose}{FindCloseSys}
  4890. \Declaration
  4891. Procedure FindClose(Var F : TSearchrec);
  4892. \Description
  4893. \var{FindClose} ends a series of \seef{FindFirst}/\seef{FindNext} calls,
  4894. and frees any memory used by these calls. It is {\em absolutely} necessary
  4895. to do this call, or huge memory losses may occur.
  4896. \Errors
  4897. None.
  4898. \SeeAlso
  4899. \seef{FindFirst}, \seef{FindNext}.
  4900. \end{procedurel}
  4901. For an example, see \seef{FindFirst}.
  4902. \begin{function}{FindFirst}
  4903. \Declaration
  4904. Function FindFirst(Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  4905. \Description
  4906. \var{FindFirst} looks for files that match the name (possibly with
  4907. wildcards) in \var{Path} and attributes \var{Attr}. It then fills up the
  4908. \var{Rslt} record with data gathered about the file. It returns 0 if a file
  4909. matching the specified criteria is found, a nonzero value (-1 on linux)
  4910. otherwise.
  4911. The \var{Rslt} record can be fed to subsequent calls to \var{FindNext}, in
  4912. order to find other files matching the specifications.
  4913. {\em remark:} A \var{FindFirst} call must {\em always} be followed by a
  4914. \seepl{FindClose}{FindCloseSys} call with the same \var{Rslt} record. Failure to do so will
  4915. result in memory loss.
  4916. \Errors
  4917. On error the function returns -1 on linux, a nonzero error code on Windows.
  4918. \SeeAlso
  4919. \seep{FindClose}{FindCloseSys}, \seef{FindNext}.
  4920. \end{function}
  4921. \latex{\inputlisting{sysutex/ex43.pp}}
  4922. \html{\input{sysutex/ex43.tex}}
  4923. \begin{function}{FindNext}
  4924. \Declaration
  4925. Function FindNext(Var Rslt : TSearchRec) : Longint;
  4926. \Description
  4927. \var{FindNext} finds a next occurrence of a search sequence initiated by
  4928. \var{FindFirst}. If another record matching the criteria in Rslt is found, 0
  4929. is returned, a nonzero constant is returned otherwise.
  4930. {\em remark:} The last \var{FindNext} call must {\em always} be followed by a
  4931. \var{FindClose} call with the same \var{Rslt} record. Failure to do so will
  4932. result in memory loss.
  4933. \Errors
  4934. On error (no more file is found), a nonzero constant is returned.
  4935. \SeeAlso
  4936. \seef{FindFirst}, \seep{FindClose}
  4937. \end{function}
  4938. For an example, see \seef{FindFirst}
  4939. \begin{function}{GetDirs}
  4940. \Declaration
  4941. Function GetDirs(Var DirName : String; Var Dirs : Array of pchar) : Longint;
  4942. \Description
  4943. \var{GetDirs} splits DirName in a null-byte separated list of directory names,
  4944. \var{Dirs} is an array of \var{PChars}, pointing to these directory names.
  4945. The function returns the number of directories found, or -1 if none were found.
  4946. DirName must contain only OSDirSeparator as Directory separator chars.
  4947. \Errors
  4948. None.
  4949. \SeeAlso
  4950. \seef{ExtractRelativePath}
  4951. \end{function}
  4952. \latex{\inputlisting{sysutex/ex45.pp}}
  4953. \html{\input{sysutex/ex45.tex}}
  4954. \begin{function}{RenameFile}
  4955. \Declaration
  4956. Function RenameFile(Const OldName, NewName : String) : Boolean;
  4957. \Description
  4958. \var{RenameFile} renames a file from \var{OldName} to \var{NewName}. The
  4959. function returns \var{True} if successful, \var{False} otherwise.
  4960. {\em Remark:} you cannot rename across disks or partitions.
  4961. \Errors
  4962. On Error, \var{False} is returned.
  4963. \SeeAlso
  4964. \seef{DeleteFile}
  4965. \end{function}
  4966. \latex{\inputlisting{sysutex/ex44.pp}}
  4967. \html{\input{sysutex/ex44.tex}}
  4968. \begin{function}{SetDirSeparators}
  4969. \Declaration
  4970. Function SetDirSeparators(Const FileName : String) : String;
  4971. \Description
  4972. \var{SetDirSeparators} returns \var{FileName} with all possible
  4973. DirSeparators replaced by \var{OSDirSeparator}.
  4974. \Errors
  4975. None.
  4976. \SeeAlso
  4977. \seef{ExpandFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir}
  4978. \end{function}
  4979. \latex{\inputlisting{sysutex/ex47.pp}}
  4980. \html{\input{sysutex/ex47.tex}}
  4981. \section{PChar functions}
  4982. \subsection{Introduction}
  4983. Most PChar functions are the same as their counterparts in the \file{STRINGS}
  4984. unit. The following functions are the same :
  4985. \begin{enumerate}
  4986. \item \seef{StrCat} : Concatenates two \var{PChar} strings.
  4987. \item \seef{StrComp} : Compares two \var{PChar} strings.
  4988. \item \seef{StrCopy} : Copies a \var{PChar} string.
  4989. \item \seef{StrECopy} : Copies a \var{PChar} string and returns a pointer to
  4990. the terminating null byte.
  4991. \item \seef{StrEnd} : Returns a pointer to the terminating null byte.
  4992. \item \seef{StrIComp} : Case insensitive compare of 2 \var{PChar} strings.
  4993. \item \seef{StrLCat} : Appends at most L characters from one \var{PChar} to
  4994. another \var{PChar}.
  4995. \item \seef{StrLComp} : Case sensitive compare of at most L characters of 2
  4996. \var{PChar} strings.
  4997. \item \seef{StrLCopy} : Copies at most L characters from one \var{PChar} to
  4998. another.
  4999. \item \seef{StrLen} : Returns the length (exclusive terminating null byte)
  5000. of a \var{PChar} string.
  5001. \item \seef{StrLIComp} : Case insensitive compare of at most L characters of 2
  5002. \var{PChar} strings.
  5003. \item \seef{StrLower} : Converts a \var{PChar} to all lowercase letters.
  5004. \item \seef{StrMove} : Moves one \var{PChar} to another.
  5005. \item \seef{StrNew} : Makes a copy of a \var{PChar} on the heap, and returns
  5006. a pointer to this copy.
  5007. \item \seef{StrPos} : Returns the position of one \var{PChar} string in
  5008. another?
  5009. \item \seef{StrRScan} : returns a pointer to the last occurrence of on
  5010. \var{PChar} string in another one.
  5011. \item \seef{StrScan} : returns a pointer to the first occurrence of on
  5012. \var{PChar} string in another one.
  5013. \item \seef{StrUpper} : Converts a \var{PChar} to all uppercase letters.
  5014. \end{enumerate}
  5015. The subsequent functions are different from their counterparts in
  5016. \file{STRINGS}, although the same examples can be used.
  5017. \begin{functionl}{StrAlloc}{StrAllocSys}
  5018. \Declaration
  5019. Function StrAlloc(Size: cardinal): PChar;
  5020. \Description
  5021. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  5022. terminating \var{\#0} included, and returns a pointer to it.
  5023. Additionally, \var{StrAlloc} allocates 4 extra bytes to store the size of
  5024. the allocated memory. Therefore this function is NOT compatible with the
  5025. \seef{StrAlloc} function of the \var{Strings} unit.
  5026. \Errors
  5027. None.
  5028. \SeeAlso
  5029. \seef{StrBufSize}, \seepl{StrDispose}{StrDisposeSys}, \seef{StrAlloc}
  5030. \end{functionl}
  5031. For an example, see \seef{StrBufSize}.
  5032. \begin{function}{StrBufSize}
  5033. \Declaration
  5034. Function StrBufSize(var Str: PChar): cardinal;
  5035. \Description
  5036. \var{StrBufSize} returns the memory allocated for \var{Str}. This function
  5037. ONLY gives the correct result if \var{Str} was allocated using
  5038. \seefl{StrAlloc}{StrAllocSys}.
  5039. \Errors
  5040. If no more memory is available, a runtime error occurs.
  5041. \SeeAlso
  5042. \seefl{StrAlloc}{StrAllocSys}.\seepl{StrDispose}{StrDisposeSys}.
  5043. \end{function}
  5044. \latex{\inputlisting{sysutex/ex46.pp}}
  5045. \html{\input{sysutex/ex46.tex}}
  5046. \begin{procedurel}{StrDispose}{StrDisposeSys}
  5047. \Declaration
  5048. Procedure StrDispose(var Str: PChar);
  5049. \Description
  5050. \var{StrDispose} frees any memory allocated for \var{Str}. This function
  5051. will only function correctly if \var{Str} has been allocated using
  5052. \seefl{StrAlloc}{StrAllocSys} from the \file{SYSUTILS} unit.
  5053. \Errors
  5054. If an invalid pointer is passed, or a pointer not allocated with
  5055. \var{StrAlloc}, an error may occur.
  5056. \SeeAlso
  5057. \seef{StrBufSize}, \seefl{StrAlloc}{StrAllocSys}, \seep{StrDispose}
  5058. \end{procedurel}
  5059. For an example, see \seef{StrBufSize}.
  5060. \begin{functionl}{StrPCopy}{StrPCopySys}
  5061. \Declaration
  5062. Function StrPCopy(Dest: PChar; Source: string): PChar;
  5063. \Description
  5064. \var{StrPCopy} Converts the Ansistring in \var{Source} to a Null-terminated
  5065. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  5066. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  5067. \Errors
  5068. No checking is performed to see whether \var{Dest} points to enough memory
  5069. to contain \var{Source}.
  5070. \SeeAlso
  5071. \seefl{StrPLCopy}{StrPLCopySys}, \seef{StrPCopy}
  5072. \end{functionl}
  5073. For an example, see \seef{StrPCopy}.
  5074. \begin{functionl}{StrPLCopy}{StrPLCopySys}
  5075. \Declaration
  5076. Function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar;
  5077. \Description
  5078. \var{StrPLCopy} Converts maximally \var{MaxLen} characters of the
  5079. Ansistring in \var{Source} to a Null-terminated string, and copies
  5080. it to \var{Dest}. \var{Dest} needs enough room to contain
  5081. the characters.
  5082. \Errors
  5083. No checking is performed to see whether \var{Dest} points to enough memory
  5084. to contain L characters of \var{Source}.
  5085. \Errors
  5086. \SeeAlso
  5087. \seefl{StrPCopy}{StrPCopySys}.
  5088. \end{functionl}
  5089. For an example, see \seef{StrPLCopy}.
  5090. \begin{functionl}{StrPas}{StrPasSys}
  5091. \Declaration
  5092. Function StrPas(Str: PChar): string;
  5093. \Description
  5094. Converts a null terminated string in \var{Str} to an Ansitring, and returns
  5095. this string. This string is NOT truncated at 255 characters as is the
  5096. \Errors
  5097. None.
  5098. \SeeAlso
  5099. \seef{StrPas}.
  5100. \end{functionl}
  5101. For an example, see \seef{StrPas}.
  5102. \section{String handling functions}
  5103. \begin{function}{AdjustLineBreaks}
  5104. \Declaration
  5105. Function AdjustLineBreaks(const S: string): string;
  5106. \Description
  5107. \var{AdjustLineBreaks} will change all \var{\#13} characters with
  5108. \var{\#13\#10} on \windowsnt and \dos. On \linux, all \var{\#13\#10}
  5109. character pairs are converted to \var{#10} and single \var{\#13}
  5110. characters also.
  5111. \Errors
  5112. None.
  5113. \SeeAlso
  5114. \seef{AnsiCompareStr}, \seef{AnsiCompareText}
  5115. \end{function}
  5116. \latex{\inputlisting{sysutex/ex48.pp}}
  5117. \html{\input{sysutex/ex48.tex}}
  5118. \begin{function}{AnsiCompareStr}
  5119. \Declaration
  5120. Function AnsiCompareStr(const S1, S2: string): integer;
  5121. \Description
  5122. \var{AnsiCompareStr} compares two strings and returns the following
  5123. result:
  5124. \begin{description}
  5125. \item[<0] if \var{S1<S2}.
  5126. \item[0] if \var{S1=S2}.
  5127. \item[>0] if \var{S1>S2}.
  5128. \end{description}
  5129. the comparision takes into account Ansi characters, i.e. it takes
  5130. care of strange accented characters. Contrary to \seef{CompareAnsiText},
  5131. the comparision is case sensitive.
  5132. \Errors
  5133. None.
  5134. \SeeAlso
  5135. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  5136. \end{function}
  5137. \latex{\inputlisting{sysutex/ex49.pp}}
  5138. \html{\input{sysutex/ex49.tex}}
  5139. \begin{function}{AnsiCompareText}
  5140. \Declaration
  5141. Function AnsiCompareText(const S1, S2: string): integer;
  5142. \Description
  5143. \Description
  5144. \var{AnsiCompareText} compares two strings and returns the following
  5145. result:
  5146. \begin{description}
  5147. \item[<0] if \var{S1<S2}.
  5148. \item[0] if \var{S1=S2}.
  5149. \item[>0] if \var{S1>S2}.
  5150. \end{description}
  5151. the comparision takes into account Ansi characters, i.e. it takes
  5152. care of strange accented characters. Contrary to \seef{CompareAnsiStr},
  5153. the comparision is case insensitive.
  5154. \Errors
  5155. None.
  5156. \SeeAlso
  5157. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  5158. \end{function}
  5159. \latex{\inputlisting{sysutex/ex50.pp}}
  5160. \html{\input{sysutex/ex50.tex}}
  5161. \begin{function}{AnsiExtractQuotedStr}
  5162. \Declaration
  5163. Function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  5164. \Description
  5165. \var{AnsiExtractQuotedStr} Returns \var{Src} as a string,, with \var{Quute}
  5166. characters removed from the beginning and end of the string, and double
  5167. \var{Quote} characters replaced by a single \var{Quote} characters.
  5168. As such, it revereses the action of \seef{AnsiQuotedStr}.
  5169. \Errors
  5170. None.
  5171. \SeeAlso
  5172. \seef{AnsiQuotedStr}
  5173. \end{function}
  5174. \latex{\inputlisting{sysutex/ex51.pp}}
  5175. \html{\input{sysutex/ex51.tex}}
  5176. \begin{function}{AnsiLastChar}
  5177. \Declaration
  5178. Function AnsiLastChar(const S: string): PChar;
  5179. \Description
  5180. This function returns a pointer to the last character of \var{S}.
  5181. Since multibyte characters are not yet supported, this is the same
  5182. as \var{@S[Length(S)])}.
  5183. \Errors
  5184. None.
  5185. \SeeAlso
  5186. \seef{AnsiStrLastChar}
  5187. \end{function}
  5188. \latex{\inputlisting{sysutex/ex52.pp}}
  5189. \html{\input{sysutex/ex52.tex}}
  5190. \begin{function}{AnsiLowerCase}
  5191. \Declaration
  5192. Function AnsiLowerCase(const s: string): string;
  5193. \Description
  5194. \var{AnsiLowerCase} converts the string \var{S} to lowercase characters
  5195. and returns the resulting string.
  5196. It takes into account the operating system language
  5197. settings when doing this, so spcial characters are converted correctly as
  5198. well.
  5199. {\em Remark} On linux, no language setting is taken in account yet.
  5200. \Errors
  5201. None.
  5202. \SeeAlso
  5203. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiStrUpper}
  5204. \end{function}
  5205. \latex{\inputlisting{sysutex/ex53.pp}}
  5206. \html{\input{sysutex/ex53.tex}}
  5207. \begin{function}{AnsiQuotedStr}
  5208. \Declaration
  5209. Function AnsiQuotedStr(const S: string; Quote: char): string;
  5210. \Description
  5211. \var{AnsiQuotedString} quotes the string \var{S} and returns the result.
  5212. This means that it puts the \var{Quote} character at both the beginning and
  5213. end of the string and replaces any occurrence of \var{Quote} in \var{S}
  5214. with 2 \var{Quote} characters. The action of \var{AnsiQuotedString} can be
  5215. reversed by \seef{AnsiExtractQuotedStr}.
  5216. \Errors
  5217. None.
  5218. \SeeAlso
  5219. \seef{AnsiExtractQuotedStr}
  5220. \end{function}
  5221. For an example, see \seef{AnsiExtractQuotedStr}
  5222. \begin{function}{AnsiStrComp}
  5223. \Declaration
  5224. Function AnsiStrComp(S1, S2: PChar): integer;
  5225. \Description
  5226. \var{AnsiStrComp} compares 2 \var{PChar} strings, and returns the following
  5227. result:
  5228. \begin{description}
  5229. \item[<0] if \var{S1<S2}.
  5230. \item[0] if \var{S1=S2}.
  5231. \item[>0] if \var{S1>S2}.
  5232. \end{description}
  5233. The comparision of the two strings is case-sensitive.
  5234. The function does not yet take internationalization settings into account.
  5235. \Errors
  5236. None.
  5237. \SeeAlso
  5238. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  5239. \end{function}
  5240. \latex{\inputlisting{sysutex/ex54.pp}}
  5241. \html{\input{sysutex/ex54.tex}}
  5242. \begin{function}{AnsiStrIComp}
  5243. \Declaration
  5244. Function AnsiStrIComp(S1, S2: PChar): integer;
  5245. \Description
  5246. \var{AnsiStrIComp} compares 2 \var{PChar} strings, and returns the following
  5247. result:
  5248. \begin{description}
  5249. \item[<0] if \var{S1<S2}.
  5250. \item[0] if \var{S1=S2}.
  5251. \item[>0] if \var{S1>S2}.
  5252. \end{description}
  5253. The comparision of the two strings is case-insensitive.
  5254. The function does not yet take internationalization settings into account.
  5255. \Errors
  5256. None.
  5257. \SeeAlso
  5258. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  5259. \end{function}
  5260. \latex{\inputlisting{sysutex/ex55.pp}}
  5261. \html{\input{sysutex/ex55.tex}}
  5262. \begin{function}{AnsiStrLastChar}
  5263. \Declaration
  5264. function AnsiStrLastChar(Str: PChar): PChar;
  5265. \Declaration
  5266. \var{AnsiStrLastChar} returns a pointer to the last character of \var{Str}.
  5267. Since multibyte characters are not yet supported, this is the same
  5268. as \var{StrEnd(Str)-1}.
  5269. \Errors
  5270. None.
  5271. \SeeAlso
  5272. \seef{AnsiLastChar}
  5273. \end{function}
  5274. \latex{\inputlisting{sysutex/ex58.pp}}
  5275. \html{\input{sysutex/ex58.tex}}
  5276. \begin{function}{AnsiStrLComp}
  5277. \Declaration
  5278. Function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
  5279. \Description
  5280. \var{AnsiStrLComp} compares the first \var{Maxlen} characters of
  5281. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  5282. result:
  5283. \begin{description}
  5284. \item[<0] if \var{S1<S2}.
  5285. \item[0] if \var{S1=S2}.
  5286. \item[>0] if \var{S1>S2}.
  5287. \end{description}
  5288. The comparision of the two strings is case-sensitive.
  5289. The function does not yet take internationalization settings into account.
  5290. \Errors
  5291. None.
  5292. \SeeAlso
  5293. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  5294. \end{function}
  5295. \latex{\inputlisting{sysutex/ex56.pp}}
  5296. \html{\input{sysutex/ex56.tex}}
  5297. \begin{function}{AnsiStrLIComp}
  5298. \Declaration
  5299. Function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
  5300. \Description
  5301. \var{AnsiStrLIComp} compares the first \var{Maxlen} characters of
  5302. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  5303. result:
  5304. \begin{description}
  5305. \item[<0] if \var{S1<S2}.
  5306. \item[0] if \var{S1=S2}.
  5307. \item[>0] if \var{S1>S2}.
  5308. \end{description}
  5309. The comparision of the two strings is case-insensitive.
  5310. The function does not yet take internationalization settings into account.
  5311. \Errors
  5312. None.
  5313. \SeeAlso
  5314. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  5315. \end{function}
  5316. \latex{\inputlisting{sysutex/ex57.pp}}
  5317. \html{\input{sysutex/ex57.tex}}
  5318. \begin{function}{AnsiStrLower}
  5319. \Declaration
  5320. Function AnsiStrLower(Str: PChar): PChar;
  5321. \Description
  5322. \var{AnsiStrLower} converts the PChar \var{Str} to lowercase characters
  5323. and returns the resulting pchar. Note that \var{Str} itself is modified,
  5324. not a copy, as in the case of \seef{AnsiLowerCase}.
  5325. It takes into account the operating system language
  5326. settings when doing this, so spcial characters are converted correctly as
  5327. well.
  5328. {\em Remark} On linux, no language setting is taken in account yet.
  5329. \Errors
  5330. None.
  5331. \SeeAlso
  5332. \seef{AnsiStrUpper}, \seef{AnsiLowercase}
  5333. \end{function}
  5334. \Errors
  5335. \SeeAlso
  5336. \end{function}
  5337. \latex{\inputlisting{sysutex/ex59.pp}}
  5338. \html{\input{sysutex/ex59.tex}}
  5339. \begin{function}{AnsiStrUpper}
  5340. \Declaration
  5341. Function AnsiStrUpper(Str: PChar): PChar;
  5342. \Description
  5343. \var{AnsiStrUpper} converts the \var{PChar} \var{Str} to uppercase characters
  5344. and returns the resulting string. Note that \var{Str} itself is modified,
  5345. not a copy, as in the case of \seef{AnsiUpperCase}.
  5346. It takes into account the operating system language
  5347. settings when doing this, so spcial characters are converted correctly as
  5348. well.
  5349. {\em Remark} On linux, no language setting is taken in account yet.
  5350. \Errors
  5351. None.
  5352. \SeeAlso
  5353. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  5354. \end{function}
  5355. \latex{\inputlisting{sysutex/ex60.pp}}
  5356. \html{\input{sysutex/ex60.tex}}
  5357. \begin{function}{AnsiUpperCase}
  5358. \Declaration
  5359. Function AnsiUpperCase(const s: string): string;
  5360. \Description
  5361. \var{AnsiUpperCase} converts the string \var{S} to uppercase characters
  5362. and returns the resulting string.
  5363. It takes into account the operating system language
  5364. settings when doing this, so spcial characters are converted correctly as
  5365. well.
  5366. {\em Remark} On linux, no language setting is taken in account yet.
  5367. \Errors
  5368. None.
  5369. \SeeAlso
  5370. \seef{AnsiStrUpper}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  5371. \end{function}
  5372. \latex{\inputlisting{sysutex/ex61.pp}}
  5373. \html{\input{sysutex/ex61.tex}}
  5374. \begin{procedure}{AppendStr}
  5375. \Declaration
  5376. Procedure AppendStr(var Dest: String; const S: string);
  5377. \Description
  5378. \var{AppendStr} appends \var{S} to Dest.
  5379. This function is provided for Delphi
  5380. compatibility only, since it is completely equivalent to \var{Dest:=Dest+S}.
  5381. \Errors
  5382. None.
  5383. \SeeAlso
  5384. \seep{AssignStr},\seef{NewStr}, \seep{DisposeStr}
  5385. \end{procedure}
  5386. \latex{\inputlisting{sysutex/ex62.pp}}
  5387. \html{\input{sysutex/ex62.tex}}
  5388. \begin{procedure}{AssignStr}
  5389. \Declaration
  5390. Procedure AssignStr(var P: PString; const S: string);
  5391. \Description
  5392. \var{AssignStr} allocates \var{S} to P. The old value of \var{P} is
  5393. disposed of.
  5394. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  5395. are managed on the heap and should be preferred to the mechanism of
  5396. dynamically allocated strings.
  5397. \Errors
  5398. None.
  5399. \SeeAlso
  5400. \seef{NewStr}, \seep{AppendStr}, \seep{DisposeStr}
  5401. \end{procedure}
  5402. \latex{\inputlisting{sysutex/ex63.pp}}
  5403. \html{\input{sysutex/ex63.tex}}
  5404. \begin{function}{BCDToInt}
  5405. \Declaration
  5406. Function BCDToInt(Value: integer): integer;
  5407. \Description
  5408. \var{BCDToInt} converts a \var{BCD} coded integer to a normal integer.
  5409. \Errors
  5410. None.
  5411. \SeeAlso
  5412. \seef{StrToInt}, \seef{IntToStr}
  5413. \end{function}
  5414. \latex{\inputlisting{sysutex/ex64.pp}}
  5415. \html{\input{sysutex/ex64.tex}}
  5416. \begin{function}{CompareMem}
  5417. \Declaration
  5418. Function CompareMem(P1, P2: Pointer; Length: cardinal): integer;
  5419. \Description
  5420. \var{CompareMem} compares, byte by byte, 2 memory areas pointed
  5421. to by \var{P1} and \var{P2}, for a length of \var{L} bytes.
  5422. It returns the following values:
  5423. \begin{description}
  5424. \item[<0] if at some position the byte at \var{P1} is less than the byte at the
  5425. same postion at \var{P2}.
  5426. \item[0] if all \var{L} bytes are the same.
  5427. \item[3]
  5428. \end{description}
  5429. \Errors
  5430. \SeeAlso
  5431. \end{function}
  5432. \begin{function}{CompareStr}
  5433. \Declaration
  5434. Function CompareStr(const S1, S2: string): Integer;
  5435. \Description
  5436. \var{CompareStr} compares two strings, \var{S1} and \var{S2},
  5437. and returns the following
  5438. result:
  5439. \begin{description}
  5440. \item[<0] if \var{S1<S2}.
  5441. \item[0] if \var{S1=S2}.
  5442. \item[>0] if \var{S1>S2}.
  5443. \end{description}
  5444. The comparision of the two strings is case-sensitive.
  5445. The function does not take internationalization settings into account, it
  5446. simply compares ASCII values.
  5447. \Errors
  5448. None.
  5449. \SeeAlso
  5450. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareText}
  5451. \end{function}
  5452. \latex{\inputlisting{sysutex/ex65.pp}}
  5453. \html{\input{sysutex/ex65.tex}}
  5454. \begin{function}{CompareText}
  5455. \Declaration
  5456. Function CompareText(const S1, S2: string): integer;
  5457. \Description
  5458. \var{CompareText} compares two strings, \var{S1} and \var{S2},
  5459. and returns the following
  5460. result:
  5461. \begin{description}
  5462. \item[<0] if \var{S1<S2}.
  5463. \item[0] if \var{S1=S2}.
  5464. \item[>0] if \var{S1>S2}.
  5465. \end{description}
  5466. The comparision of the two strings is case-insensitive.
  5467. The function does not take internationalization settings into account, it
  5468. simply compares ASCII values.
  5469. \Errors
  5470. None.
  5471. \SeeAlso
  5472. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareStr}
  5473. \end{function}
  5474. \latex{\inputlisting{sysutex/ex66.pp}}
  5475. \html{\input{sysutex/ex66.tex}}
  5476. \begin{procedurel}{DisposeStr}{DisposeStrSys}
  5477. \Declaration
  5478. Procedure DisposeStr(S: PString);
  5479. \Description
  5480. \var{DisposeStr} removes the dynamically allocated string \var{S} from the
  5481. heap, and releases the occupied memory.
  5482. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  5483. are managed on the heap and should be preferred to the mechanism of
  5484. dynamically allocated strings.
  5485. \Errors
  5486. None.
  5487. \SeeAlso
  5488. \seef{NewStr}, \seep{AppendStr}, \seep{AssignStr}
  5489. \end{procedurel}
  5490. For an example, see \seep{DisposeStr}.
  5491. \begin{function}{FloatToStr}
  5492. \Declaration
  5493. Function FloatToStr(Value: Extended): String;
  5494. \Description
  5495. \var{FloatToStr} converts the floating point variable \var{Value} to a
  5496. string representation. It will choose the shortest possible notation of the
  5497. two following formats:
  5498. \begin{description}
  5499. \item[Fixed format] will represent the string in fixed notation,
  5500. \item[Decimal format] will represent the string in scientific notation.
  5501. \end{description}
  5502. (more information on these formats can be found in \seef{FloatToStrF})
  5503. \var{FloatToStr} is completely equivalent to a \var{FloatToStrF(Value, ffGeneral,
  5504. 15, 0);} call.
  5505. \Errors
  5506. None.
  5507. \SeeAlso
  5508. \seef{FloatToStrF}
  5509. %, \seef{FormatFloat}
  5510. \end{function}
  5511. \latex{\inputlisting{sysutex/ex67.pp}}
  5512. \html{\input{sysutex/ex67.tex}}
  5513. \begin{function}{FloatToStrF}
  5514. \Declaration
  5515. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  5516. \Description
  5517. \var{FloatToStrF} converts the floating point number \var{value} to a string
  5518. representation, according to the settings of the parameters \var{Format},
  5519. \var{Precision} and \var{Digits}.
  5520. The meaning of the \var{Precision} and \var{Digits} parameter depends on the
  5521. \var{Format} parameter. The format is controlled mainly by the \var{Format}
  5522. parameter. It can have one of the following values:
  5523. \begin{description}
  5524. \item[ffcurrency] Money format. \var{Value} is converted to a string using
  5525. the global variables \var{CurrencyString}, \var{CurrencyFormat} and
  5526. \var{NegCurrencyFormat}. The \var{Digits} paramater specifies the number of digits
  5527. following the decimal point and should be in the range -1 to 18. If Digits
  5528. equals \var{-1}, \var{CurrencyDecimals} is assumed. The \var{Precision} parameter is ignored.
  5529. %
  5530. \item[ffExponent] Scientific format. \var{Value} is converted to a
  5531. string using scientific notation: 1 digit before the decimal point, possibly
  5532. preceded by a minus sign if \var{Value} is negative. The number of
  5533. digits after the decimal point is controlled by \var{Precision} and must lie
  5534. in the range 0 to 15.
  5535. %
  5536. \item[ffFixed] Fixed point format. \var{Value} is converted to a string
  5537. using fixed point notation. The result is composed of all digits of the
  5538. integer part of \var{Value}, preceded by a minus sign if \var{Value} is
  5539. negative. Following the integer part is \var{DecimalSeparator} and then the
  5540. fractional part of \var{Value}, rounded off to \var{Digits} numbers.
  5541. If the number is too large then the result will be in scientific notation.
  5542. %
  5543. \item[ffGeneral] General number format. The argument is converted to a
  5544. string using \var{ffExponent} or \var{ffFixed} format, depending on wich one
  5545. gives the shortest string. There will be no trailing zeroes. If \var{Value}
  5546. is less than \var{0.00001} or if the number of decimals left of the decimal
  5547. point is larger than \var{Precision} then scientific notation is used, and
  5548. \var{Digits} is the minimum number of digits in the exponent. Otherwise
  5549. \var{Digits} is ignored.
  5550. \item[ffnumber] Is the same as \var{ffFixed}, except that thousand separators
  5551. are inserted in the resultig string.
  5552. \end{description}
  5553. \Errors
  5554. None.
  5555. \SeeAlso
  5556. \seef{FloatToStr}, \seef{FoatToText}
  5557. \end{function}
  5558. \latex{\inputlisting{sysutex/ex68.pp}}
  5559. \html{\input{sysutex/ex68.tex}}
  5560. \begin{function}{FloatToText}
  5561. \Declaration
  5562. Function FloatToText(Buffer : Pchar;Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): Longint;
  5563. \Description
  5564. \var{FloatToText} converts the floating point variable \var{Value} to a
  5565. string representation and stores it in \var{Buffer}. The conversion is
  5566. giverned by \var{format}, \var{Precisison} and \var{Digits}.
  5567. more information on these parameters can be found in \seef{FloatToStrF}.
  5568. \var{Buffer} should point to enough space to hold the result. No checking on
  5569. this is performed.
  5570. The result is the number of characters that was copied in \var{Buffer}.
  5571. \Errors
  5572. None.
  5573. \SeeAlso
  5574. \seef{FloatToStr}, \seef{FloatToStrF}
  5575. \end{function}
  5576. \latex{\inputlisting{sysutex/ex69.pp}}
  5577. \html{\input{sysutex/ex69.tex}}
  5578. \begin{procedure}{FmtStr}
  5579. \Declaration
  5580. Procedure (Var Res: String; Const Fmt : String; Const args: Array of const);
  5581. \Description
  5582. \var{FmtStr} calls \seef{Format} with \var{Fmt} and \var{Args} as arguments,
  5583. and stores the result in \var{Res}. For more information on how the
  5584. resulting string is composed, see \seef{Format}.
  5585. \Errors
  5586. In case of error, a \var{EConvertError} exception is raised.
  5587. \SeeAlso
  5588. \seef{Format}, \seef{FormatBuf}.
  5589. \end{procedure}
  5590. \latex{\inputlisting{sysutex/ex70.pp}}
  5591. \html{\input{sysutex/ex70.tex}}
  5592. \begin{function}{Format}
  5593. \Declaration
  5594. Function Format(Const Fmt : String; const Args : Array of const) : String;
  5595. \Description
  5596. Format replaces all placeholders in\var{Fmt} with the arguments passed in
  5597. \var{Args} and returns the resulting string. A placeholder looks as follows:
  5598. \begin{verbatim}
  5599. '%' [Index':'] ['-'] [Width] ['.' Precision] ArgType
  5600. \end{verbatim}
  5601. elements between single quotes must be typed as shown without the quotes,
  5602. and elements between square brackets \var{[ ]} are optional. The meaning
  5603. of the different elements is shown below:
  5604. \begin{description}
  5605. \item['\%'] starts the placeholder. If you want to insert a literal
  5606. \var{\%} character, then you must insert two of them : \var{\%\%}.
  5607. \item[Index ':'] takes the \var{Index}-th element in the argument array
  5608. as the element to insert.
  5609. \item['-'] tells \var{Format} to left-align the inserted text. The default
  5610. behaviour is to right-align inserted text. This can only take effect if the
  5611. \var{Width} element is also specified.
  5612. \item[Width] the inserted string must have at least have \var{Width}
  5613. characters. If not, the inserted string will be padded with spaces. By
  5614. default, the string is left-padded, resulting in a right-aligned string.
  5615. This behaviour can be changed by the \var{'-'} character.
  5616. \item['.' Precision] Indicates the precision to be used when converting
  5617. the argument. The exact meaning of this parameter depends on \var{ArgType}.
  5618. \end{description}
  5619. The \var{Index}, \var{Width} and \var{Precision} parameters can be replaced
  5620. by \var{*}, in which case their value will be read from the next element in
  5621. the \var{Args} array. This value must be an integer, or an
  5622. \var{EConvertError} exception will be raised.
  5623. The argument type is determined from \var{ArgType}. It can have one of the
  5624. following values (case insensitive):
  5625. \begin{description}
  5626. \item[D] Decimal format. The next argument in the \var{Args} array should be
  5627. an integer. The argument is converted to a decimal string,. If precision is
  5628. specified, then the string will have at least \var{Precision} digits in it.
  5629. If needed, the string is (left) padded with zeroes.
  5630. \item[E] scientific format. The next argument in the \var{Args} array should
  5631. be a Floating point value. The argument is converted to a decimal string
  5632. using scientific notation, using \seef{FormatFloat}, where the optional
  5633. precision is used to specify the total number of decimals. (defalt a valueof
  5634. 15 is used). The exponent is formatted using maximally 3 digits.
  5635. In short, the \var{E} specifier formats it's arguument as follows:
  5636. \begin{verbatim}
  5637. FloatToStrF(Argument,ffexponent,Precision,3)
  5638. \end{verbatim}
  5639. \item[F] fixed point format. The next argument in the \var{Args} array
  5640. should be a floating point value. The argument is converted to a
  5641. decimal string, using fixed notation (see \seef{FloatToStrF}).
  5642. \var{Precision} indicates the number of digits following the
  5643. decimal point.
  5644. In short, the \var{F} specifier formats it's arguument as follows:
  5645. \begin{verbatim}
  5646. FloatToStrF(Argument,ffFixed,ffixed,9999,Precision)
  5647. \end{verbatim}
  5648. \item[G] General number format. The next argument in the \var{Args} array
  5649. should be a floating point value. The argument is converted to a decimal
  5650. string using fixed point notation or scientific notation, depending on which
  5651. gives the shortest result. \var{Precision} is used to determine the number
  5652. of digits after the decimal point.
  5653. In short, the \var{G} specifier formats it's arguument as follows:
  5654. \begin{verbatim}
  5655. FloatToStrF(Argument,ffGeneral,Precision,3)
  5656. \end{verbatim}
  5657. \item[M] Currency format. the next argument in the var{Args} array must
  5658. be a floating point value. The argument is converted to a decimal string
  5659. using currency notation. This means that fixed-point notation is used, but
  5660. that the currency symbol is appended. If precision is specified, then
  5661. then it overrides the \var{CurrencyDecimals} global variable used in the
  5662. \seef{FloatToStrF}
  5663. In short, the \var{M} specifier formats it's arguument as follows:
  5664. \begin{verbatim}
  5665. FloatToStrF(Argument,ffCurrency,9999,Precision)
  5666. \end{verbatim}
  5667. \item[N] Number format. This is the same as fixed point format, except that
  5668. thousand separators are inserted in the resulting string.
  5669. \item[P] Pointer format. The next argument in the \var{Args} array must be a
  5670. pointer (typed or untyped). The pointer value is converted to a string of
  5671. length 8, representing the hexadecimal value of the pointer.
  5672. \item[S] String format. The next argument in the \var{Args} array must be
  5673. a string. The argument is simply copied to the result string. If
  5674. \var{Precision} is specified, then only \var{Precision} characters are
  5675. copied to the result string.
  5676. \item[X] hexadecimal format. The next argument in the \var{Args} array must
  5677. be an integer. The argument is converted to a hexadecimal string with just
  5678. enough characters to contain the value of the integer. If \var{Precision}
  5679. is specified then the resulting hexadecimal representation will have at
  5680. least \var{Precision} characters in it (with a maximum value of 32).
  5681. \end{description}
  5682. \Errors
  5683. In case of error, an \var{EConversionError} exception is raised. Possible
  5684. errors are:
  5685. \begin{enumerate}
  5686. \item Errors in the format specifiers.
  5687. \item The next argument is not of the type needed by a specifier.
  5688. \item The number of arguments is not sufficient for all format specifiers.
  5689. \end{enumerate}
  5690. \SeeAlso
  5691. \seef{FormatBuf}
  5692. \end{function}
  5693. \latex{\inputlisting{sysutex/ex71.pp}}
  5694. \html{\input{sysutex/ex71.tex}}
  5695. \begin{function}{FormatBuf}
  5696. \Declaration
  5697. Function FormatBuf(Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const) : Cardinal;
  5698. \Description
  5699. \var{Format}
  5700. \Errors
  5701. \SeeAlso
  5702. \end{function}
  5703. \latex{\inputlisting{sysutex/ex72.pp}}
  5704. \html{\input{sysutex/ex72.tex}}
  5705. \begin{function}{IntToHex}
  5706. \Declaration
  5707. Function IntToHex(Value: integer; Digits: integer): string;
  5708. \Description
  5709. \var{IntToHex} converts \var{Value} to a hexadecimal string
  5710. representation. The result will contain at least \var{Digits}
  5711. characters. If \var{Digits} is less than the needed number of characters,
  5712. the string will NOT be truncated. If \var{Digits} is larger than the needed
  5713. number of characters, the result is padded with zeroes.
  5714. \Errors
  5715. None.
  5716. \SeeAlso
  5717. \seef{IntToStr}, \var{StrToInt}
  5718. \end{function}
  5719. \latex{\inputlisting{sysutex/ex73.pp}}
  5720. \html{\input{sysutex/ex73.tex}}
  5721. \begin{function}{IntToStr}
  5722. \Declaration
  5723. Function IntToStr(Value: integer): string;
  5724. \Description
  5725. \var{IntToStr} coverts \var{Value} to it's string representation.
  5726. The resulting string has only as much characters as needed to represent
  5727. the value. If the value is negative a minus sign is prepended to the
  5728. string.
  5729. \Errors
  5730. None.
  5731. \SeeAlso
  5732. \seef{IntToHex}, \seef{StrToInt}
  5733. \end{function}
  5734. \latex{\inputlisting{sysutex/ex74.pp}}
  5735. \html{\input{sysutex/ex74.tex}}
  5736. \begin{function}{IsValidIdent}
  5737. \Declaration
  5738. Function IsValidIdent(const Ident: string): boolean;
  5739. \Description
  5740. \Errors
  5741. \SeeAlso
  5742. \end{function}
  5743. \begin{function}{LeftStr}
  5744. \Declaration
  5745. Function LeftStr(const S: string; Count: integer): string;
  5746. \Description
  5747. \Errors
  5748. \SeeAlso
  5749. \end{function}
  5750. \begin{function}{LoadStr}
  5751. \Declaration
  5752. Function LoadStr(Ident: integer): string;
  5753. \Description
  5754. \Errors
  5755. \SeeAlso
  5756. \end{function}
  5757. \begin{function}{LowerCase}
  5758. \Declaration
  5759. Function LowerCase(const s: string): string;
  5760. \Description
  5761. \Errors
  5762. \SeeAlso
  5763. \end{function}
  5764. \begin{functionl}{NewStr}{NewStrSys}
  5765. \Declaration
  5766. Function NewStr(const S: string): PString;
  5767. \Description
  5768. \Errors
  5769. \SeeAlso
  5770. \end{functionl}
  5771. \begin{function}{QuotedStr}
  5772. \Declaration
  5773. Function QuotedStr(const S: string): string;
  5774. \Description
  5775. \Errors
  5776. \SeeAlso
  5777. \end{function}
  5778. \begin{function}{RightStr}
  5779. \Declaration
  5780. Function RightStr(const S: string; Count: integer): string;
  5781. \Description
  5782. \Errors
  5783. \SeeAlso
  5784. \end{function}
  5785. \begin{function}{StrFmt}
  5786. \Declaration
  5787. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  5788. \Description
  5789. \Errors
  5790. \SeeAlso
  5791. \end{function}
  5792. \begin{function}{StrLFmt}
  5793. \Declaration
  5794. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  5795. \Description
  5796. \Errors
  5797. \SeeAlso
  5798. \end{function}
  5799. \begin{function}{StrToInt}
  5800. \Declaration
  5801. Function StrToInt(const s: string): integer;
  5802. \Description
  5803. \Errors
  5804. \SeeAlso
  5805. \end{function}
  5806. \begin{function}{StrToIntDef}
  5807. \Declaration
  5808. Function StrToIntDef(const S: string; Default: integer): integer;
  5809. \Description
  5810. \Errors
  5811. \SeeAlso
  5812. \end{function}
  5813. \begin{function}{Trim}
  5814. \Declaration
  5815. Function Trim(const S: string): string;
  5816. \Description
  5817. \Errors
  5818. \SeeAlso
  5819. \end{function}
  5820. \begin{function}{TrimLeft}
  5821. \Declaration
  5822. Function TrimLeft(const S: string): string;
  5823. \Description
  5824. \Errors
  5825. \SeeAlso
  5826. \end{function}
  5827. \begin{function}{TrimRight}
  5828. \Declaration
  5829. Function TrimRight(const S: string): string;
  5830. \Description
  5831. \Errors
  5832. \SeeAlso
  5833. \end{function}
  5834. \begin{function}{UpperCase}
  5835. \Declaration
  5836. Function UpperCase(const s: string): string;
  5837. \Description
  5838. \Errors
  5839. \SeeAlso
  5840. \end{function}