sysutils.tex 83 KB

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