sysutils.tex 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693
  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. It is implemented
  26. on all supported platforms.
  27. This chapter starts out with a definition of all types and constants
  28. that are defined, followed by an overview of functions grouped by
  29. functionality, and lastly the complete explanation of each function.
  30. \section{Constants and types}
  31. The following general-purpose constants are defined:
  32. \begin{verbatim}
  33. const
  34. SecsPerDay = 24 * 60 * 60; // Seconds and milliseconds per day
  35. MSecsPerDay = SecsPerDay * 1000;
  36. DateDelta = 693594; // Days between 1/1/0001 and 12/31/1899
  37. Eoln = #10;
  38. \end{verbatim}
  39. The following types are used frequently in date and time functions.
  40. They are the same on all platforms.
  41. \begin{verbatim}
  42. type
  43. TSystemTime = record
  44. Year, Month, Day: word;
  45. Hour, Minute, Second, MilliSecond: word;
  46. end ;
  47. TDateTime = double;
  48. TTimeStamp = record
  49. Time: integer; { Number of milliseconds since midnight }
  50. Date: integer; { One plus number of days since 1/1/0001 }
  51. end ;
  52. \end{verbatim}
  53. The following type is used in the \seef{FindFirst},\seef{FindNext}
  54. and \seepl{FindClose}{FindCloseSys} functions. The \var{win32} version differs from
  55. the other versions. If code is to be portable, that part shouldn't
  56. be used.
  57. \begin{verbatim}
  58. Type
  59. THandle = Longint;
  60. TSearchRec = Record
  61. Time,Size, Attr : Longint;
  62. Name : TFileName;
  63. ExcludeAttr : Longint;
  64. FindHandle : THandle;
  65. {$ifdef Win32}
  66. FindData : TWin32FindData;
  67. {$endif}
  68. end;
  69. \end{verbatim}
  70. The following constants are file-attributes that need to be matched in the
  71. findfirst call.
  72. \begin{verbatim}
  73. Const
  74. faReadOnly = $00000001;
  75. faHidden = $00000002;
  76. faSysFile = $00000004;
  77. faVolumeId = $00000008;
  78. faDirectory = $00000010;
  79. faArchive = $00000020;
  80. faAnyFile = $0000003f;
  81. \end{verbatim}
  82. The following constants can be used in the \seef{FileOpen} call.
  83. \begin{verbatim}
  84. Const
  85. fmOpenRead = $0000;
  86. fmOpenWrite = $0001;
  87. fmOpenReadWrite = $0002;
  88. \end{verbatim}
  89. The following constants can be used in the \seef{FileSeek} call.
  90. \begin{verbatim}
  91. Const
  92. fsFromBeginning = 0;
  93. fsFromCurrent = 1;
  94. fsFromEnd = 2;
  95. \end{verbatim}
  96. The following variables are used in the case translation routines.
  97. \begin{verbatim}
  98. type
  99. TCaseTranslationTable = array[0..255] of char;
  100. var
  101. UpperCaseTable: TCaseTranslationTable;
  102. LowerCaseTable: TCaseTranslationTable;
  103. \end{verbatim}
  104. The initialization code of the \file{sysutils} unit fills these
  105. tables with the appropriate values. For the win32 and go32v2
  106. versions, this information is obtained from the operating system.
  107. The following constants control the formatting of dates.
  108. For the Win32 version of the \file{sysutils} unit, these
  109. constants are set according to the internationalization
  110. settings of Windows by the initialization code of the unit.
  111. \begin{verbatim}
  112. Const
  113. DateSeparator: char = '-';
  114. ShortDateFormat: string = 'd/m/y';
  115. LongDateFormat: string = 'dd" "mmmm" "yyyy';
  116. ShortMonthNames: array[1..12] of string[128] =
  117. ('Jan','Feb','Mar','Apr','May','Jun',
  118. 'Jul','Aug','Sep','Oct','Nov','Dec');
  119. LongMonthNames: array[1..12] of string[128] =
  120. ('January','February','March','April',
  121. 'May','June','July','August',
  122. 'September','October','November','December');
  123. ShortDayNames: array[1..7] of string[128] =
  124. ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
  125. LongDayNames: array[1..7] of string[128] =
  126. ('Sunday','Monday','Tuesday','Wednesday',
  127. 'Thursday','Friday','Saturday');
  128. \end{verbatim}
  129. The following constants control the formatting of times.
  130. For the Win32 version of the \file{sysutils} unit, these
  131. constants are set according to the internationalization
  132. settings of Windows by the initialization code of the unit.
  133. \begin{verbatim}
  134. Const
  135. ShortTimeFormat: string = 'hh:nn';
  136. LongTimeFormat: string = 'hh:nn:ss';
  137. TimeSeparator: char = ':';
  138. TimeAMString: string[7] = 'AM';
  139. TimePMString: string[7] = 'PM';
  140. \end{verbatim}
  141. The following constants control the formatting of currencies
  142. and numbers. For the Win32 version of the \file{sysutils} unit,
  143. these constants are set according to the internationalization
  144. settings of Windows by the initialization code of the unit.
  145. \begin{verbatim}
  146. Const
  147. DecimalSeparator : Char = '.';
  148. ThousandSeparator : Char = ',';
  149. CurrencyDecimals : Byte = 2;
  150. CurrencyString : String[7] = '$';
  151. { Format to use when formatting currency :
  152. 0 = $1 1 = 1$ 2 = $ 1 3 = 1 $
  153. 4 = Currency string replaces decimal indicator.
  154. e.g. 1$50
  155. }
  156. CurrencyFormat : Byte = 1;
  157. { Same as above, only for negative currencies:
  158. 0 = ($1)
  159. 1 = -$1
  160. 2 = $-1
  161. 3 = $1-
  162. 4 = (1$)
  163. 5 = -1$
  164. 6 = 1-$
  165. 7 = 1$-
  166. 8 = -1 $
  167. 9 = -$ 1
  168. 10 = $ 1-
  169. }
  170. NegCurrFormat : Byte = 5;
  171. \end{verbatim}
  172. The following types are used in various string functions.
  173. \begin{verbatim}
  174. type
  175. PString = ^String;
  176. TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
  177. \end{verbatim}
  178. The following constants are used in the file name handling routines. Do not
  179. use a slash of backslash character directly as a path separator; instead
  180. use the \var{OsDirSeparator} character.
  181. \begin{verbatim}
  182. Const
  183. DirSeparators : set of char = ['/','\'];
  184. {$ifdef Linux}
  185. OSDirSeparator = '/';
  186. {$else}
  187. OsDirSeparator = '\';
  188. {$endif}
  189. \end{verbatim}
  190. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  191. % Functions and procedures by category
  192. \section{Function list by category}
  193. What follows is a listing of the available functions, grouped by category.
  194. For each function there is a reference to the page where you can find the
  195. function.
  196. \subsection{String functions}
  197. Functions for handling strings.
  198. \begin{funclist}
  199. \funcref{AnsiCompareStr}{Compare two strings}
  200. \funcref{AnsiCompareText}{Compare two strings, case insensitive}
  201. \funcref{AnsiExtractQuotedStr}{Removes quotes from string}
  202. \funcref{AnsiLastChar}{Get last character of string}
  203. \funcref{AnsiLowerCase}{Convert string to all-lowercase}
  204. \funcref{AnsiQuotedStr}{Qoutes a string}
  205. \funcref{AnsiStrComp}{Compare strings case-sensitive}
  206. \funcref{AnsiStrIComp}{Compare strings case-insensitive}
  207. \funcref{AnsiStrLComp}{Compare L characters of strings case sensitive}
  208. \funcref{AnsiStrLIComp}{Compare L characters of strings case insensitive}
  209. \funcref{AnsiStrLastChar}{Get last character of string}
  210. \funcref{AnsiStrLower}{Convert string to all-lowercase}
  211. \funcref{AnsiStrUpper}{Convert string to all-uppercase}
  212. \funcref{AnsiUpperCase}{Convert string to all-uppercase}
  213. \procref{AppendStr}{Append 2 strings}
  214. \procref{AssignStr}{Assign value of strings on heap}
  215. \funcref{CompareStr}{Compare two strings case sensitive}
  216. \funcref{CompareText}{Compare two strings case insensitive}
  217. \procrefl{DisposeStr}{DisposeStrSys}{Remove string from heap}
  218. \funcref{IsValidIdent}{Is string a valid pascal identifier}
  219. \funcref{LeftStr}{Get first N characters of a string}
  220. \funcref{LoadStr}{Load string from resources}
  221. \funcref{LowerCase}{Convert string to all-lowercase}
  222. \funcrefl{NewStr}{NewStrSys}{Allocate new string on heap}
  223. \funcref{RightStr}{Get last N characters of a string}
  224. \funcrefl{StrAlloc}{StrAllocSys}{Allocate memory for string}
  225. \funcref{StrBufSize}{Reserve memory for a string}
  226. \procrefl{StrDispose}{StrDisposeSys}{Remove string from heap}
  227. \funcrefl{StrPas}{StrPasSys}{Convert PChar to pascal string}
  228. \funcrefl{StrPCopy}{StrPCopySys}{Copy pascal string}
  229. \funcrefl{StrPLCopy}{StrPLCopySys}{Copy N bytes of pascal string}
  230. \funcref{UpperCase}{Convert string to all-uppercase}
  231. \end{funclist}
  232. \subsection{Formatting strings}
  233. Functions for formatting strings.
  234. \begin{funclist}
  235. \funcref{AdjustLineBreaks}{Convert line breaks to line breaks for system}
  236. \funcref{FormatBuf}{Format a buffer}
  237. \funcref{Format}{Format arguments in string}
  238. \procref{FmtStr}{Format buffer}
  239. \funcref{QuotedStr}{Quote a string}
  240. \funcref{StrFmt}{Format arguments in a string}
  241. \funcref{StrLFmt}{Format maximum L characters in a string}
  242. \funcref{TrimLeft}{Remove whitespace at the left of a string}
  243. \funcref{TrimRight}{Remove whitespace at the right of a string}
  244. \funcref{Trim}{Remove whitespace at both ends of a string}
  245. \end{funclist}
  246. \subsection{File input/output routines}
  247. Functions for reading/writing to file.
  248. \begin{funclist}
  249. \funcref{FileCreate}{Create a file and return handle}
  250. \funcref{FileOpen}{Open file end return handle}
  251. \funcref{FileRead}{Read from file}
  252. \funcref{FileSeek}{Set file position}
  253. \funcref{FileTruncate}{Truncate file length}
  254. \funcref{FileWrite}{Write to file}
  255. \procref{FileClose}{Close file handle}
  256. \end{funclist}
  257. \subsection{File handling routines}
  258. Functions for file manipulation.
  259. \begin{funclist}
  260. \funcref{AddDisk}{Add sisk to list of disk drives}
  261. \funcref{ChangeFileExt}{Change extension of file name}
  262. \funcref{CreateDir}{Create a directory}
  263. \funcref{DeleteFile}{Delete a file}
  264. \funcrefl{DiskFree}{DiskFreeSys}{Free space on disk}
  265. \funcrefl{DiskSize}{DiskSizeSys}{Total size of disk}
  266. \funcref{ExpandFileName}{Create full file name}
  267. \funcref{ExpandUNCFileName}{Create full UNC file name}
  268. \funcref{ExtractFileDir}{Extract directory part of filename}
  269. \funcref{ExtractFileDrive}{Extract drive part of filename}
  270. \funcref{ExtractFileExt}{Extract extension part of filename}
  271. \funcref{ExtractFileName}{Extract name part of filename}
  272. \funcref{ExtractFilePath}{Extrct path part of filename}
  273. \funcref{ExtractRelativePath}{Construct relative path between two files}
  274. \funcref{FileAge}{Return file age}
  275. \funcref{FileDateToDateTime}{Convert file date to system date}
  276. \funcref{FileExists}{Determine whether a file exists on disk}
  277. \funcref{FileGetAttr}{Get attributes of file}
  278. \funcref{FileGetDate}{Get date of last file modification}
  279. \funcref{FileSearch}{Search for file in path}
  280. \funcrefl{FileSetAttr}{FileSetAttr}{Get file attributes}
  281. \funcrefl{FileSetDate}{FileSetDate}{Get file dates}
  282. \funcref{FindFirst}{Start finding a file}
  283. \funcref{FindNext}{Find next file}
  284. \funcref{GetCurrentDir}{Return current working directory}
  285. \funcref{RemoveDir}{Remove a directory from disk}
  286. \funcref{RenameFile}{Rename a file on disk}
  287. \funcref{SetCurrentDir}{Set current working directory}
  288. \funcref{SetDirSeparators}{Set directory separator characters}
  289. \procrefl{FindClose}{FindCloseSys}{Stop searching a file}
  290. \procref{DoDirSeparators}{Replace directory separator characters}
  291. \end{funclist}
  292. \subsection{Date/time routines}
  293. Functions for date and time handling.
  294. \begin{funclist}
  295. \funcref{DateTimeToFileDate}{Convert DateTime type to file date}
  296. \funcref{DateTimeToStr}{Construct string representation of DateTime}
  297. \procref{DateTimeToString}{Construct string representation of DateTime}
  298. \procref{DateTimeToSystemTime}{Convert DateTime to system time}
  299. \funcref{DateTimeToTimeStamp}{Convert DateTime to timestamp}
  300. \funcref{DateToStr}{Construct string representation of date}
  301. \funcref{Date}{Get current date}
  302. \funcref{DayOfWeek}{Get day of week}
  303. \procref{DecodeDate}{Decode DateTime to year month and day}
  304. \procref{DecodeTime}{Decode DateTime to hours, minutes and seconds}
  305. \funcref{EncodeDate}{Encode year, day and month to DateTime}
  306. \funcref{EncodeTime}{Encode hours, minutes and seconds to DateTime}
  307. \funcref{FormatDateTime}{Return string representation of DateTime}
  308. \funcref{IncMonth}{Add 1 to month}
  309. \funcref{IsLeapYear}{Determine if year is leap year}
  310. \funcref{MSecsToTimeStamp}{Convert nr of milliseconds to timestamp}
  311. \funcref{Now}{Get current date and time}
  312. \funcref{StrToDateTime}{Convert string to DateTime}
  313. \funcref{StrToDate}{Convert string to date}
  314. \funcref{StrToTime}{Convert string to time}
  315. \funcref{SystemTimeToDateTime}{Convert system time to datetime}
  316. \funcref{TimeStampToDateTime}{Convert time stamp to DateTime}
  317. \funcref{TimeStampToMSecs}{Convert Timestamp to number of millicseconds}
  318. \funcref{TimeToStr}{return string representation of Time}
  319. \funcref{Time}{Get current tyme}
  320. \end{funclist}
  321. \section{Miscellaneous conversion routines}
  322. Functions for various conversions.
  323. \begin{funclist}
  324. \funcref{BCDToInt}{Convert BCD number to integer}
  325. \funcref{CompareMem}{Compare two memory regions}
  326. \funcref{FloatToStrF}{Convert float to formatted string}
  327. \funcref{FloatToStr}{Convert float to string}
  328. \funcref{FloatToText}{Convert float to string}
  329. \funcref{GetDirs}{Split string in list of directories}
  330. \funcref{IntToHex}{return hexadecimal representation of integer}
  331. \funcref{IntToStr}{return decumal representation of integer}
  332. \funcref{StrToIntDef}{Convert string to integer with default value}
  333. \funcref{StrToInt}{Convert string to integer}
  334. \end{funclist}
  335. \section{Date and time functions}
  336. \subsection{Date and time formatting characters}
  337. \label{se:formatchars}
  338. Various date and time formatting routines accept a format string.
  339. to format the date and or time. The following characters can be used
  340. to control the date and time formatting:
  341. \begin{description}
  342. \item[c] : shortdateformat + ' ' + shorttimeformat
  343. \item[d] : day of month
  344. \item[dd] : day of month (leading zero)
  345. \item[ddd] : day of week (abbreviation)
  346. \item[dddd] : day of week (full)
  347. \item[ddddd] : shortdateformat
  348. \item[dddddd] : longdateformat
  349. \item[m] : month
  350. \item[mm] : month (leading zero)
  351. \item[mmm] : month (abbreviation)
  352. \item[mmmm] : month (full)
  353. \item[y] : year (four digits)
  354. \item[yy] : year (two digits)
  355. \item[yyyy] : year (with century)
  356. \item[h] : hour
  357. \item[hh] : hour (leading zero)
  358. \item[n] : minute
  359. \item[nn] : minute (leading zero)
  360. \item[s] : second
  361. \item[ss] : second (leading zero)
  362. \item[t] : shorttimeformat
  363. \item[tt] : longtimeformat
  364. \item[am/pm] : use 12 hour clock and display am and pm accordingly
  365. \item[a/p] : use 12 hour clock and display a and p accordingly
  366. \item[/] : insert date seperator
  367. \item[:] : insert time seperator
  368. \item["xx"] : literal text
  369. \item['xx'] : literal text
  370. \end{description}
  371. \begin{type}{TDateTime}
  372. \Declaration
  373. TDateTime = Double;
  374. \Description
  375. Many functions return or require a \var{TDateTime} type, which contains
  376. a date and time in encoded form. The date and time are converted to a double
  377. as follows:
  378. \begin{itemize}
  379. \item The date part is stored in the integer part of the double as the
  380. number of days passed since January 1, 1900.
  381. \item The time part is stored in the fractional part of the double, as
  382. the number of milliseconds passed since midnight (00:00), divided by the
  383. total number of milliseconds in a day.
  384. \end{itemize}
  385. \end{type}
  386. \begin{function}{Date}
  387. \Declaration
  388. Function Date: TDateTime;
  389. \Description
  390. \var{Date} returns the current date in \var{TDateTime} format.
  391. For more information about the \var{TDateTime} type, see \seetype{TDateTime}.
  392. \Errors
  393. None.
  394. \SeeAlso
  395. \seef{Time},\seef{Now}, \seetype{TDateTime}.
  396. \end{function}
  397. \latex{\lstinputlisting{sysutex/ex1.pp}}
  398. \html{\input{sysutex/ex1.tex}}
  399. \begin{function}{DateTimeToFileDate}
  400. \Declaration
  401. Function DateTimeToFileDate(DateTime : TDateTime) : Longint;
  402. \Description
  403. \var{DateTimeToFileDate} function converts a date/time indication in
  404. \var{TDateTime} format to a filedate function, such as returned for
  405. instance by the \seef{FileAge} function.
  406. \Errors
  407. None.
  408. \SeeAlso
  409. \seef{Time}, \seef{Date}, \seef{FileDateToDateTime},
  410. \seep{DateTimeToSystemTime}, \seef{DateTimeToTimeStamp}
  411. \end{function}
  412. \latex{\lstinputlisting{sysutex/ex2.pp}}
  413. \html{\input{sysutex/ex2.tex}}
  414. \begin{function}{DateTimeToStr}
  415. \Declaration
  416. Function DateTimeToStr(DateTime: TDateTime): string;
  417. \Description
  418. \var{DateTimeToStr} returns a string representation of
  419. \var{DateTime} using the formatting specified in
  420. \var{ShortDateTimeFormat}. It corresponds to a call to
  421. \var{FormatDateTime('c',DateTime)} (see \sees{formatchars}).
  422. \Errors
  423. None.
  424. \SeeAlso
  425. \seef{FormatDateTime}, \seetype{TDateTime}.
  426. \end{function}
  427. \latex{\lstinputlisting{sysutex/ex3.pp}}
  428. \html{\input{sysutex/ex3.tex}}
  429. \begin{procedure}{DateTimeToString}
  430. \Declaration
  431. Procedure DateTimeToString(var Result: string; const FormatStr: string; const DateTime: TDateTime);
  432. \Description
  433. \var{DateTimeToString} returns in \var{Result} a string representation of
  434. \var{DateTime} using the formatting specified in \var{FormatStr}.
  435. for a list of characters that can be used in the \var{FormatStr} formatting
  436. string, see \sees{formatchars}.
  437. \Errors
  438. In case a wrong formatting character is found, an \var{EConvertError} is
  439. raised.
  440. \SeeAlso
  441. \seef{FormatDateTime}, \sees{formatchars}.
  442. \end{procedure}
  443. \latex{\lstinputlisting{sysutex/ex4.pp}}
  444. \html{\input{sysutex/ex4.tex}}
  445. \begin{procedure}{DateTimeToSystemTime}
  446. \Declaration
  447. Procedure DateTimeToSystemTime(DateTime: TDateTime; var SystemTime: TSystemTime);
  448. \Description
  449. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  450. \var{TDateTime} format to a system time \var{SystemTime}.
  451. \Errors
  452. None.
  453. \SeeAlso
  454. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  455. \seef{DateTimeToTimeStamp}
  456. \end{procedure}
  457. \latex{\lstinputlisting{sysutex/ex5.pp}}
  458. \html{\input{sysutex/ex5.tex}}
  459. \begin{function}{DateTimeToTimeStamp}
  460. \Declaration
  461. Function DateTimeToTimeStamp(DateTime: TDateTime): TTimeStamp;
  462. \Description
  463. \var{DateTimeToSystemTime} converts a date/time pair in \var{DateTime}, with
  464. \var{TDateTime} format to a \var{TTimeStamp} format.
  465. \Errors
  466. None.
  467. \SeeAlso
  468. \seef{DateTimeToFileDate}, \seef{SystemTimeToDateTime},
  469. \seep{DateTimeToSystemTime}
  470. \end{function}
  471. \latex{\lstinputlisting{sysutex/ex6.pp}}
  472. \html{\input{sysutex/ex6.tex}}
  473. \begin{function}{DateToStr}
  474. \Declaration
  475. Function DateToStr(Date: TDateTime): string;
  476. \Description
  477. \var{DateToStr} converts \var{Date} to a string representation. It uses
  478. \var{ShortDateFormat} as it's formatting string. It is hence completely
  479. equivalent to a \var{FormatDateTime('ddddd', Date)}.
  480. \Errors
  481. None.
  482. \SeeAlso
  483. \seef{TimeToStr}, \seef{DateTimeToStr}, \seef{FormatDateTime},
  484. \seef{StrToDate}
  485. \end{function}
  486. \latex{\lstinputlisting{sysutex/ex7.pp}}
  487. \html{\input{sysutex/ex7.tex}}
  488. \begin{function}{DayOfWeek}
  489. \Declaration
  490. Function DayOfWeek(DateTime: TDateTime): integer;
  491. \Description
  492. \var{DayOfWeek} returns the day of the week from \var{DateTime}.
  493. \var{Sunday} is counted as day 1, \var{Saturday} is counted as
  494. day 7. The result of \var{DayOfWeek} can serve as an index to
  495. the \var{LongDayNames} constant array, to retrieve the name of
  496. the day.
  497. \Errors
  498. None.
  499. \SeeAlso
  500. \seef{Date}, \seef{DateToStr}
  501. \end{function}
  502. \latex{\lstinputlisting{sysutex/ex8.pp}}
  503. \html{\input{sysutex/ex8.tex}}
  504. \begin{procedure}{DecodeDate}
  505. \Declaration
  506. Procedure DecodeDate(Date: TDateTime; var Year, Month, Day: word);
  507. \Description
  508. \var{DecodeDate} decodes the Year, Month and Day stored in \var{Date},
  509. and returns them in the \var{Year}, \var{Month} and \var{Day} variables.
  510. \Errors
  511. None.
  512. \SeeAlso
  513. \seef{EncodeDate}, \seep{DecodeTime}.
  514. \end{procedure}
  515. \latex{\lstinputlisting{sysutex/ex9.pp}}
  516. \html{\input{sysutex/ex9.tex}}
  517. \begin{procedure}{DecodeTime}
  518. \Declaration
  519. Procedure DecodeTime(Time: TDateTime; var Hour, Minute, Second, MilliSecond: word);
  520. \Description
  521. \var{DecodeDate} decodes the hours, minutes, second and milliseconds stored
  522. in \var{Time}, and returns them in the \var{Hour}, \var{Minute} and
  523. \var{Second} and \var{MilliSecond} variables.
  524. \Errors
  525. None.
  526. \SeeAlso
  527. \seef{EncodeTime}, \seep{DecodeDate}.
  528. \end{procedure}
  529. \latex{\lstinputlisting{sysutex/ex10.pp}}
  530. \html{\input{sysutex/ex10.tex}}
  531. \begin{function}{EncodeDate}
  532. \Declaration
  533. Function EncodeDate(Year, Month, Day :word): TDateTime;
  534. \Description
  535. \var{EncodeDate} encodes the \var{Year}, \var{Month} and \var{Day} variables to
  536. a date in \var{TDateTime} format. It does the opposite of the
  537. \seep{DecodeDate} procedure.
  538. The parameters must lie withing valid ranges (boundaries included):
  539. \begin{description}
  540. \item[Year] must be between 1 and 9999.
  541. \item[Month] must be within the range 1-12.
  542. \item[Day] msut be between 1 and 31.
  543. \end{description}
  544. \Errors
  545. In case one of the parameters is out of it's valid range, 0 is returned.
  546. \SeeAlso
  547. \seef{EncodeTime}, \seep{DecodeDate}.
  548. \end{function}
  549. \latex{\lstinputlisting{sysutex/ex11.pp}}
  550. \html{\input{sysutex/ex11.tex}}
  551. \begin{function}{EncodeTime}
  552. \Declaration
  553. Function EncodeTime(Hour, Minute, Second, MilliSecond:word): TDateTime;
  554. \Description
  555. \var{EncodeTime} encodes the \var{Hour}, \var{Minute}, \var{Second},
  556. \var{MilliSecond} variables to a \var{TDateTime} format result.
  557. It does the opposite of the \seep{DecodeTime} procedure.
  558. The parameters must have a valid range (boundaries included):
  559. \begin{description}
  560. \item[Hour] must be between 0 and 23.
  561. \item[Minute,second] must both be between 0 and 59.
  562. \item[Millisecond] must be between 0 and 999.
  563. \end{description}
  564. \Errors
  565. In case one of the parameters is outside of it's valid range, 0 is returned.
  566. \SeeAlso
  567. \seef{EncodeDate}, \seep{DecodeTime}.
  568. \end{function}
  569. \latex{\lstinputlisting{sysutex/ex12.pp}}
  570. \html{\input{sysutex/ex12.tex}}
  571. \begin{function}{FileDateToDateTime}
  572. \Declaration
  573. Function FileDateToDateTime(Filedate : Longint) : TDateTime;
  574. \Description
  575. \var{FileDateToDateTime} converts the date/time encoded in \var{filedate}
  576. to a \var{TDateTime} encoded form. It can be used to convert date/time values
  577. returned by the \seef{FileAge} or \seef{FindFirst}/\seef{FindNext}
  578. functions to \var{TDateTime} form.
  579. \Errors
  580. None.
  581. \SeeAlso
  582. \seef{DateTimeToFileDate}
  583. \end{function}
  584. \latex{\lstinputlisting{sysutex/ex13.pp}}
  585. \html{\input{sysutex/ex13.tex}}
  586. \begin{function}{FormatDateTime}
  587. \Declaration
  588. Function FormatDateTime(FormatStr: string; DateTime: TDateTime):string;
  589. \Description
  590. \var{FormatDateTime} formats the date and time encoded in \var{DateTime}
  591. according to the formatting given in \var{FormatStr}. The complete list
  592. of formatting characters can be found in \sees{formatchars}.
  593. \Errors
  594. On error (such as an invalid character in the formatting string), and
  595. \var{EConvertError} exception is raised.
  596. \SeeAlso
  597. \seef{DateTimeToStr}, \seef{DateToStr}, \seef{TimeToStr},
  598. \seef{StrToDateTime}
  599. \end{function}
  600. \latex{\lstinputlisting{sysutex/ex14.pp}}
  601. \html{\input{sysutex/ex14.tex}}
  602. \begin{function}{IncMonth}
  603. \Declaration
  604. Function IncMonth(const DateTime: TDateTime; NumberOfMonths: integer): TDateTime;
  605. \Description
  606. \var{IncMonth} increases the month number in \var{DateTime} with
  607. \var{NumberOfMonths}. It wraps the result as to get a month between 1 and
  608. 12, and updates the year accordingly. \var{NumberOfMonths} can be negative,
  609. and can be larger than 12 (in absolute value).
  610. \Errors
  611. None.
  612. \SeeAlso
  613. \seef{Date}, \seef{Time}, \seef{Now}
  614. \end{function}
  615. \latex{\lstinputlisting{sysutex/ex15.pp}}
  616. \html{\input{sysutex/ex15.tex}}
  617. \begin{function}{IsLeapYear}
  618. \Declaration
  619. Function IsLeapYear(Year: Word): boolean;
  620. \Description
  621. \var{IsLeapYear} returns \var{True} if \var{Year} is a leap year,
  622. \var{False} otherwise.
  623. \Errors
  624. None.
  625. \SeeAlso
  626. \seef{IncMonth}, \seef{Date}
  627. \end{function}
  628. \latex{\lstinputlisting{sysutex/ex16.pp}}
  629. \html{\input{sysutex/ex16.tex}}
  630. \begin{function}{MSecsToTimeStamp}
  631. \Declaration
  632. Function MSecsToTimeStamp(MSecs: Comp): TTimeStamp;
  633. \Description
  634. \var{MSecsTiTimeStamp} converts the given number of milliseconds to
  635. a \var{TTimeStamp} date/time notation.
  636. Use \var{TTimeStamp} variables if you need to keep very precise track of
  637. time.
  638. \Errors
  639. None.
  640. \SeeAlso
  641. \seef{TimeStampToMSecs}, \seef{DateTimeToTimeStamp},
  642. \end{function}
  643. \latex{\lstinputlisting{sysutex/ex17.pp}}
  644. \html{\input{sysutex/ex17.tex}}
  645. \begin{function}{Now}
  646. \Declaration
  647. Function Now: TDateTime;
  648. \Description
  649. \var{Now} returns the current date and time. It is equivalent to
  650. \var{Date+Time}.
  651. \Errors
  652. None.
  653. \SeeAlso
  654. \seef{Date}, \seef{Time}
  655. \end{function}
  656. \latex{\lstinputlisting{sysutex/ex18.pp}}
  657. \html{\input{sysutex/ex18.tex}}
  658. \begin{function}{StrToDate}
  659. \Declaration
  660. Function StrToDate(const S: string): TDateTime;
  661. \Description
  662. \var{StrToDate} converts the string \var{S} to a \var{TDateTime} date
  663. value. The Date must consist of 1 to three digits, separated by the
  664. \var{DateSeparator} character. If two numbers are given, they
  665. are supposed to form the day and month of the current year. If only
  666. one number is given, it is supposed to represent the day of the
  667. current month. (This is \em{not} supported in Delphi)
  668. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  669. \var{ShortDateFormat} variable.
  670. \Errors
  671. On error (e.g. an invalid date or invalid character),
  672. an \var{EConvertError} exception is raised.
  673. \SeeAlso
  674. \seef{StrToTime}, \seef{DateToStr}n \seef{TimeToStr}.
  675. \end{function}
  676. \latex{\lstinputlisting{sysutex/ex19.pp}}
  677. \html{\input{sysutex/ex19.tex}}
  678. \begin{function}{StrToDateTime}
  679. \Declaration
  680. Function StrToDateTime(const S: string): TDateTime;
  681. \Description
  682. \var{StrToDateTime} converts the string \var{S} to a \var{TDateTime} date
  683. and time value. The Date must consist of 1 to three digits, separated by the
  684. \var{DateSeparator} character. If two numbers are given, they
  685. are supposed to form the day and month of the current year. If only
  686. one number is given, it is supposed to represent the day of the
  687. current month. (This is \em{not} supported in Delphi)
  688. The order of the digits (y/m/d, m/d/y, d/m/y) is determined from the
  689. \var{ShortDateFormat} variable.
  690. \Errors
  691. On error (e.g. an invalid date or invalid character),
  692. an \var{EConvertError} exception is raised.
  693. \SeeAlso
  694. \seef{StrToDate}, \seef{StrToTime}, \seef{DateTimeToStr}
  695. \end{function}
  696. \latex{\lstinputlisting{sysutex/ex20.pp}}
  697. \html{\input{sysutex/ex20.tex}}
  698. \begin{function}{StrToTime}
  699. \Declaration
  700. Function StrToTime(const S: string): TDateTime;
  701. \Description
  702. \var{StrToTime} converts the string \var{S} to a \var{TDateTime} time
  703. value. The time must consist of 1 to 4 digits, separated by the
  704. \var{TimeSeparator} character. If two numbers are given, they
  705. are supposed to form the hour and minutes.
  706. \Errors
  707. On error (e.g. an invalid date or invalid character),
  708. an \var{EConvertError} exception is raised.
  709. \SeeAlso
  710. \seef{StrToDate}, \seef{StrToDateTime}, \seef{TimeToStr}
  711. \end{function}
  712. \latex{\lstinputlisting{sysutex/ex21.pp}}
  713. \html{\input{sysutex/ex21.tex}}
  714. \begin{function}{SystemTimeToDateTime}
  715. \Declaration
  716. Function SystemTimeToDateTime(const SystemTime: TSystemTime): TDateTime;
  717. \Description
  718. \var{SystemTimeToDateTime} converts a \var{TSystemTime} record to a
  719. \var{TDateTime} style date/time indication.
  720. \Errors
  721. None.
  722. \SeeAlso
  723. \seep{DateTimeToSystemTime}
  724. \end{function}
  725. \latex{\lstinputlisting{sysutex/ex22.pp}}
  726. \html{\input{sysutex/ex22.tex}}
  727. \begin{function}{Time}
  728. \Declaration
  729. Function Time: TDateTime;
  730. \Description
  731. \var{Time} returns the current time in \var{TDateTime} format. The date
  732. part of the \var{TDateTimeValue} is set to zero.
  733. \Errors
  734. None.
  735. \SeeAlso
  736. \seef{Now}, \seef{Date}
  737. \end{function}
  738. \latex{\lstinputlisting{sysutex/ex23.pp}}
  739. \html{\input{sysutex/ex23.tex}}
  740. \begin{function}{TimeStampToDateTime}
  741. \Declaration
  742. Function TimeStampToDateTime(const TimeStamp: TTimeStamp): TDateTime;
  743. \Description
  744. \var{TimeStampToDateTime} converts \var{TimeStamp} to a \var{TDateTime}
  745. format variable. It is the inverse operation of \seef{DateTimeToTimeStamp}.
  746. \Errors
  747. None.
  748. \SeeAlso
  749. \seef{DateTimeToTimeStamp}, \seef{TimeStampToMSecs}
  750. \end{function}
  751. \latex{\lstinputlisting{sysutex/ex24.pp}}
  752. \html{\input{sysutex/ex24.tex}}
  753. \begin{function}{TimeStampToMSecs}
  754. \Declaration
  755. Function TimeStampToMSecs(const TimeStamp: TTimeStamp): comp;
  756. \Description
  757. \var{TimeStampToMSecs} converts {TimeStamp} to the number of seconds
  758. since \var{1/1/0001}.
  759. Use \var{TTimeStamp} variables if you need to keep very precise track of
  760. time.
  761. \Errors
  762. None.
  763. \SeeAlso
  764. \seef{MSecsToTimeStamp}, \seef{TimeStampToDateTime}
  765. \end{function}
  766. For an example, see \seef{MSecsToTimeStamp}.
  767. \begin{function}{TimeToStr}
  768. \Declaration
  769. Function TimeToStr(Time: TDateTime): string;
  770. \Description
  771. \var{TimeToStr} converts the time in \var{Time} to a string. It uses
  772. the \var{ShortTimeFormat} variable to see what formatting needs to be
  773. applied. It is therefor entirely equivalent to a
  774. \var{FormatDateTime('t',Time)} call.
  775. \Errors
  776. None.
  777. \SeeAlso
  778. \end{function}
  779. \latex{\lstinputlisting{sysutex/ex25.pp}}
  780. \html{\input{sysutex/ex25.tex}}
  781. \section{Disk functions}
  782. \begin{functionl}{AddDisk (Linux only)}{AddDisk}
  783. \Declaration
  784. Function AddDisk (Const PAth : String) : Longint;
  785. \Description
  786. On Linux both the \seef{DiskFree} and \seef{DiskSize} functions need a
  787. file on the specified drive, since is required for the statfs system call.
  788. These filenames are set in drivestr[0..26], and the first 4 have been
  789. preset to :
  790. \begin{description}
  791. \item[Disk 0] \var{'.'} default drive - hence current directory is used.
  792. \item[Disk 1] \var{'/fd0/.'} floppy drive 1.
  793. \item[Disk 2] \var{'/fd1/.'} floppy drive 2.
  794. \item[Disk 3] \var{'/'} \file{C:} equivalent of DOS is the root partition.
  795. \end{description}
  796. Drives 4..26 can be set by your own applications with the \var{AddDisk} call.
  797. The \var{AddDisk} call adds \var{Path} to the names of drive files, and
  798. returns the number of the disk that corresponds to this drive. If you
  799. add more than 21 drives, the count is wrapped to 4.
  800. \Errors
  801. None.
  802. \SeeAlso
  803. \seefl{DiskFree}{DiskFreeSys}, \seefl{DiskSize}{DiskSizeSys}
  804. \end{functionl}
  805. \begin{function}{CreateDir}
  806. \Declaration
  807. Function CreateDir(Const NewDir : String) : Boolean;
  808. \Description
  809. \var{CreateDir} creates a new directory with name \var{NewDir}.
  810. If the directory doesn't contain an absolute path, then the directory is
  811. created below the current working directory.
  812. The function returns \var{True} if the directory was successfully
  813. created, \var{False} otherwise.
  814. \Errors
  815. In case of an error, the function returns \var{False}.
  816. \SeeAlso
  817. \seef{RemoveDir}
  818. \end{function}
  819. \latex{\lstinputlisting{sysutex/ex26.pp}}
  820. \html{\input{sysutex/ex26.tex}}
  821. \begin{functionl}{DiskFree}{DiskFreeSys}
  822. \Declaration
  823. Function DiskFree(Drive : Byte) : Longint;
  824. \Description
  825. \var{DiskFree} returns the free space (in bytes) on disk \var{Drive}.
  826. Drive is the number of the disk drive:
  827. \begin{description}
  828. \item[0] for the current drive.
  829. \item[1] for the first floppy drive.
  830. \item[2] for the second floppy drive.
  831. \item[3] for the first hard-disk parttion.
  832. \item[4-26] for all other drives and partitions.
  833. \end{description}
  834. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  835. different than the \dos one, since the filesystem is seen as one big
  836. directory tree. For this reason, the \var{DiskFree} and \seef{DiskSize}
  837. functions must be mimicked using filenames that reside on the partitions.
  838. For more information, see \seef{AddDisk}
  839. \Errors
  840. On error, \var{-1} is returned.
  841. \SeeAlso
  842. \seefl{DiskSize}{DiskSizeSys}, \seef{AddDisk}
  843. \end{functionl}
  844. \latex{\lstinputlisting{sysutex/ex27.pp}}
  845. \html{\input{sysutex/ex27.tex}}
  846. \begin{functionl}{DiskSize}{DiskSizeSys}
  847. \Declaration
  848. Function DiskSize(Drive : Byte) : Longint;
  849. \Description
  850. \var{DiskSize} returns the size (in bytes) of disk \var{Drive}.
  851. Drive is the number of the disk drive:
  852. \begin{description}
  853. \item[0] for the current drive.
  854. \item[1] for the first floppy drive.
  855. \item[2] for the second floppy drive.
  856. \item[3] for the first hard-disk parttion.
  857. \item[4-26] for all other drives and partitions.
  858. \end{description}
  859. {\em Remark} Under \linux, and Unix in general, the concept of disk is
  860. different than the \dos one, since the filesystem is seen as one big
  861. directory tree. For this reason, the \seef{DiskFree} and \var{DiskSize}
  862. functions must be mimicked using filenames that reside on the partitions.
  863. For more information, see \seef{AddDisk}
  864. \Errors
  865. On error, \var{-1} is returned.
  866. \SeeAlso
  867. \seefl{DiskFree}{DiskFreeSys}, \seef{AddDisk}
  868. \end{functionl}
  869. For an example, see \seefl{DiskFree}{DiskFreeSys}.
  870. \begin{function}{GetCurrentDir}
  871. \Declaration
  872. Function GetCurrentDir : String;
  873. \Description
  874. \var{GetCurrentDir} returns the current working directory.
  875. \Errors
  876. None.
  877. \SeeAlso
  878. \seef{SetCurrentDir}, \seef{DiskFree}, \seef{DiskSize}
  879. \end{function}
  880. \latex{\lstinputlisting{sysutex/ex28.pp}}
  881. \html{\input{sysutex/ex28.tex}}
  882. \begin{function}{RemoveDir}
  883. \Declaration
  884. Function RemoveDir(Const Dir : String) : Boolean;
  885. \Description
  886. \var{RemoveDir} removes directory \var{Dir} from the disk.
  887. If the directory is not absolue, it is appended to the current working
  888. directory.
  889. \Errors
  890. In case of error (e.g. the directory isn't empty) the function returns
  891. \var{False}. If successful, \var{True} is returned.
  892. \SeeAlso
  893. \end{function}
  894. For an example, see \seef{CreateDir}.
  895. \begin{function}{SetCurrentDir}
  896. \Declaration
  897. Function SetCurrentDir(Const NewDir : String) : Boolean;
  898. \Description
  899. \var{SetCurrentDir} sets the current working directory of your program
  900. to \var{NewDir}. It returns \var{True} if the function was successfull,
  901. \var{False} otherwise.
  902. \Errors
  903. In case of error, \var{False} is returned.
  904. \SeeAlso
  905. \seef{GetCurrentDir}
  906. \end{function}
  907. \latex{\lstinputlisting{sysutex/ex29.pp}}
  908. \html{\input{sysutex/ex29.tex}}
  909. \section{File handling functions}
  910. \begin{function}{ChangeFileExt}
  911. \Declaration
  912. Function ChangeFileExt(const FileName, Extension: string): string;
  913. \Description
  914. \var{ChangeFileExt} changes the file extension in \var{FileName} to
  915. \var{Extension}.
  916. The extension \var{Extension} includes the starting \var{.} (dot).
  917. The previous extension of \var{FileName} are all characters after the
  918. last \var{.}, the \var{.} character included.
  919. If \var{FileName} doesn't have an extension, \var{Extension} is just
  920. appended.
  921. \Errors
  922. None.
  923. \SeeAlso
  924. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExpandFileName}
  925. \end{function}
  926. \begin{function}{DeleteFile}
  927. \Declaration
  928. Function DeleteFile(Const FileName : String) : Boolean;
  929. \Description
  930. \var{DeleteFile} deletes file \var{FileName} from disk. The function
  931. returns \var{True} if the file was successfully removed, \var{False}
  932. otherwise.
  933. \Errors
  934. On error, \var{False} is returned.
  935. \SeeAlso
  936. \seef{FileCreate}, \seef{FileExists}
  937. \end{function}
  938. \latex{\lstinputlisting{sysutex/ex31.pp}}
  939. \html{\input{sysutex/ex31.tex}}
  940. \begin{procedure}{DoDirSeparators}
  941. \Declaration
  942. Procedure DoDirSeparators(Var FileName : String);
  943. \Description
  944. This function replaces all directory separators \var{'\' and '/'}
  945. to the directory separator character for the current system.
  946. \Errors
  947. None.
  948. \SeeAlso
  949. \seef{ExtractFileName}, \seef{ExtractFilePath}
  950. \end{procedure}
  951. \latex{\lstinputlisting{sysutex/ex32.pp}}
  952. \html{\input{sysutex/ex32.tex}}
  953. \begin{function}{ExpandFileName}
  954. \Declaration
  955. Function ExpandFileName(Const FileName : string): String;
  956. \Description
  957. \var{ExpandFileName} expands the filename to an absolute filename.
  958. It changes all directory separator characters to the one appropriate for the
  959. system first.
  960. \Errors
  961. None.
  962. \SeeAlso
  963. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  964. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  965. \end{function}
  966. \latex{\lstinputlisting{sysutex/ex33.pp}}
  967. \html{\input{sysutex/ex33.tex}}
  968. \begin{function}{ExpandUNCFileName}
  969. \Declaration
  970. Function ExpandUNCFileName(Const FileName : string): String;
  971. \Description
  972. \var{ExpandUNCFileName} runs \seef{ExpandFileName} on \var{FileName}
  973. and then attempts to replace the driveletter by the name of a shared disk.
  974. \Errors
  975. \SeeAlso
  976. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  977. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  978. \end{function}
  979. \begin{function}{ExtractFileDir}
  980. \Declaration
  981. Function ExtractFileDir(Const FileName : string): string;
  982. \Description
  983. \var{ExtractFileDir} returns only the directory part of \var{FileName},
  984. not including a driveletter. The directory name has NO ending directory
  985. separator, in difference with \seef{ExtractFilePath}.
  986. \Errors
  987. None.
  988. \SeeAlso
  989. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  990. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  991. \end{function}
  992. \latex{\lstinputlisting{sysutex/ex34.pp}}
  993. \html{\input{sysutex/ex34.tex}}
  994. \begin{function}{ExtractFileDrive}
  995. \Declaration
  996. Function ExtractFileDrive(const FileName: string): string;
  997. \Description
  998. \var{Extract}
  999. \Errors
  1000. \SeeAlso
  1001. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  1002. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  1003. \end{function}
  1004. For an example, see \seef{ExtractFileDir}.
  1005. \begin{function}{ExtractFileExt}
  1006. \Declaration
  1007. Function ExtractFileExt(const FileName: string): string;
  1008. \Description
  1009. \var{ExtractFileExt} returns the extension (including the
  1010. \var{.}(dot) character) of \var{FileName}.
  1011. \Errors
  1012. None.
  1013. \SeeAlso
  1014. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  1015. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  1016. \end{function}
  1017. For an example, see \seef{ExtractFileDir}.
  1018. \begin{function}{ExtractFileName}
  1019. \Declaration
  1020. Function ExtractFileName(const FileName: string): string;
  1021. \Description
  1022. \var{ExtractFileName} returns the filename part from \var{FileName}.
  1023. The filename consists of all characters after the last directory separator
  1024. character ('/' or '\') or drive letter.
  1025. The full filename can always be reconstucted by concatenating the result
  1026. of \seef{ExtractFilePath} and \var{ExtractFileName}.
  1027. \Errors
  1028. None.
  1029. \SeeAlso
  1030. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  1031. \seef{ExtractFileDrive}, \seef{ExtractFileExt},\seef{ExtractRelativePath}
  1032. \end{function}
  1033. For an example, see \seef{ExtractFileDir}.
  1034. \begin{function}{ExtractFilePath}
  1035. \Declaration
  1036. Function ExtractFilePath(const FileName: string): string;
  1037. \Description
  1038. \var{ExtractFilePath} returns the path part (including driveletter) from
  1039. \var{FileName}. The path consists of all characters before the last
  1040. directory separator character ('/' or '\'), including the directory
  1041. separator itself.
  1042. In case there is only a drive letter, that will be returned.
  1043. The full filename can always be reconstucted by concatenating the result
  1044. of \var{ExtractFilePath} and \seef{ExtractFileName}.
  1045. \Errors
  1046. None.
  1047. \SeeAlso
  1048. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  1049. \seef{ExtractFileDrive}, \seef{ExtractFileExt}, \seef{ExtractRelativePath}
  1050. \end{function}
  1051. For an example, see \seef{ExtractFileDir}.
  1052. \begin{function}{ExtractRelativePath}
  1053. \Declaration
  1054. Function ExtractRelativePath(Const BaseName,DestNAme : String): String;
  1055. \Description
  1056. \var{ExtractRelativePath} constructs a relative path to go from
  1057. \var{BaseName} to \var{DestName}. If \var{DestName} is on another drive
  1058. (Not on Linux) then the whole \var{Destname} is returned.
  1059. {\em Note:} This function does not exist in the Delphi unit.
  1060. \Errors
  1061. None.
  1062. \SeeAlso
  1063. \seef{ExtractFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir},
  1064. \seef{ExtractFileDrive}, \seef{ExtractFileExt},
  1065. \end{function}
  1066. \latex{\lstinputlisting{sysutex/ex35.pp}}
  1067. \html{\input{sysutex/ex35.tex}}
  1068. \begin{function}{FileAge}
  1069. \Declaration
  1070. Function FileAge(Const FileName : String): Longint;
  1071. \Description
  1072. \var{FileAge} returns the last modification time of file \var{FileName}.
  1073. The FileDate format can be transformed to \var{TDateTime} format with the
  1074. \seef{FileDateToDateTime} function.
  1075. \Errors
  1076. In case of errors, \var{-1} is returned.
  1077. \SeeAlso
  1078. \seef{FileDateToDateTime}, \seef{FileExists}, \seef{FileGetAttr}
  1079. \end{function}
  1080. \latex{\lstinputlisting{sysutex/ex36.pp}}
  1081. \html{\input{sysutex/ex36.tex}}
  1082. \begin{procedure}{FileClose}
  1083. \Declaration
  1084. Procedure FileClose(Handle : Longint);
  1085. \Description
  1086. \var{FileClose} closes the file handle \var{Handle}. After this call,
  1087. attempting to read or write from the handle will result in an error.
  1088. \Errors
  1089. None.
  1090. \SeeAlso
  1091. \seef{FileCreate}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  1092. \seef{FileTruncate}, \seef{FileSeek}
  1093. \end{procedure}
  1094. For an example, see \seef{FileCreate}
  1095. \begin{function}{FileCreate}
  1096. \Declaration
  1097. Function FileCreate(Const FileName : String) : Longint;
  1098. \Description
  1099. \var{FileCreate} creates a new file with name \var{FileName} on the disk and
  1100. returns a file handle which can be used to read or write from the file with
  1101. the \seef{FileRead} and \seef{FileWrite} functions.
  1102. If a file with name \var{FileName} already existed on the disk, it is
  1103. overwritten.
  1104. \Errors
  1105. If an error occurs (e.g. disk full or non-existent path), the function
  1106. returns \var{-1}.
  1107. \SeeAlso
  1108. \seep{FileClose}, \seef{FileWrite}, \seef{FileOpen}, \seef{FileRead},
  1109. \seef{FileTruncate}, \seef{FileSeek}
  1110. \end{function}
  1111. \latex{\lstinputlisting{sysutex/ex37.pp}}
  1112. \html{\input{sysutex/ex37.tex}}
  1113. \begin{function}{FileExists}
  1114. \Declaration
  1115. Function FileExists(Const FileName : String) : Boolean;
  1116. \Description
  1117. \var{FileExists} returns \var{True} if a file with name \var{FileName}
  1118. exists on the disk, \var{False} otherwise.
  1119. \Errors
  1120. None.
  1121. \SeeAlso
  1122. \seef{FileAge}, \seef{FileGetAttr}, \seef{FileSetAttr}
  1123. \end{function}
  1124. \latex{\lstinputlisting{sysutex/ex38.pp}}
  1125. \html{\input{sysutex/ex38.tex}}
  1126. \begin{function}{FileGetAttr}
  1127. \Declaration
  1128. Function FileGetAttr(Const FileName : String) : Longint;
  1129. \Description
  1130. \var{FileGetAttr} returns the attribute settings of file
  1131. \var{FileName}. The attribute is a \var{OR}-ed combination
  1132. of the following constants:
  1133. \begin{description}
  1134. \item[faReadOnly] The file is read-only.
  1135. \item[faHidden] The file is hidden. (On \linux, this means that the filename
  1136. starts with a dot)
  1137. \item[faSysFile] The file is a system file (On \linux, this means that the
  1138. file is a character, block or FIFO file).
  1139. \item[faVolumeId] Volume Label. Not possible under \linux.
  1140. \item[faDirectory] File is a directory.
  1141. \item[faArchive] file is an archive. Not possible on \linux.
  1142. \end{description}
  1143. \Errors
  1144. In case of error, -1 is returned.
  1145. \SeeAlso
  1146. \seef{FileSetAttr}, \seef{FileAge}, \seef{FileGetDate}.
  1147. \end{function}
  1148. \latex{\lstinputlisting{sysutex/ex40.pp}}
  1149. \html{\input{sysutex/ex40.tex}}
  1150. \begin{function}{FileGetDate}
  1151. \Declaration
  1152. Function FileGetDate(Handle : Longint) : Longint;
  1153. \Description
  1154. \var{FileGetdate} returns the filetime of the opened file with filehandle
  1155. \var{Handle}. It is the same as \seef{FileAge}, with this difference that
  1156. \var{FileAge} only needs the file name, while \var{FilegetDate} needs an
  1157. open file handle.
  1158. \Errors
  1159. On error, -1 is returned.
  1160. \SeeAlso
  1161. \seef{FileAge}
  1162. \end{function}
  1163. \latex{\lstinputlisting{sysutex/ex39.pp}}
  1164. \html{\input{sysutex/ex39.tex}}
  1165. \begin{function}{FileOpen}
  1166. \Declaration
  1167. Function FileOpen(Const FileName : string; Mode : Integer) : Longint;
  1168. \Description
  1169. \var{FileOpen} opens a file with name \var{FileName} with mode \var{Mode}.
  1170. \var{Mode} can be one of the following constants:
  1171. \begin{description}
  1172. \item[fmOpenRead] The file is opened for reading.
  1173. \item[fmOpenWrite] The file is opened for writing.
  1174. \item[fmOpenReadWrite] The file is opened for reading and writing.
  1175. \end{description}
  1176. If the file has been successfully opened, it can be read from or written to
  1177. (depending on the \var{Mode} parameter) with the \seef{FileRead} and
  1178. \var{FileWrite} functions.
  1179. Remark that you cannot open a file if it doesn't exist yet, i.e. it will not
  1180. be created for you. If you want tp create a new file, or overwrite an old
  1181. one, use the \seef{FileCreate} function.
  1182. \Errors
  1183. On Error, -1 is returned.
  1184. \SeeAlso
  1185. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileRead},
  1186. \seef{FileTruncate}, \seef{FileSeek}
  1187. \end{function}
  1188. For an example, see \seef{FileRead}
  1189. \begin{function}{FileRead}
  1190. \Declaration
  1191. Function FileRead(Handle : Longint; Var Buffer; Count : longint) : Longint;
  1192. \Description
  1193. \var{FileRead} reads \var{Count} bytes from file-handle \var{Handle} and
  1194. stores them into \var{Buffer}. Buffer must be at least \var{Count} bytes
  1195. long. No checking on this is performed, so be careful not to overwrite any
  1196. memory. \var{Handle} must be the result of a \seef{FileOpen} call.
  1197. \Errors
  1198. On error, -1 is returned.
  1199. \SeeAlso
  1200. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen},
  1201. \seef{FileTruncate}, \seef{FileSeek}
  1202. \end{function}
  1203. For an example, see \seef{FileOpen}
  1204. \begin{function}{FileSearch}
  1205. \Declaration
  1206. Function FileSearch(Const Name, DirList : String) : String;
  1207. \Description
  1208. \var{FileSearch} looks for the file \var{Name} in \var{DirList}, where
  1209. dirlist is a list of directories, separated by semicolons or colons.
  1210. It returns the full filename of the first match found.
  1211. \Errors
  1212. On error, an empty string is returned.
  1213. \SeeAlso
  1214. \seef{ExpandFileName}, \seef{FindFirst}
  1215. \end{function}
  1216. \latex{\lstinputlisting{sysutex/ex41.pp}}
  1217. \html{\input{sysutex/ex41.tex}}
  1218. \begin{function}{FileSeek}
  1219. \Declaration
  1220. Function FileSeek(Handle,Offset,Origin : Longint) : Longint;
  1221. \Description
  1222. \var{FileSeek} sets the file pointer on position \var{Offset}, starting from
  1223. \var{Origin}. Origin can be one of the following values:
  1224. \begin{description}
  1225. \item[fsFromBeginning] \var{Offset} is relative to the first byte of the file. This
  1226. position is zero-based. i.e. the first byte is at offset 0.
  1227. \item[fsFromCurrent] \var{Offset} is relative to the current position.
  1228. \item[fsFromEnd] \var{Offset} is relative to the end of the file. This means
  1229. that \var{Offset} can only be zero or negative in this case.
  1230. \end{description}
  1231. If successfull, the function returns the new file position, relative to the
  1232. beginning of the file.
  1233. {\em Remark:} The abovementioned constants do not exist in Delphi.
  1234. \Errors
  1235. On error, -1 is returned.
  1236. \SeeAlso
  1237. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  1238. \seef{FileRead}, \seef{FileTruncate}
  1239. \end{function}
  1240. \latex{\lstinputlisting{sysutex/ex42.pp}}
  1241. \html{\input{sysutex/ex42.tex}}
  1242. For an example, see \seef{FileCreate}
  1243. \begin{functionl}{FileSetAttr (Not on Linux)}{FileSetAttr}
  1244. \Declaration
  1245. Function FileSetAttr(Const Filename : String; Attr: longint) : Longint;
  1246. \Description
  1247. \var{FileSetAttr} sets the attributes of \var{FileName} to \var{Attr}.
  1248. If the function was successful, 0 is returned, -1 otherwise.
  1249. \var{Attr} can be set to an OR-ed combination of the pre-defined
  1250. \var{faXXX} constants.
  1251. \Errors
  1252. On error, -1 is returned (always on linux).
  1253. \SeeAlso
  1254. \seef{FileGetAttr}, \seef{FileGetDate}, \seef{FileSetDate}.
  1255. \end{functionl}
  1256. \begin{functionl}{FileSetDate (Not on Linux)}{FileSetDate}
  1257. \Declaration
  1258. Function FileSetDate(Handle,Age : Longint) : Longint;
  1259. \Description
  1260. \var{FileSetDate} sets the file date of the file with handle \var{Handle}
  1261. to \var{Age}, where \var{Age} is a DOS date-and-time stamp value.
  1262. The function returns zero of successfull.
  1263. \Errors
  1264. On Linux, -1 is always returned, since this is impossible to implement.
  1265. On Windows and DOS, a negative error code is returned.
  1266. \SeeAlso
  1267. \end{functionl}
  1268. \begin{function}{FileTruncate}
  1269. \Declaration
  1270. Function FileTruncate(Handle,Size: Longint) : boolean;
  1271. \Description
  1272. \var{FileTruncate} truncates the file with handle \var{Handle} to
  1273. \var{Size} bytes. The file must have been opened for writing prior
  1274. to this call. The function returns \var{True} is successful, \var{False}
  1275. otherwise.
  1276. \Errors
  1277. On error, the function returns \var{False}.
  1278. \SeeAlso
  1279. \seep{FileClose}, \seef{FileWrite}, \seef{FileCreate}, \seef{FileOpen}
  1280. \seef{FileRead}, \seef{FileSeek}
  1281. \end{function}
  1282. For an example, see \seef{FileCreate}.
  1283. \begin{function}{FileWrite}
  1284. \Declaration
  1285. Function FileWrite(Handle : Longint; Var Buffer; Count : Longint) : Longint;
  1286. \Description
  1287. \var{FileWrite} writes \var{Count} bytes from \var{Buffer} to the file with
  1288. handle \var{Handle}. Prior to this call, the file must have been opened
  1289. for writing. \var{Buffer} must be at least \var{Count} bytes large, or
  1290. a memory access error may occur.
  1291. The function returns the number of bytes written, or -1 in case of an
  1292. error.
  1293. \Errors
  1294. In case of error, -1 is returned.
  1295. \SeeAlso
  1296. \seep{FileClose}, \seef{FileCreate}, \seef{FileOpen}
  1297. \seef{FileRead}, \seef{FileTruncate}, \seef{FileSeek}
  1298. \end{function}
  1299. For an example, see \seef{FileCreate}.
  1300. \begin{procedurel}{FindClose}{FindCloseSys}
  1301. \Declaration
  1302. Procedure FindClose(Var F : TSearchrec);
  1303. \Description
  1304. \var{FindClose} ends a series of \seef{FindFirst}/\seef{FindNext} calls,
  1305. and frees any memory used by these calls. It is {\em absolutely} necessary
  1306. to do this call, or huge memory losses may occur.
  1307. \Errors
  1308. None.
  1309. \SeeAlso
  1310. \seef{FindFirst}, \seef{FindNext}.
  1311. \end{procedurel}
  1312. For an example, see \seef{FindFirst}.
  1313. \begin{function}{FindFirst}
  1314. \Declaration
  1315. Function FindFirst(Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
  1316. \Description
  1317. \var{FindFirst} looks for files that match the name (possibly with
  1318. wildcards) in \var{Path} and attributes \var{Attr}. It then fills up the
  1319. \var{Rslt} record with data gathered about the file. It returns 0 if a file
  1320. matching the specified criteria is found, a nonzero value (-1 on linux)
  1321. otherwise.
  1322. The \var{Rslt} record can be fed to subsequent calls to \var{FindNext}, in
  1323. order to find other files matching the specifications.
  1324. {\em remark:} A \var{FindFirst} call must {\em always} be followed by a
  1325. \seepl{FindClose}{FindCloseSys} call with the same \var{Rslt} record. Failure to do so will
  1326. result in memory loss.
  1327. \Errors
  1328. On error the function returns -1 on linux, a nonzero error code on Windows.
  1329. \SeeAlso
  1330. \seep{FindClose}{FindCloseSys}, \seef{FindNext}.
  1331. \end{function}
  1332. \latex{\lstinputlisting{sysutex/ex43.pp}}
  1333. \html{\input{sysutex/ex43.tex}}
  1334. \begin{function}{FindNext}
  1335. \Declaration
  1336. Function FindNext(Var Rslt : TSearchRec) : Longint;
  1337. \Description
  1338. \var{FindNext} finds a next occurrence of a search sequence initiated by
  1339. \var{FindFirst}. If another record matching the criteria in Rslt is found, 0
  1340. is returned, a nonzero constant is returned otherwise.
  1341. {\em remark:} The last \var{FindNext} call must {\em always} be followed by a
  1342. \var{FindClose} call with the same \var{Rslt} record. Failure to do so will
  1343. result in memory loss.
  1344. \Errors
  1345. On error (no more file is found), a nonzero constant is returned.
  1346. \SeeAlso
  1347. \seef{FindFirst}, \seep{FindClose}
  1348. \end{function}
  1349. For an example, see \seef{FindFirst}
  1350. \begin{function}{GetDirs}
  1351. \Declaration
  1352. Function GetDirs(Var DirName : String; Var Dirs : Array of pchar) : Longint;
  1353. \Description
  1354. \var{GetDirs} splits DirName in a null-byte separated list of directory names,
  1355. \var{Dirs} is an array of \var{PChars}, pointing to these directory names.
  1356. The function returns the number of directories found, or -1 if none were found.
  1357. DirName must contain only OSDirSeparator as Directory separator chars.
  1358. \Errors
  1359. None.
  1360. \SeeAlso
  1361. \seef{ExtractRelativePath}
  1362. \end{function}
  1363. \latex{\lstinputlisting{sysutex/ex45.pp}}
  1364. \html{\input{sysutex/ex45.tex}}
  1365. \begin{function}{RenameFile}
  1366. \Declaration
  1367. Function RenameFile(Const OldName, NewName : String) : Boolean;
  1368. \Description
  1369. \var{RenameFile} renames a file from \var{OldName} to \var{NewName}. The
  1370. function returns \var{True} if successful, \var{False} otherwise.
  1371. {\em Remark:} you cannot rename across disks or partitions.
  1372. \Errors
  1373. On Error, \var{False} is returned.
  1374. \SeeAlso
  1375. \seef{DeleteFile}
  1376. \end{function}
  1377. \latex{\lstinputlisting{sysutex/ex44.pp}}
  1378. \html{\input{sysutex/ex44.tex}}
  1379. \begin{function}{SetDirSeparators}
  1380. \Declaration
  1381. Function SetDirSeparators(Const FileName : String) : String;
  1382. \Description
  1383. \var{SetDirSeparators} returns \var{FileName} with all possible
  1384. DirSeparators replaced by \var{OSDirSeparator}.
  1385. \Errors
  1386. None.
  1387. \SeeAlso
  1388. \seef{ExpandFileName}, \seef{ExtractFilePath}, \seef{ExtractFileDir}
  1389. \end{function}
  1390. \latex{\lstinputlisting{sysutex/ex47.pp}}
  1391. \html{\input{sysutex/ex47.tex}}
  1392. \section{PChar functions}
  1393. \subsection{Introduction}
  1394. Most PChar functions are the same as their counterparts in the \file{STRINGS}
  1395. unit. The following functions are the same :
  1396. \begin{enumerate}
  1397. \item \seef{StrCat} : Concatenates two \var{PChar} strings.
  1398. \item \seef{StrComp} : Compares two \var{PChar} strings.
  1399. \item \seef{StrCopy} : Copies a \var{PChar} string.
  1400. \item \seef{StrECopy} : Copies a \var{PChar} string and returns a pointer to
  1401. the terminating null byte.
  1402. \item \seef{StrEnd} : Returns a pointer to the terminating null byte.
  1403. \item \seef{StrIComp} : Case insensitive compare of 2 \var{PChar} strings.
  1404. \item \seef{StrLCat} : Appends at most L characters from one \var{PChar} to
  1405. another \var{PChar}.
  1406. \item \seef{StrLComp} : Case sensitive compare of at most L characters of 2
  1407. \var{PChar} strings.
  1408. \item \seef{StrLCopy} : Copies at most L characters from one \var{PChar} to
  1409. another.
  1410. \item \seef{StrLen} : Returns the length (exclusive terminating null byte)
  1411. of a \var{PChar} string.
  1412. \item \seef{StrLIComp} : Case insensitive compare of at most L characters of 2
  1413. \var{PChar} strings.
  1414. \item \seef{StrLower} : Converts a \var{PChar} to all lowercase letters.
  1415. \item \seef{StrMove} : Moves one \var{PChar} to another.
  1416. \item \seef{StrNew} : Makes a copy of a \var{PChar} on the heap, and returns
  1417. a pointer to this copy.
  1418. \item \seef{StrPos} : Returns the position of one \var{PChar} string in
  1419. another?
  1420. \item \seef{StrRScan} : returns a pointer to the last occurrence of on
  1421. \var{PChar} string in another one.
  1422. \item \seef{StrScan} : returns a pointer to the first occurrence of on
  1423. \var{PChar} string in another one.
  1424. \item \seef{StrUpper} : Converts a \var{PChar} to all uppercase letters.
  1425. \end{enumerate}
  1426. The subsequent functions are different from their counterparts in
  1427. \file{STRINGS}, although the same examples can be used.
  1428. \begin{functionl}{StrAlloc}{StrAllocSys}
  1429. \Declaration
  1430. Function StrAlloc(Size: cardinal): PChar;
  1431. \Description
  1432. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  1433. terminating \var{\#0} included, and returns a pointer to it.
  1434. Additionally, \var{StrAlloc} allocates 4 extra bytes to store the size of
  1435. the allocated memory. Therefore this function is NOT compatible with the
  1436. \seef{StrAlloc} function of the \var{Strings} unit.
  1437. \Errors
  1438. None.
  1439. \SeeAlso
  1440. \seef{StrBufSize}, \seepl{StrDispose}{StrDisposeSys}, \seef{StrAlloc}
  1441. \end{functionl}
  1442. For an example, see \seef{StrBufSize}.
  1443. \begin{function}{StrBufSize}
  1444. \Declaration
  1445. Function StrBufSize(var Str: PChar): cardinal;
  1446. \Description
  1447. \var{StrBufSize} returns the memory allocated for \var{Str}. This function
  1448. ONLY gives the correct result if \var{Str} was allocated using
  1449. \seefl{StrAlloc}{StrAllocSys}.
  1450. \Errors
  1451. If no more memory is available, a runtime error occurs.
  1452. \SeeAlso
  1453. \seefl{StrAlloc}{StrAllocSys}.\seepl{StrDispose}{StrDisposeSys}.
  1454. \end{function}
  1455. \latex{\lstinputlisting{sysutex/ex46.pp}}
  1456. \html{\input{sysutex/ex46.tex}}
  1457. \begin{procedurel}{StrDispose}{StrDisposeSys}
  1458. \Declaration
  1459. Procedure StrDispose(var Str: PChar);
  1460. \Description
  1461. \var{StrDispose} frees any memory allocated for \var{Str}. This function
  1462. will only function correctly if \var{Str} has been allocated using
  1463. \seefl{StrAlloc}{StrAllocSys} from the \file{SYSUTILS} unit.
  1464. \Errors
  1465. If an invalid pointer is passed, or a pointer not allocated with
  1466. \var{StrAlloc}, an error may occur.
  1467. \SeeAlso
  1468. \seef{StrBufSize}, \seefl{StrAlloc}{StrAllocSys}, \seep{StrDispose}
  1469. \end{procedurel}
  1470. For an example, see \seef{StrBufSize}.
  1471. \begin{functionl}{StrPCopy}{StrPCopySys}
  1472. \Declaration
  1473. Function StrPCopy(Dest: PChar; Source: string): PChar;
  1474. \Description
  1475. \var{StrPCopy} Converts the Ansistring in \var{Source} to a Null-terminated
  1476. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  1477. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  1478. \Errors
  1479. No checking is performed to see whether \var{Dest} points to enough memory
  1480. to contain \var{Source}.
  1481. \SeeAlso
  1482. \seefl{StrPLCopy}{StrPLCopySys}, \seef{StrPCopy}
  1483. \end{functionl}
  1484. For an example, see \seef{StrPCopy}.
  1485. \begin{functionl}{StrPLCopy}{StrPLCopySys}
  1486. \Declaration
  1487. Function StrPLCopy(Dest: PChar; Source: string; MaxLen: cardinal): PChar;
  1488. \Description
  1489. \var{StrPLCopy} Converts maximally \var{MaxLen} characters of the
  1490. Ansistring in \var{Source} to a Null-terminated string, and copies
  1491. it to \var{Dest}. \var{Dest} needs enough room to contain
  1492. the characters.
  1493. \Errors
  1494. No checking is performed to see whether \var{Dest} points to enough memory
  1495. to contain L characters of \var{Source}.
  1496. \Errors
  1497. \SeeAlso
  1498. \seefl{StrPCopy}{StrPCopySys}.
  1499. \end{functionl}
  1500. \begin{functionl}{StrPas}{StrPasSys}
  1501. \Declaration
  1502. Function StrPas(Str: PChar): string;
  1503. \Description
  1504. Converts a null terminated string in \var{Str} to an Ansitring, and returns
  1505. this string. This string is NOT truncated at 255 characters as is the
  1506. \Errors
  1507. None.
  1508. \SeeAlso
  1509. \seef{StrPas}.
  1510. \end{functionl}
  1511. For an example, see \seef{StrPas}.
  1512. \section{String handling functions}
  1513. \begin{function}{AdjustLineBreaks}
  1514. \Declaration
  1515. Function AdjustLineBreaks(const S: string): string;
  1516. \Description
  1517. \var{AdjustLineBreaks} will change all \var{\#13} characters with
  1518. \var{\#13\#10} on \windowsnt and \dos. On \linux, all \var{\#13\#10}
  1519. character pairs are converted to \var{\#10} and single \var{\#13}
  1520. characters also.
  1521. \Errors
  1522. None.
  1523. \SeeAlso
  1524. \seef{AnsiCompareStr}, \seef{AnsiCompareText}
  1525. \end{function}
  1526. \latex{\lstinputlisting{sysutex/ex48.pp}}
  1527. \html{\input{sysutex/ex48.tex}}
  1528. \begin{function}{AnsiCompareStr}
  1529. \Declaration
  1530. Function AnsiCompareStr(const S1, S2: string): integer;
  1531. \Description
  1532. \var{AnsiCompareStr} compares two strings and returns the following
  1533. result:
  1534. \begin{description}
  1535. \item[<0] if \var{S1<S2}.
  1536. \item[0] if \var{S1=S2}.
  1537. \item[>0] if \var{S1>S2}.
  1538. \end{description}
  1539. the comparision takes into account Ansi characters, i.e. it takes
  1540. care of strange accented characters. Contrary to \seef{AnsiCompareText},
  1541. the comparision is case sensitive.
  1542. \Errors
  1543. None.
  1544. \SeeAlso
  1545. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  1546. \end{function}
  1547. \latex{\lstinputlisting{sysutex/ex49.pp}}
  1548. \html{\input{sysutex/ex49.tex}}
  1549. \begin{function}{AnsiCompareText}
  1550. \Declaration
  1551. Function AnsiCompareText(const S1, S2: string): integer;
  1552. \Description
  1553. \Description
  1554. \var{AnsiCompareText} compares two strings and returns the following
  1555. result:
  1556. \begin{description}
  1557. \item[<0] if \var{S1<S2}.
  1558. \item[0] if \var{S1=S2}.
  1559. \item[>0] if \var{S1>S2}.
  1560. \end{description}
  1561. the comparision takes into account Ansi characters, i.e. it takes
  1562. care of strange accented characters. Contrary to \seef{AnsiCompareStr},
  1563. the comparision is case insensitive.
  1564. \Errors
  1565. None.
  1566. \SeeAlso
  1567. \seef{AdjustLineBreaks}, \seef{AnsiCompareText}
  1568. \end{function}
  1569. \latex{\lstinputlisting{sysutex/ex50.pp}}
  1570. \html{\input{sysutex/ex50.tex}}
  1571. \begin{function}{AnsiExtractQuotedStr}
  1572. \Declaration
  1573. Function AnsiExtractQuotedStr(var Src: PChar; Quote: Char): string;
  1574. \Description
  1575. \var{AnsiExtractQuotedStr} Returns \var{Src} as a string,, with \var{Quute}
  1576. characters removed from the beginning and end of the string, and double
  1577. \var{Quote} characters replaced by a single \var{Quote} characters.
  1578. As such, it revereses the action of \seef{AnsiQuotedStr}.
  1579. \Errors
  1580. None.
  1581. \SeeAlso
  1582. \seef{AnsiQuotedStr}
  1583. \end{function}
  1584. \latex{\lstinputlisting{sysutex/ex51.pp}}
  1585. \html{\input{sysutex/ex51.tex}}
  1586. \begin{function}{AnsiLastChar}
  1587. \Declaration
  1588. Function AnsiLastChar(const S: string): PChar;
  1589. \Description
  1590. This function returns a pointer to the last character of \var{S}.
  1591. Since multibyte characters are not yet supported, this is the same
  1592. as \var{@S[Length(S)])}.
  1593. \Errors
  1594. None.
  1595. \SeeAlso
  1596. \seef{AnsiStrLastChar}
  1597. \end{function}
  1598. \latex{\lstinputlisting{sysutex/ex52.pp}}
  1599. \html{\input{sysutex/ex52.tex}}
  1600. \begin{function}{AnsiLowerCase}
  1601. \Declaration
  1602. Function AnsiLowerCase(const s: string): string;
  1603. \Description
  1604. \var{AnsiLowerCase} converts the string \var{S} to lowercase characters
  1605. and returns the resulting string.
  1606. It takes into account the operating system language
  1607. settings when doing this, so spcial characters are converted correctly as
  1608. well.
  1609. {\em Remark} On linux, no language setting is taken in account yet.
  1610. \Errors
  1611. None.
  1612. \SeeAlso
  1613. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiStrUpper}
  1614. \end{function}
  1615. \latex{\lstinputlisting{sysutex/ex53.pp}}
  1616. \html{\input{sysutex/ex53.tex}}
  1617. \begin{function}{AnsiQuotedStr}
  1618. \Declaration
  1619. Function AnsiQuotedStr(const S: string; Quote: char): string;
  1620. \Description
  1621. \var{AnsiQuotedString} quotes the string \var{S} and returns the result.
  1622. This means that it puts the \var{Quote} character at both the beginning and
  1623. end of the string and replaces any occurrence of \var{Quote} in \var{S}
  1624. with 2 \var{Quote} characters. The action of \var{AnsiQuotedString} can be
  1625. reversed by \seef{AnsiExtractQuotedStr}.
  1626. \Errors
  1627. None.
  1628. \SeeAlso
  1629. \seef{AnsiExtractQuotedStr}
  1630. \end{function}
  1631. For an example, see \seef{AnsiExtractQuotedStr}
  1632. \begin{function}{AnsiStrComp}
  1633. \Declaration
  1634. Function AnsiStrComp(S1, S2: PChar): integer;
  1635. \Description
  1636. \var{AnsiStrComp} compares 2 \var{PChar} strings, and returns the following
  1637. result:
  1638. \begin{description}
  1639. \item[<0] if \var{S1<S2}.
  1640. \item[0] if \var{S1=S2}.
  1641. \item[>0] if \var{S1>S2}.
  1642. \end{description}
  1643. The comparision of the two strings is case-sensitive.
  1644. The function does not yet take internationalization settings into account.
  1645. \Errors
  1646. None.
  1647. \SeeAlso
  1648. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1649. \end{function}
  1650. \latex{\lstinputlisting{sysutex/ex54.pp}}
  1651. \html{\input{sysutex/ex54.tex}}
  1652. \begin{function}{AnsiStrIComp}
  1653. \Declaration
  1654. Function AnsiStrIComp(S1, S2: PChar): integer;
  1655. \Description
  1656. \var{AnsiStrIComp} compares 2 \var{PChar} strings, and returns the following
  1657. result:
  1658. \begin{description}
  1659. \item[<0] if \var{S1<S2}.
  1660. \item[0] if \var{S1=S2}.
  1661. \item[>0] if \var{S1>S2}.
  1662. \end{description}
  1663. The comparision of the two strings is case-insensitive.
  1664. The function does not yet take internationalization settings into account.
  1665. \Errors
  1666. None.
  1667. \SeeAlso
  1668. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1669. \end{function}
  1670. \latex{\lstinputlisting{sysutex/ex55.pp}}
  1671. \html{\input{sysutex/ex55.tex}}
  1672. \begin{function}{AnsiStrLastChar}
  1673. \Declaration
  1674. function AnsiStrLastChar(Str: PChar): PChar;
  1675. \Declaration
  1676. \var{AnsiStrLastChar} returns a pointer to the last character of \var{Str}.
  1677. Since multibyte characters are not yet supported, this is the same
  1678. as \var{StrEnd(Str)-1}.
  1679. \Errors
  1680. None.
  1681. \SeeAlso
  1682. \seef{AnsiLastChar}
  1683. \end{function}
  1684. \latex{\lstinputlisting{sysutex/ex58.pp}}
  1685. \html{\input{sysutex/ex58.tex}}
  1686. \begin{function}{AnsiStrLComp}
  1687. \Declaration
  1688. Function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
  1689. \Description
  1690. \var{AnsiStrLComp} compares the first \var{Maxlen} characters of
  1691. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  1692. result:
  1693. \begin{description}
  1694. \item[<0] if \var{S1<S2}.
  1695. \item[0] if \var{S1=S2}.
  1696. \item[>0] if \var{S1>S2}.
  1697. \end{description}
  1698. The comparision of the two strings is case-sensitive.
  1699. The function does not yet take internationalization settings into account.
  1700. \Errors
  1701. None.
  1702. \SeeAlso
  1703. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1704. \end{function}
  1705. \latex{\lstinputlisting{sysutex/ex56.pp}}
  1706. \html{\input{sysutex/ex56.tex}}
  1707. \begin{function}{AnsiStrLIComp}
  1708. \Declaration
  1709. Function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
  1710. \Description
  1711. \var{AnsiStrLIComp} compares the first \var{Maxlen} characters of
  1712. 2 \var{PChar} strings, \var{S1} and \var{S2}, and returns the following
  1713. result:
  1714. \begin{description}
  1715. \item[<0] if \var{S1<S2}.
  1716. \item[0] if \var{S1=S2}.
  1717. \item[>0] if \var{S1>S2}.
  1718. \end{description}
  1719. The comparision of the two strings is case-insensitive.
  1720. The function does not yet take internationalization settings into account.
  1721. \Errors
  1722. None.
  1723. \SeeAlso
  1724. \seef{AnsiCompareText}, \seef{AnsiCompareStr}
  1725. \end{function}
  1726. \latex{\lstinputlisting{sysutex/ex57.pp}}
  1727. \html{\input{sysutex/ex57.tex}}
  1728. \begin{function}{AnsiStrLower}
  1729. \Declaration
  1730. Function AnsiStrLower(Str: PChar): PChar;
  1731. \Description
  1732. \var{AnsiStrLower} converts the PChar \var{Str} to lowercase characters
  1733. and returns the resulting pchar. Note that \var{Str} itself is modified,
  1734. not a copy, as in the case of \seef{AnsiLowerCase}.
  1735. It takes into account the operating system language
  1736. settings when doing this, so spcial characters are converted correctly as
  1737. well.
  1738. {\em Remark} On linux, no language setting is taken in account yet.
  1739. \Errors
  1740. None.
  1741. \SeeAlso
  1742. \seef{AnsiStrUpper}, \seef{AnsiLowerCase}
  1743. \end{function}
  1744. \latex{\lstinputlisting{sysutex/ex59.pp}}
  1745. \html{\input{sysutex/ex59.tex}}
  1746. \begin{function}{AnsiStrUpper}
  1747. \Declaration
  1748. Function AnsiStrUpper(Str: PChar): PChar;
  1749. \Description
  1750. \var{AnsiStrUpper} converts the \var{PChar} \var{Str} to uppercase characters
  1751. and returns the resulting string. Note that \var{Str} itself is modified,
  1752. not a copy, as in the case of \seef{AnsiUpperCase}.
  1753. It takes into account the operating system language
  1754. settings when doing this, so spcial characters are converted correctly as
  1755. well.
  1756. {\em Remark} On linux, no language setting is taken in account yet.
  1757. \Errors
  1758. None.
  1759. \SeeAlso
  1760. \seef{AnsiUpperCase}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  1761. \end{function}
  1762. \latex{\lstinputlisting{sysutex/ex60.pp}}
  1763. \html{\input{sysutex/ex60.tex}}
  1764. \begin{function}{AnsiUpperCase}
  1765. \Declaration
  1766. Function AnsiUpperCase(const s: string): string;
  1767. \Description
  1768. \var{AnsiUpperCase} converts the string \var{S} to uppercase characters
  1769. and returns the resulting string.
  1770. It takes into account the operating system language
  1771. settings when doing this, so spcial characters are converted correctly as
  1772. well.
  1773. {\em Remark} On linux, no language setting is taken in account yet.
  1774. \Errors
  1775. None.
  1776. \SeeAlso
  1777. \seef{AnsiStrUpper}, \seef{AnsiStrLower}, \seef{AnsiLowerCase}
  1778. \end{function}
  1779. \latex{\lstinputlisting{sysutex/ex61.pp}}
  1780. \html{\input{sysutex/ex61.tex}}
  1781. \begin{procedure}{AppendStr}
  1782. \Declaration
  1783. Procedure AppendStr(var Dest: String; const S: string);
  1784. \Description
  1785. \var{AppendStr} appends \var{S} to Dest.
  1786. This function is provided for Delphi
  1787. compatibility only, since it is completely equivalent to \var{Dest:=Dest+S}.
  1788. \Errors
  1789. None.
  1790. \SeeAlso
  1791. \seep{AssignStr},\seef{NewStr}, \seep{DisposeStr}
  1792. \end{procedure}
  1793. \latex{\lstinputlisting{sysutex/ex62.pp}}
  1794. \html{\input{sysutex/ex62.tex}}
  1795. \begin{procedure}{AssignStr}
  1796. \Declaration
  1797. Procedure AssignStr(var P: PString; const S: string);
  1798. \Description
  1799. \var{AssignStr} allocates \var{S} to P. The old value of \var{P} is
  1800. disposed of.
  1801. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  1802. are managed on the heap and should be preferred to the mechanism of
  1803. dynamically allocated strings.
  1804. \Errors
  1805. None.
  1806. \SeeAlso
  1807. \seef{NewStr}, \seep{AppendStr}, \seep{DisposeStr}
  1808. \end{procedure}
  1809. \latex{\lstinputlisting{sysutex/ex63.pp}}
  1810. \html{\input{sysutex/ex63.tex}}
  1811. \begin{function}{BCDToInt}
  1812. \Declaration
  1813. Function BCDToInt(Value: integer): integer;
  1814. \Description
  1815. \var{BCDToInt} converts a \var{BCD} coded integer to a normal integer.
  1816. \Errors
  1817. None.
  1818. \SeeAlso
  1819. \seef{StrToInt}, \seef{IntToStr}
  1820. \end{function}
  1821. \latex{\lstinputlisting{sysutex/ex64.pp}}
  1822. \html{\input{sysutex/ex64.tex}}
  1823. \begin{function}{CompareMem}
  1824. \Declaration
  1825. Function CompareMem(P1, P2: Pointer; Length: cardinal): integer;
  1826. \Description
  1827. \var{CompareMem} compares, byte by byte, 2 memory areas pointed
  1828. to by \var{P1} and \var{P2}, for a length of \var{L} bytes.
  1829. It returns the following values:
  1830. \begin{description}
  1831. \item[<0] if at some position the byte at \var{P1} is less than the byte at the
  1832. same postion at \var{P2}.
  1833. \item[0] if all \var{L} bytes are the same.
  1834. \item[3]
  1835. \end{description}
  1836. \Errors
  1837. \SeeAlso
  1838. \end{function}
  1839. \begin{function}{CompareStr}
  1840. \Declaration
  1841. Function CompareStr(const S1, S2: string): Integer;
  1842. \Description
  1843. \var{CompareStr} compares two strings, \var{S1} and \var{S2},
  1844. and returns the following
  1845. result:
  1846. \begin{description}
  1847. \item[<0] if \var{S1<S2}.
  1848. \item[0] if \var{S1=S2}.
  1849. \item[>0] if \var{S1>S2}.
  1850. \end{description}
  1851. The comparision of the two strings is case-sensitive.
  1852. The function does not take internationalization settings into account, it
  1853. simply compares ASCII values.
  1854. \Errors
  1855. None.
  1856. \SeeAlso
  1857. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareText}
  1858. \end{function}
  1859. \latex{\lstinputlisting{sysutex/ex65.pp}}
  1860. \html{\input{sysutex/ex65.tex}}
  1861. \begin{function}{CompareText}
  1862. \Declaration
  1863. Function CompareText(const S1, S2: string): integer;
  1864. \Description
  1865. \var{CompareText} compares two strings, \var{S1} and \var{S2},
  1866. and returns the following
  1867. result:
  1868. \begin{description}
  1869. \item[<0] if \var{S1<S2}.
  1870. \item[0] if \var{S1=S2}.
  1871. \item[>0] if \var{S1>S2}.
  1872. \end{description}
  1873. The comparision of the two strings is case-insensitive.
  1874. The function does not take internationalization settings into account, it
  1875. simply compares ASCII values.
  1876. \Errors
  1877. None.
  1878. \SeeAlso
  1879. \seef{AnsiCompareText}, \seef{AnsiCompareStr}, \seef{CompareStr}
  1880. \end{function}
  1881. \latex{\lstinputlisting{sysutex/ex66.pp}}
  1882. \html{\input{sysutex/ex66.tex}}
  1883. \begin{procedurel}{DisposeStr}{DisposeStrSys}
  1884. \Declaration
  1885. Procedure DisposeStr(S: PString);
  1886. \Description
  1887. \var{DisposeStr} removes the dynamically allocated string \var{S} from the
  1888. heap, and releases the occupied memory.
  1889. This function is provided for Delphi compatibility only. \var{AnsiStrings}
  1890. are managed on the heap and should be preferred to the mechanism of
  1891. dynamically allocated strings.
  1892. \Errors
  1893. None.
  1894. \SeeAlso
  1895. \seef{NewStr}, \seep{AppendStr}, \seep{AssignStr}
  1896. \end{procedurel}
  1897. For an example, see \seep{DisposeStr}.
  1898. \begin{function}{FloatToStr}
  1899. \Declaration
  1900. Function FloatToStr(Value: Extended): String;
  1901. \Description
  1902. \var{FloatToStr} converts the floating point variable \var{Value} to a
  1903. string representation. It will choose the shortest possible notation of the
  1904. two following formats:
  1905. \begin{description}
  1906. \item[Fixed format] will represent the string in fixed notation,
  1907. \item[Decimal format] will represent the string in scientific notation.
  1908. \end{description}
  1909. (more information on these formats can be found in \seef{FloatToStrF})
  1910. \var{FloatToStr} is completely equivalent to a \var{FloatToStrF(Value, ffGeneral,
  1911. 15, 0);} call.
  1912. \Errors
  1913. None.
  1914. \SeeAlso
  1915. \seef{FloatToStrF}
  1916. %, \seef{FormatFloat}
  1917. \end{function}
  1918. \latex{\lstinputlisting{sysutex/ex67.pp}}
  1919. \html{\input{sysutex/ex67.tex}}
  1920. \begin{function}{FloatToStrF}
  1921. \Declaration
  1922. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  1923. \Description
  1924. \var{FloatToStrF} converts the floating point number \var{value} to a string
  1925. representation, according to the settings of the parameters \var{Format},
  1926. \var{Precision} and \var{Digits}.
  1927. The meaning of the \var{Precision} and \var{Digits} parameter depends on the
  1928. \var{Format} parameter. The format is controlled mainly by the \var{Format}
  1929. parameter. It can have one of the following values:
  1930. \begin{description}
  1931. \item[ffcurrency] Money format. \var{Value} is converted to a string using
  1932. the global variables \var{CurrencyString}, \var{CurrencyFormat} and
  1933. \var{NegCurrencyFormat}. The \var{Digits} paramater specifies the number of digits
  1934. following the decimal point and should be in the range -1 to 18. If Digits
  1935. equals \var{-1}, \var{CurrencyDecimals} is assumed. The \var{Precision} parameter is ignored.
  1936. %
  1937. \item[ffExponent] Scientific format. \var{Value} is converted to a
  1938. string using scientific notation: 1 digit before the decimal point, possibly
  1939. preceded by a minus sign if \var{Value} is negative. The number of
  1940. digits after the decimal point is controlled by \var{Precision} and must lie
  1941. in the range 0 to 15.
  1942. %
  1943. \item[ffFixed] Fixed point format. \var{Value} is converted to a string
  1944. using fixed point notation. The result is composed of all digits of the
  1945. integer part of \var{Value}, preceded by a minus sign if \var{Value} is
  1946. negative. Following the integer part is \var{DecimalSeparator} and then the
  1947. fractional part of \var{Value}, rounded off to \var{Digits} numbers.
  1948. If the number is too large then the result will be in scientific notation.
  1949. %
  1950. \item[ffGeneral] General number format. The argument is converted to a
  1951. string using \var{ffExponent} or \var{ffFixed} format, depending on wich one
  1952. gives the shortest string. There will be no trailing zeroes. If \var{Value}
  1953. is less than \var{0.00001} or if the number of decimals left of the decimal
  1954. point is larger than \var{Precision} then scientific notation is used, and
  1955. \var{Digits} is the minimum number of digits in the exponent. Otherwise
  1956. \var{Digits} is ignored.
  1957. \item[ffnumber] Is the same as \var{ffFixed}, except that thousand separators
  1958. are inserted in the resultig string.
  1959. \end{description}
  1960. \Errors
  1961. None.
  1962. \SeeAlso
  1963. \seef{FloatToStr}, \seef{FloatToText}
  1964. \end{function}
  1965. \latex{\lstinputlisting{sysutex/ex68.pp}}
  1966. \html{\input{sysutex/ex68.tex}}
  1967. \begin{function}{FloatToText}
  1968. \Declaration
  1969. Function FloatToText(Buffer : Pchar;Value: Extended; Format: TFloatFormat; Precision, Digits: Integer): Longint;
  1970. \Description
  1971. \var{FloatToText} converts the floating point variable \var{Value} to a
  1972. string representation and stores it in \var{Buffer}. The conversion is
  1973. giverned by \var{format}, \var{Precisison} and \var{Digits}.
  1974. more information on these parameters can be found in \seef{FloatToStrF}.
  1975. \var{Buffer} should point to enough space to hold the result. No checking on
  1976. this is performed.
  1977. The result is the number of characters that was copied in \var{Buffer}.
  1978. \Errors
  1979. None.
  1980. \SeeAlso
  1981. \seef{FloatToStr}, \seef{FloatToStrF}
  1982. \end{function}
  1983. \latex{\lstinputlisting{sysutex/ex69.pp}}
  1984. \html{\input{sysutex/ex69.tex}}
  1985. \begin{procedure}{FmtStr}
  1986. \Declaration
  1987. Procedure (Var Res: String; Const Fmt : String; Const args: Array of const);
  1988. \Description
  1989. \var{FmtStr} calls \seef{Format} with \var{Fmt} and \var{Args} as arguments,
  1990. and stores the result in \var{Res}. For more information on how the
  1991. resulting string is composed, see \seef{Format}.
  1992. \Errors
  1993. In case of error, a \var{EConvertError} exception is raised.
  1994. \SeeAlso
  1995. \seef{Format}, \seef{FormatBuf}.
  1996. \end{procedure}
  1997. \latex{\lstinputlisting{sysutex/ex70.pp}}
  1998. \html{\input{sysutex/ex70.tex}}
  1999. \begin{function}{Format}
  2000. \Declaration
  2001. Function Format(Const Fmt : String; const Args : Array of const) : String;
  2002. \Description
  2003. Format replaces all placeholders in\var{Fmt} with the arguments passed in
  2004. \var{Args} and returns the resulting string. A placeholder looks as follows:
  2005. \begin{verbatim}
  2006. '%' [Index':'] ['-'] [Width] ['.' Precision] ArgType
  2007. \end{verbatim}
  2008. elements between single quotes must be typed as shown without the quotes,
  2009. and elements between square brackets \var{[ ]} are optional. The meaning
  2010. of the different elements is shown below:
  2011. \begin{description}
  2012. \item['\%'] starts the placeholder. If you want to insert a literal
  2013. \var{\%} character, then you must insert two of them : \var{\%\%}.
  2014. \item[Index ':'] takes the \var{Index}-th element in the argument array
  2015. as the element to insert.
  2016. \item['-'] tells \var{Format} to left-align the inserted text. The default
  2017. behaviour is to right-align inserted text. This can only take effect if the
  2018. \var{Width} element is also specified.
  2019. \item[Width] the inserted string must have at least have \var{Width}
  2020. characters. If not, the inserted string will be padded with spaces. By
  2021. default, the string is left-padded, resulting in a right-aligned string.
  2022. This behaviour can be changed by the \var{'-'} character.
  2023. \item['.' Precision] Indicates the precision to be used when converting
  2024. the argument. The exact meaning of this parameter depends on \var{ArgType}.
  2025. \end{description}
  2026. The \var{Index}, \var{Width} and \var{Precision} parameters can be replaced
  2027. by \var{*}, in which case their value will be read from the next element in
  2028. the \var{Args} array. This value must be an integer, or an
  2029. \var{EConvertError} exception will be raised.
  2030. The argument type is determined from \var{ArgType}. It can have one of the
  2031. following values (case insensitive):
  2032. \begin{description}
  2033. \item[D] Decimal format. The next argument in the \var{Args} array should be
  2034. an integer. The argument is converted to a decimal string,. If precision is
  2035. specified, then the string will have at least \var{Precision} digits in it.
  2036. If needed, the string is (left) padded with zeroes.
  2037. \item[E] scientific format. The next argument in the \var{Args} array should
  2038. be a Floating point value. The argument is converted to a decimal string
  2039. using scientific notation, using \seef{FloatToStrF}, where the optional
  2040. precision is used to specify the total number of decimals. (defalt a valueof
  2041. 15 is used). The exponent is formatted using maximally 3 digits.
  2042. In short, the \var{E} specifier formats it's arguument as follows:
  2043. \begin{verbatim}
  2044. FloatToStrF(Argument,ffexponent,Precision,3)
  2045. \end{verbatim}
  2046. \item[F] fixed point format. The next argument in the \var{Args} array
  2047. should be a floating point value. The argument is converted to a
  2048. decimal string, using fixed notation (see \seef{FloatToStrF}).
  2049. \var{Precision} indicates the number of digits following the
  2050. decimal point.
  2051. In short, the \var{F} specifier formats it's arguument as follows:
  2052. \begin{verbatim}
  2053. FloatToStrF(Argument,ffFixed,ffixed,9999,Precision)
  2054. \end{verbatim}
  2055. \item[G] General number format. The next argument in the \var{Args} array
  2056. should be a floating point value. The argument is converted to a decimal
  2057. string using fixed point notation or scientific notation, depending on which
  2058. gives the shortest result. \var{Precision} is used to determine the number
  2059. of digits after the decimal point.
  2060. In short, the \var{G} specifier formats it's arguument as follows:
  2061. \begin{verbatim}
  2062. FloatToStrF(Argument,ffGeneral,Precision,3)
  2063. \end{verbatim}
  2064. \item[M] Currency format. the next argument in the var{Args} array must
  2065. be a floating point value. The argument is converted to a decimal string
  2066. using currency notation. This means that fixed-point notation is used, but
  2067. that the currency symbol is appended. If precision is specified, then
  2068. then it overrides the \var{CurrencyDecimals} global variable used in the
  2069. \seef{FloatToStrF}
  2070. In short, the \var{M} specifier formats it's arguument as follows:
  2071. \begin{verbatim}
  2072. FloatToStrF(Argument,ffCurrency,9999,Precision)
  2073. \end{verbatim}
  2074. \item[N] Number format. This is the same as fixed point format, except that
  2075. thousand separators are inserted in the resulting string.
  2076. \item[P] Pointer format. The next argument in the \var{Args} array must be a
  2077. pointer (typed or untyped). The pointer value is converted to a string of
  2078. length 8, representing the hexadecimal value of the pointer.
  2079. \item[S] String format. The next argument in the \var{Args} array must be
  2080. a string. The argument is simply copied to the result string. If
  2081. \var{Precision} is specified, then only \var{Precision} characters are
  2082. copied to the result string.
  2083. \item[X] hexadecimal format. The next argument in the \var{Args} array must
  2084. be an integer. The argument is converted to a hexadecimal string with just
  2085. enough characters to contain the value of the integer. If \var{Precision}
  2086. is specified then the resulting hexadecimal representation will have at
  2087. least \var{Precision} characters in it (with a maximum value of 32).
  2088. \end{description}
  2089. \Errors
  2090. In case of error, an \var{EConversionError} exception is raised. Possible
  2091. errors are:
  2092. \begin{enumerate}
  2093. \item Errors in the format specifiers.
  2094. \item The next argument is not of the type needed by a specifier.
  2095. \item The number of arguments is not sufficient for all format specifiers.
  2096. \end{enumerate}
  2097. \SeeAlso
  2098. \seef{FormatBuf}
  2099. \end{function}
  2100. \latex{\lstinputlisting{sysutex/ex71.pp}}
  2101. \html{\input{sysutex/ex71.tex}}
  2102. \begin{function}{FormatBuf}
  2103. \Declaration
  2104. Function FormatBuf(Var Buffer; BufLen : Cardinal; Const Fmt; fmtLen : Cardinal; Const Args : Array of const) : Cardinal;
  2105. \Description
  2106. \var{Format}
  2107. \Errors
  2108. \SeeAlso
  2109. \end{function}
  2110. \latex{\lstinputlisting{sysutex/ex72.pp}}
  2111. \html{\input{sysutex/ex72.tex}}
  2112. \begin{function}{IntToHex}
  2113. \Declaration
  2114. Function IntToHex(Value: integer; Digits: integer): string;
  2115. \Description
  2116. \var{IntToHex} converts \var{Value} to a hexadecimal string
  2117. representation. The result will contain at least \var{Digits}
  2118. characters. If \var{Digits} is less than the needed number of characters,
  2119. the string will NOT be truncated. If \var{Digits} is larger than the needed
  2120. number of characters, the result is padded with zeroes.
  2121. \Errors
  2122. None.
  2123. \SeeAlso
  2124. \seef{IntToStr}, \var{StrToInt}
  2125. \end{function}
  2126. \latex{\lstinputlisting{sysutex/ex73.pp}}
  2127. \html{\input{sysutex/ex73.tex}}
  2128. \begin{function}{IntToStr}
  2129. \Declaration
  2130. Function IntToStr(Value: integer): string;
  2131. \Description
  2132. \var{IntToStr} coverts \var{Value} to it's string representation.
  2133. The resulting string has only as much characters as needed to represent
  2134. the value. If the value is negative a minus sign is prepended to the
  2135. string.
  2136. \Errors
  2137. None.
  2138. \SeeAlso
  2139. \seef{IntToHex}, \seef{StrToInt}
  2140. \end{function}
  2141. \latex{\lstinputlisting{sysutex/ex74.pp}}
  2142. \html{\input{sysutex/ex74.tex}}
  2143. \begin{function}{IsValidIdent}
  2144. \Declaration
  2145. Function IsValidIdent(const Ident: string): boolean;
  2146. \Description
  2147. \var{IsValidIdent} returns \var{True} if \var{Ident} can be used as a
  2148. compoent name. It returns \var{False} otherwise. \var{Ident} must consist of
  2149. a letter or underscore, followed by a combination of letters, numbers or
  2150. underscores to be a valid identifier.
  2151. \Errors
  2152. None.
  2153. \SeeAlso
  2154. \end{function}
  2155. \latex{\lstinputlisting{sysutex/ex75.pp}}
  2156. \html{\input{sysutex/ex75.tex}}
  2157. \begin{function}{LeftStr}
  2158. \Declaration
  2159. Function LeftStr(const S: string; Count: integer): string;
  2160. \Description
  2161. \var{LeftStr} returns the \var{Count} leftmost characters of \var{S}.
  2162. It is equivalent to a call to \var{Copy(S,1,Count)}.
  2163. \Errors
  2164. None.
  2165. \SeeAlso
  2166. \seef{RightStr}, \seef{TrimLeft}, \seef{TrimRight}, \seef{Trim}
  2167. \end{function}
  2168. \latex{\lstinputlisting{sysutex/ex76.pp}}
  2169. \html{\input{sysutex/ex76.tex}}
  2170. \begin{function}{LoadStr}
  2171. \Declaration
  2172. Function LoadStr(Ident: integer): string;
  2173. \Description
  2174. This function is not yet implemented. resources are not yet supported.
  2175. \Errors
  2176. \SeeAlso
  2177. \end{function}
  2178. \begin{function}{LowerCase}
  2179. \Declaration
  2180. Function LowerCase(const s: string): string;
  2181. \Description
  2182. \var{LowerCase} returns the lowercase equivalent of \var{S}. Ansi characters
  2183. are not taken into account, only ASCII codes below 127 are converted. It is
  2184. completely equivalent to the lowercase function of the system unit, and is
  2185. provided for compatiibility only.
  2186. \Errors
  2187. None.
  2188. \SeeAlso
  2189. \seef{AnsiLowerCase}, \seef{UpperCase}, \seef{AnsiUpperCase}
  2190. \end{function}
  2191. \latex{\lstinputlisting{sysutex/ex77.pp}}
  2192. \html{\input{sysutex/ex77.tex}}
  2193. \begin{functionl}{NewStr}{NewStrSys}
  2194. \Declaration
  2195. Function NewStr(const S: string): PString;
  2196. \Description
  2197. \var{NewStr} assigns a new dynamic string on the heap, copies \var{S} into
  2198. it, and returns a pointer to the newly assigned string.
  2199. This function is obsolete, and shouldn't be used any more. The
  2200. \var{AnsiString} mechanism also allocates ansistrings on the heap, and
  2201. should be preferred over this mechanism.
  2202. \Errors
  2203. If not enough memory is present, an EOutOfMemory exception will be raised.
  2204. \SeeAlso
  2205. \seep{AssignStr}, \seepl{DisposeStr}{DisposeStrSys}
  2206. \end{functionl}
  2207. For an example, see \seep{AssignStr}.
  2208. \begin{function}{QuotedStr}
  2209. \Declaration
  2210. Function QuotedStr(const S: string): string;
  2211. \Description
  2212. \var{QuotedStr} returns the string \var{S}, quoted with single quotes. This means
  2213. that \var{S} is enclosed in single quotes, and every single quote in \var{S}
  2214. is doubled. It is equivalent to a call to \var{AnsiQuotedStr(s, '''')}.
  2215. \Errors
  2216. None.
  2217. \SeeAlso
  2218. \seef{AnsiQuotedStr}, \seef{AnsiExtractQuotedStr}.
  2219. \end{function}
  2220. \latex{\lstinputlisting{sysutex/ex78.pp}}
  2221. \html{\input{sysutex/ex78.tex}}
  2222. \begin{function}{RightStr}
  2223. \Declaration
  2224. Function RightStr(const S: string; Count: integer): string;
  2225. \Description
  2226. \var{RightStr} returns the \var{Count} rightmost characters of \var{S}.
  2227. It is equivalent to a call to \var{Copy(S,Length(S)+1-Count,Count)}.
  2228. If \var{Count} is larger than the actual length of \var{S} only the real
  2229. length will be used.
  2230. \Errors
  2231. None.
  2232. \SeeAlso
  2233. \seef{LeftStr},\seef{Trim}, \seef{TrimLeft}, \seef{TrimRight}
  2234. \end{function}
  2235. \latex{\lstinputlisting{sysutex/ex79.pp}}
  2236. \html{\input{sysutex/ex79.tex}}
  2237. \begin{function}{StrFmt}
  2238. \Declaration
  2239. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  2240. \Description
  2241. \var{StrFmt} will format \var{fmt} with \var{Args}, as the \seef{Format}
  2242. function does, and it will store the result in \var{Buffer}. The function
  2243. returns \var{Buffer}. \var{Buffer} should point to enough space to contain
  2244. the whole result.
  2245. \Errors
  2246. for a list of errors, see \seef{Format}.
  2247. \SeeAlso
  2248. \seef{StrLFmt}, \seep{FmtStr}, \seef{Format}, \seef{FormatBuf}
  2249. \end{function}
  2250. \latex{\lstinputlisting{sysutex/ex80.pp}}
  2251. \html{\input{sysutex/ex80.tex}}
  2252. \begin{function}{StrLFmt}
  2253. \Declaration
  2254. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  2255. \Description
  2256. \var{StrLFmt} will format \var{fmt} with \var{Args}, as the \seef{Format}
  2257. function does, and it will store maximally \var{Maxlen characters} of the
  2258. result in \var{Buffer}. The function returns \var{Buffer}. \var{Buffer}
  2259. should point to enough space to contain \var{MaxLen} characters.
  2260. \Errors
  2261. for a list of errors, see \seef{Format}.
  2262. \SeeAlso
  2263. \seef{StrFmt}, \seep{FmtStr}, \seef{Format}, \seef{FormatBuf}
  2264. \end{function}
  2265. \latex{\lstinputlisting{sysutex/ex81.pp}}
  2266. \html{\input{sysutex/ex81.tex}}
  2267. \begin{function}{StrToInt}
  2268. \Declaration
  2269. Function StrToInt(const s: string): integer;
  2270. \Description
  2271. \var{StrToInt} will convert the string \var{S}to an integer.
  2272. If the string contains invalid characters or has an invalid format,
  2273. then an \var{EConvertError} is raised.
  2274. To be successfully converted, a string can contain a combination
  2275. of \var{numerical} characters, possibly preceded by a minus sign (\var{-}).
  2276. Spaces are not allowed.
  2277. \Errors
  2278. In case of error, an \var{EConvertError} is raised.
  2279. \SeeAlso
  2280. \seef{IntToStr}, \seef{StrToIntDef}
  2281. \end{function}
  2282. \latex{\lstinputlisting{sysutex/ex82.pp}}
  2283. \html{\input{sysutex/ex82.tex}}
  2284. \begin{function}{StrToIntDef}
  2285. \Declaration
  2286. Function StrToIntDef(const S: string; Default: integer): integer;
  2287. \Description
  2288. \var{StrToIntDef} will convert a string to an integer. If the string contains
  2289. invalid characters or has an invalid format, then \var{Default} is returned.
  2290. To be successfully converted, a string can contain a combination of
  2291. \var{numerical} characters, possibly preceded by a minus sign (\var{-}).
  2292. Spaces are not allowed.
  2293. \Errors
  2294. None.
  2295. \SeeAlso
  2296. \seef{IntToStr}, \seef{StrToInt}
  2297. \end{function}
  2298. \latex{\lstinputlisting{sysutex/ex83.pp}}
  2299. \html{\input{sysutex/ex83.tex}}
  2300. \begin{function}{Trim}
  2301. \Declaration
  2302. Function Trim(const S: string): string;
  2303. \Description
  2304. \var{Trim} strips blank characters (spaces) at the beginning and end of \var{S}
  2305. and returns the resulting string. Only \var{\#32} characters are stripped.
  2306. If the string contains only spaces, an empty string is returned.
  2307. \Errors
  2308. None.
  2309. \SeeAlso
  2310. \seef{TrimLeft}, \seef{TrimRight}
  2311. \end{function}
  2312. \latex{\lstinputlisting{sysutex/ex84.pp}}
  2313. \html{\input{sysutex/ex84.tex}}
  2314. \begin{function}{TrimLeft}
  2315. \Declaration
  2316. Function TrimLeft(const S: string): string;
  2317. \Description
  2318. \var{TrimLeft} strips blank characters (spaces) at the beginning of \var{S}
  2319. and returns the resulting string. Only \var{\#32} characters are stripped.
  2320. If the string contains only spaces, an empty string is returned.
  2321. \Errors
  2322. None.
  2323. \SeeAlso
  2324. \seef{Trim}, \seef{TrimRight}
  2325. \end{function}
  2326. \latex{\lstinputlisting{sysutex/ex85.pp}}
  2327. \html{\input{sysutex/ex85.tex}}
  2328. \begin{function}{TrimRight}
  2329. \Declaration
  2330. Function TrimRight(const S: string): string;
  2331. \Description
  2332. \var{Trim} strips blank characters (spaces) at the end of \var{S}
  2333. and returns the resulting string. Only \var{\#32} characters are stripped.
  2334. If the string contains only spaces, an empty string is returned.
  2335. \Errors
  2336. None.
  2337. \SeeAlso
  2338. \seef{Trim}, \seef{TrimLeft}
  2339. \end{function}
  2340. \latex{\lstinputlisting{sysutex/ex86.pp}}
  2341. \html{\input{sysutex/ex86.tex}}
  2342. \begin{function}{UpperCase}
  2343. \Declaration
  2344. Function UpperCase(const s: string): string;
  2345. \Description
  2346. \var{UpperCase} returns the uppercase equivalent of \var{S}. Ansi characters
  2347. are not taken into account, only ASCII codes below 127 are converted. It is
  2348. completely equivalent to the \var{UpCase} function of the system unit, and is
  2349. provided for compatiibility only.
  2350. \Errors
  2351. None.
  2352. \SeeAlso
  2353. \seef{AnsiLowerCase}, \seef{LowerCase}, \seef{AnsiUpperCase}
  2354. \Errors
  2355. \SeeAlso
  2356. \end{function}
  2357. \latex{\lstinputlisting{sysutex/ex87.pp}}
  2358. \html{\input{sysutex/ex87.tex}}