sysutils.tex 86 KB

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