sysutils.tex 86 KB

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