sysstr.inc 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. { NewStr creates a new PString and assigns S to it
  20. if length(s) = 0 NewStr returns Nil }
  21. function NewStr(const S: string): PString;
  22. begin
  23. if (S='') then
  24. Result:=nil
  25. else
  26. begin
  27. getmem(Result,length(s)+1);
  28. if (Result<>nil) then
  29. Result^:=s;
  30. end;
  31. end;
  32. { DisposeStr frees the memory occupied by S }
  33. procedure DisposeStr(S: PString);
  34. begin
  35. if S <> Nil then
  36. begin
  37. Freemem(S,Length(S^)+1);
  38. S:=nil;
  39. end;
  40. end;
  41. { AssignStr assigns S to P^ }
  42. procedure AssignStr(var P: PString; const S: string);
  43. begin
  44. P^ := s;
  45. end ;
  46. { AppendStr appends S to Dest }
  47. procedure AppendStr(var Dest: String; const S: string);
  48. begin
  49. Dest := Dest + S;
  50. end ;
  51. { UpperCase returns a copy of S where all lowercase characters ( from a to z )
  52. have been converted to uppercase }
  53. function UpperCase(const S: string): string;
  54. var i: integer;
  55. begin
  56. result := S;
  57. i := Length(S);
  58. while i <> 0 do begin
  59. if (result[i] in ['a'..'z']) then result[i] := char(byte(result[i]) - 32);
  60. Dec(i);
  61. end;
  62. end;
  63. { LowerCase returns a copy of S where all uppercase characters ( from A to Z )
  64. have been converted to lowercase }
  65. function LowerCase(const S: string): string;
  66. var i: integer;
  67. begin
  68. result := S;
  69. i := Length(result);
  70. while i <> 0 do begin
  71. if (result[i] in ['A'..'Z']) then result[i] := char(byte(result[i]) + 32);
  72. dec(i);
  73. end;
  74. end;
  75. { CompareStr compares S1 and S2, the result is the based on
  76. substraction of the ascii values of the characters in S1 and S2
  77. case result
  78. S1 < S2 < 0
  79. S1 > S2 > 0
  80. S1 = S2 = 0 }
  81. function CompareStr(const S1, S2: string): Integer;
  82. var count, count1, count2: integer;
  83. begin
  84. result := 0;
  85. Count1 := Length(S1);
  86. Count2 := Length(S2);
  87. if Count1>Count2 then
  88. Count:=Count2
  89. else
  90. Count:=Count1;
  91. result := CompareMemRange(Pointer(S1),Pointer(S2), Count);
  92. if (result=0) and (Count1<>Count2) then
  93. begin
  94. if Count1>Count2 then
  95. result:=ord(s1[Count+1])
  96. else
  97. result:=-ord(s2[Count+1]);
  98. end;
  99. end;
  100. { CompareMemRange returns the result of comparison of Length bytes at P1 and P2
  101. case result
  102. P1 < P2 < 0
  103. P1 > P2 > 0
  104. P1 = P2 = 0 }
  105. function CompareMemRange(P1, P2: Pointer; Length: cardinal): integer;
  106. var
  107. i: cardinal;
  108. begin
  109. i := 0;
  110. result := 0;
  111. while (result=0) and (I<length) do
  112. begin
  113. result:=byte(P1^)-byte(P2^);
  114. P1:=pchar(P1)+1; // VP compat.
  115. P2:=pchar(P2)+1;
  116. i := i + 1;
  117. end ;
  118. end ;
  119. function CompareMem(P1, P2: Pointer; Length: cardinal): Boolean;
  120. var
  121. i: cardinal;
  122. begin
  123. for i := 0 to Length - 1 do
  124. begin
  125. if Byte(P1^) <> Byte(P2^) then
  126. begin
  127. Result := False;
  128. exit;
  129. end;
  130. Inc(pchar(P1));
  131. Inc(pchar(P2));
  132. end;
  133. Result := True;
  134. end;
  135. { CompareText compares S1 and S2, the result is the based on
  136. substraction of the ascii values of characters in S1 and S2
  137. comparison is case-insensitive
  138. case result
  139. S1 < S2 < 0
  140. S1 > S2 > 0
  141. S1 = S2 = 0 }
  142. function CompareText(const S1, S2: string): integer;
  143. var
  144. i, count, count1, count2: integer; Chr1, Chr2: byte;
  145. begin
  146. result := 0;
  147. Count1 := Length(S1);
  148. Count2 := Length(S2);
  149. if (Count1>Count2) then
  150. Count := Count2
  151. else
  152. Count := Count1;
  153. i := 0;
  154. while (result=0) and (i<count) do
  155. begin
  156. inc (i);
  157. Chr1 := byte(s1[i]);
  158. Chr2 := byte(s2[i]);
  159. if Chr1 in [97..122] then
  160. dec(Chr1,32);
  161. if Chr2 in [97..122] then
  162. dec(Chr2,32);
  163. result := Chr1 - Chr2;
  164. end ;
  165. if (result = 0) then
  166. result:=(count1-count2);
  167. end;
  168. function SameText(const s1,s2:String):Boolean;
  169. begin
  170. Result:=CompareText(S1,S2)=0;
  171. end;
  172. {==============================================================================}
  173. { Ansi string functions }
  174. { these functions rely on the character set loaded by the OS }
  175. {==============================================================================}
  176. function AnsiUpperCase(const s: string): string;
  177. var len, i: integer;
  178. begin
  179. len := length(s);
  180. SetLength(result, len);
  181. for i := 1 to len do
  182. result[i] := UpperCaseTable[ord(s[i])];
  183. end ;
  184. function AnsiLowerCase(const s: string): string;
  185. var len, i: integer;
  186. begin
  187. len := length(s);
  188. SetLength(result, len);
  189. for i := 1 to len do
  190. result[i] := LowerCaseTable[ord(s[i])];
  191. end ;
  192. function AnsiCompareStr(const S1, S2: string): integer;
  193. Var I,L1,L2 : Longint;
  194. begin
  195. Result:=0;
  196. L1:=Length(S1);
  197. L2:=Length(S2);
  198. I:=1;
  199. While (Result=0) and ((I<=L1) and (I<=L2)) do
  200. begin
  201. Result:=Ord(S1[I])-Ord(S2[I]); //!! Must be replaced by ansi characters !!
  202. Inc(I);
  203. end;
  204. If Result=0 Then
  205. Result:=L1-L2;
  206. end;
  207. function AnsiCompareText(const S1, S2: string): integer;
  208. Var I,L1,L2 : Longint;
  209. begin
  210. Result:=0;
  211. L1:=Length(S1);
  212. L2:=Length(S2);
  213. I:=1;
  214. While (Result=0) and ((I<=L1) and (I<=L2)) do
  215. begin
  216. Result:=Ord(LowerCaseTable[Ord(S1[I])])-Ord(LowerCaseTable[Ord(S2[I])]); //!! Must be replaced by ansi characters !!
  217. Inc(I);
  218. end;
  219. If Result=0 Then
  220. Result:=L1-L2;
  221. end;
  222. function AnsiSameText(const s1,s2:String):Boolean;
  223. begin
  224. AnsiSameText:=AnsiCompareText(S1,S2)=0;
  225. end;
  226. function AnsiStrComp(S1, S2: PChar): integer;
  227. begin
  228. Result:=0;
  229. If S1=Nil then
  230. begin
  231. If S2=Nil Then Exit;
  232. result:=-1;
  233. exit;
  234. end;
  235. If S2=Nil then
  236. begin
  237. Result:=1;
  238. exit;
  239. end;
  240. Repeat
  241. Result:=Ord(S1[0])-Ord(S2[0]); //!! Must be replaced by ansi characters !!
  242. Inc(S1);
  243. Inc(S2);
  244. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0))
  245. end;
  246. function AnsiStrIComp(S1, S2: PChar): integer;
  247. begin
  248. Result:=0;
  249. If S1=Nil then
  250. begin
  251. If S2=Nil Then Exit;
  252. result:=-1;
  253. exit;
  254. end;
  255. If S2=Nil then
  256. begin
  257. Result:=1;
  258. exit;
  259. end;
  260. Repeat
  261. Result:=Ord(LowerCaseTable[Ord(S1[0])])-Ord(LowerCaseTable[Ord(S2[0])]); //!! Must be replaced by ansi characters !!
  262. Inc(S1);
  263. Inc(S2);
  264. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0))
  265. end;
  266. function AnsiStrLComp(S1, S2: PChar; MaxLen: cardinal): integer;
  267. Var I : cardinal;
  268. begin
  269. Result:=0;
  270. If MaxLen=0 then exit;
  271. If S1=Nil then
  272. begin
  273. If S2=Nil Then Exit;
  274. result:=-1;
  275. exit;
  276. end;
  277. If S2=Nil then
  278. begin
  279. Result:=1;
  280. exit;
  281. end;
  282. I:=0;
  283. Repeat
  284. Result:=Ord(S1[0])-Ord(S2[0]); //!! Must be replaced by ansi characters !!
  285. Inc(S1);
  286. Inc(S2);
  287. Inc(I);
  288. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0)) or (I=MaxLen)
  289. end ;
  290. function AnsiStrLIComp(S1, S2: PChar; MaxLen: cardinal): integer;
  291. Var I : cardinal;
  292. begin
  293. Result:=0;
  294. If MaxLen=0 then exit;
  295. If S1=Nil then
  296. begin
  297. If S2=Nil Then Exit;
  298. result:=-1;
  299. exit;
  300. end;
  301. If S2=Nil then
  302. begin
  303. Result:=1;
  304. exit;
  305. end;
  306. I:=0;
  307. Repeat
  308. Result:=Ord(LowerCaseTable[Ord(S1[0])])-Ord(LowerCaseTable[Ord(S2[0])]); //!! Must be replaced by ansi characters !!
  309. Inc(S1);
  310. Inc(S2);
  311. Inc(I);
  312. Until (Result<>0) or ((S1[0]=#0) or (S2[0]=#0)) or (I=MaxLen)
  313. end ;
  314. function AnsiStrLower(Str: PChar): PChar;
  315. begin
  316. result := Str;
  317. if Str <> Nil then begin
  318. while Str^ <> #0 do begin
  319. Str^ := LowerCaseTable[byte(Str^)];
  320. Str := Str + 1;
  321. end ;
  322. end ;
  323. end ;
  324. function AnsiStrUpper(Str: PChar): PChar;
  325. begin
  326. result := Str;
  327. if Str <> Nil then begin
  328. while Str^ <> #0 do begin
  329. Str^ := UpperCaseTable[byte(Str^)];
  330. Str := Str + 1;
  331. end ;
  332. end ;
  333. end ;
  334. function AnsiLastChar(const S: string): PChar;
  335. begin
  336. //!! No multibyte yet, so we return the last one.
  337. result:=StrEnd(Pchar(S));
  338. Dec(Result);
  339. end ;
  340. function AnsiStrLastChar(Str: PChar): PChar;
  341. begin
  342. //!! No multibyte yet, so we return the last one.
  343. result:=StrEnd(Str);
  344. Dec(Result);
  345. end ;
  346. {==============================================================================}
  347. { End of Ansi functions }
  348. {==============================================================================}
  349. { Trim returns a copy of S with blanks characters on the left and right stripped off }
  350. Const WhiteSpace = [' ',#10,#13,#9];
  351. function Trim(const S: string): string;
  352. var Ofs, Len: integer;
  353. begin
  354. len := Length(S);
  355. while (Len>0) and (S[Len] in WhiteSpace) do
  356. dec(Len);
  357. Ofs := 1;
  358. while (Ofs<=Len) and (S[Ofs] in WhiteSpace) do
  359. Inc(Ofs);
  360. result := Copy(S, Ofs, 1 + Len - Ofs);
  361. end ;
  362. { TrimLeft returns a copy of S with all blank characters on the left stripped off }
  363. function TrimLeft(const S: string): string;
  364. var i,l:integer;
  365. begin
  366. l := length(s);
  367. i := 1;
  368. while (i<=l) and (s[i] in whitespace) do
  369. inc(i);
  370. Result := copy(s, i, l);
  371. end ;
  372. { TrimRight returns a copy of S with all blank characters on the right stripped off }
  373. function TrimRight(const S: string): string;
  374. var l:integer;
  375. begin
  376. l := length(s);
  377. while (l>0) and (s[l] in whitespace) do
  378. dec(l);
  379. result := copy(s,1,l);
  380. end ;
  381. { QuotedStr returns S quoted left and right and every single quote in S
  382. replaced by two quotes }
  383. function QuotedStr(const S: string): string;
  384. begin
  385. result := AnsiQuotedStr(s, '''');
  386. end ;
  387. { AnsiQuotedStr returns S quoted left and right by Quote,
  388. and every single occurance of Quote replaced by two }
  389. function AnsiQuotedStr(const S: string; Quote: char): string;
  390. var i, j, count: integer;
  391. begin
  392. result := '' + Quote;
  393. count := length(s);
  394. i := 0;
  395. j := 0;
  396. while i < count do begin
  397. i := i + 1;
  398. if S[i] = Quote then begin
  399. result := result + copy(S, 1 + j, i - j) + Quote;
  400. j := i;
  401. end ;
  402. end ;
  403. if i <> j then
  404. result := result + copy(S, 1 + j, i - j);
  405. result := result + Quote;
  406. end ;
  407. { AnsiExtractQuotedStr returns a copy of Src with quote characters
  408. deleted to the left and right and double occurances
  409. of Quote replaced by a single Quote }
  410. function AnsiExtractQuotedStr(Const Src: PChar; Quote: Char): string;
  411. var i: integer; P, Q: PChar;
  412. begin
  413. P := Src;
  414. if Src^ = Quote then P := P + 1;
  415. Q := StrEnd(P);
  416. if PChar(Q - 1)^ = Quote then Q := Q - 1;
  417. SetLength(result, Q - P);
  418. i := 0;
  419. while P <> Q do begin
  420. i := i + 1;
  421. result[i] := P^;
  422. if (P^ = Quote) and (PChar(P + 1)^ = Quote) then
  423. P := P + 1;
  424. P := P + 1;
  425. end ;
  426. SetLength(result, i);
  427. end ;
  428. { AdjustLineBreaks returns S with all CR characters not followed by LF
  429. replaced with CR/LF }
  430. // under Linux all CR characters or CR/LF combinations should be replaced with LF
  431. function AdjustLineBreaks(const S: string): string;
  432. var i, j, count: integer;
  433. begin
  434. result := '';
  435. i := 0;
  436. j := 0;
  437. count := Length(S);
  438. while i < count do begin
  439. i := i + 1;
  440. {$ifndef Unix}
  441. if (S[i] = #13) and ((i = count) or (S[i + 1] <> #10)) then
  442. begin
  443. result := result + Copy(S, 1 + j, i - j) + #10;
  444. j := i;
  445. end;
  446. {$else}
  447. If S[i]=#13 then
  448. begin
  449. Result:= Result+Copy(S,J+1,i-j-1)+#10;
  450. If I<>Count Then
  451. If S[I+1]=#10 then inc(i);
  452. J :=I;
  453. end;
  454. {$endif}
  455. end ;
  456. if j <> i then
  457. result := result + copy(S, 1 + j, i - j);
  458. end ;
  459. { IsValidIdent returns true if the first character of Ident is in:
  460. 'A' to 'Z', 'a' to 'z' or '_' and the following characters are
  461. on of: 'A' to 'Z', 'a' to 'z', '0'..'9' or '_' }
  462. function IsValidIdent(const Ident: string): boolean;
  463. var i, len: integer;
  464. begin
  465. result := false;
  466. len := length(Ident);
  467. if len <> 0 then begin
  468. result := Ident[1] in ['A'..'Z', 'a'..'z', '_'];
  469. i := 1;
  470. while (result) and (i < len) do begin
  471. i := i + 1;
  472. result := result and (Ident[i] in ['A'..'Z', 'a'..'z', '0'..'9', '_']);
  473. end ;
  474. end ;
  475. end ;
  476. { IntToStr returns a string representing the value of Value }
  477. function IntToStr(Value: integer): string;
  478. begin
  479. System.Str(Value, result);
  480. end ;
  481. {$IFNDEF VIRTUALPASCAL}
  482. function IntToStr(Value: int64): string;
  483. begin
  484. System.Str(Value, result);
  485. end ;
  486. {$ENDIF}
  487. function IntToStr(Value: QWord): string;
  488. begin
  489. System.Str(Value, result);
  490. end ;
  491. { IntToHex returns a string representing the hexadecimal value of Value }
  492. const
  493. HexDigits: array[0..15] of char = '0123456789ABCDEF';
  494. function IntToHex(Value: integer; Digits: integer): string;
  495. var i: integer;
  496. begin
  497. SetLength(result, digits);
  498. for i := 0 to digits - 1 do
  499. begin
  500. result[digits - i] := HexDigits[value and 15];
  501. value := value shr 4;
  502. end ;
  503. end ;
  504. {$IFNDEF VIRTUALPASCAL} // overloading
  505. function IntToHex(Value: int64; Digits: integer): string;
  506. var i: integer;
  507. begin
  508. SetLength(result, digits);
  509. for i := 0 to digits - 1 do
  510. begin
  511. result[digits - i] := HexDigits[value and 15];
  512. value := value shr 4;
  513. end ;
  514. end ;
  515. {$ENDIF}
  516. { StrToInt converts the string S to an integer value,
  517. if S does not represent a valid integer value EConvertError is raised }
  518. function StrToInt(const S: string): integer;
  519. {$IFDEF VIRTUALPASCAL}
  520. var Error: longint;
  521. {$ELSE}
  522. var Error: word;
  523. {$ENDIF}
  524. begin
  525. Val(S, result, Error);
  526. if Error <> 0 then raise EConvertError.createfmt(SInValidInteger,[S]);
  527. end ;
  528. function StrToInt64(const S: string): int64;
  529. {$IFDEF VIRTUALPASCAL}
  530. var Error: longint;
  531. {$ELSE}
  532. var Error: word;
  533. {$ENDIF}
  534. begin
  535. Val(S, result, Error);
  536. if Error <> 0 then raise EConvertError.createfmt(SInValidInteger,[S]);
  537. end ;
  538. { StrToIntDef converts the string S to an integer value,
  539. Default is returned in case S does not represent a valid integer value }
  540. function StrToIntDef(const S: string; Default: integer): integer;
  541. {$IFDEF VIRTUALPASCAL}
  542. var Error: longint;
  543. {$ELSE}
  544. var Error: word;
  545. {$ENDIF}
  546. begin
  547. Val(S, result, Error);
  548. if Error <> 0 then result := Default;
  549. end ;
  550. { StrToIntDef converts the string S to an integer value,
  551. Default is returned in case S does not represent a valid integer value }
  552. function StrToInt64Def(const S: string; Default: int64): int64;
  553. {$IFDEF VIRTUALPASCAL}
  554. var Error: longint;
  555. {$ELSE}
  556. var Error: word;
  557. {$ENDIF}
  558. begin
  559. Val(S, result, Error);
  560. if Error <> 0 then result := Default;
  561. end ;
  562. { LoadStr returns the string resource Ident. }
  563. function LoadStr(Ident: integer): string;
  564. begin
  565. result:='';
  566. end ;
  567. { FmtLoadStr returns the string resource Ident and formats it accordingly }
  568. function FmtLoadStr(Ident: integer; const Args: array of const): string;
  569. begin
  570. result:='';
  571. end;
  572. Const
  573. feInvalidFormat = 1;
  574. feMissingArgument = 2;
  575. feInvalidArgIndex = 3;
  576. {$ifdef fmtdebug}
  577. Procedure Log (Const S: String);
  578. begin
  579. Writeln (S);
  580. end;
  581. {$endif}
  582. Procedure DoFormatError (ErrCode : Longint);
  583. Var
  584. S : String;
  585. begin
  586. //!! must be changed to contain format string...
  587. S:='';
  588. Case ErrCode of
  589. feInvalidFormat : raise EConvertError.Createfmt(SInvalidFormat,[s]);
  590. feMissingArgument : raise EConvertError.Createfmt(SArgumentMissing,[s]);
  591. feInvalidArgIndex : raise EConvertError.Createfmt(SInvalidArgIndex,[s]);
  592. end;
  593. end;
  594. Function Format (Const Fmt : String; const Args : Array of const) : String;
  595. Var ChPos,OldPos,ArgPos,DoArg,Len : Longint;
  596. Hs,ToAdd : String;
  597. Index,Width,Prec : Longint;
  598. Left : Boolean;
  599. Fchar : char;
  600. {
  601. ReadFormat reads the format string. It returns the type character in
  602. uppercase, and sets index, Width, Prec to their correct values,
  603. or -1 if not set. It sets Left to true if left alignment was requested.
  604. In case of an error, DoFormatError is called.
  605. }
  606. Function ReadFormat : Char;
  607. Var Value : longint;
  608. Procedure ReadInteger;
  609. {$IFDEF VIRTUALPASCAL}
  610. var Code: longint;
  611. {$ELSE}
  612. var Code: word;
  613. {$ENDIF}
  614. begin
  615. If Value<>-1 then exit; // Was already read.
  616. OldPos:=chPos;
  617. While (Chpos<=Len) and
  618. (Pos(Fmt[chpos],'1234567890')<>0) do inc(chpos);
  619. If Chpos>len then
  620. DoFormatError(feInvalidFormat);
  621. If Fmt[Chpos]='*' then
  622. begin
  623. If (Chpos>OldPos) or (ArgPos>High(Args))
  624. or (Args[ArgPos].Vtype<>vtInteger) then
  625. DoFormatError(feInvalidFormat);
  626. Value:=Args[ArgPos].VInteger;
  627. Inc(ArgPos);
  628. Inc(chPos);
  629. end
  630. else
  631. begin
  632. If (OldPos<chPos) Then
  633. begin
  634. Val (Copy(Fmt,OldPos,ChPos-OldPos),value,code);
  635. // This should never happen !!
  636. If Code>0 then DoFormatError (feInvalidFormat);
  637. end
  638. else
  639. Value:=-1;
  640. end;
  641. end;
  642. Procedure ReadIndex;
  643. begin
  644. ReadInteger;
  645. If Fmt[ChPos]=':' then
  646. begin
  647. If Value=-1 then DoFormatError(feMissingArgument);
  648. Index:=Value;
  649. Value:=-1;
  650. Inc(Chpos);
  651. end;
  652. {$ifdef fmtdebug}
  653. Log ('Read index');
  654. {$endif}
  655. end;
  656. Procedure ReadLeft;
  657. begin
  658. If Fmt[chpos]='-' then
  659. begin
  660. left:=True;
  661. Inc(chpos);
  662. end
  663. else
  664. Left:=False;
  665. {$ifdef fmtdebug}
  666. Log ('Read Left');
  667. {$endif}
  668. end;
  669. Procedure ReadWidth;
  670. begin
  671. ReadInteger;
  672. If Value<>-1 then
  673. begin
  674. Width:=Value;
  675. Value:=-1;
  676. end;
  677. {$ifdef fmtdebug}
  678. Log ('Read width');
  679. {$endif}
  680. end;
  681. Procedure ReadPrec;
  682. begin
  683. If Fmt[chpos]='.' then
  684. begin
  685. inc(chpos);
  686. ReadInteger;
  687. If Value=-1 then
  688. Value:=0;
  689. prec:=Value;
  690. end;
  691. {$ifdef fmtdebug}
  692. Log ('Read precision');
  693. {$endif}
  694. end;
  695. begin
  696. {$ifdef fmtdebug}
  697. Log ('Start format');
  698. {$endif}
  699. Index:=-1;
  700. Width:=-1;
  701. Prec:=-1;
  702. Value:=-1;
  703. inc(chpos);
  704. If Fmt[Chpos]='%' then
  705. begin
  706. Result:='%';
  707. exit; // VP fix
  708. end;
  709. ReadIndex;
  710. ReadLeft;
  711. ReadWidth;
  712. ReadPrec;
  713. ReadFormat:=Upcase(Fmt[ChPos]);
  714. {$ifdef fmtdebug}
  715. Log ('End format');
  716. {$endif}
  717. end;
  718. {$ifdef fmtdebug}
  719. Procedure DumpFormat (C : char);
  720. begin
  721. Write ('Fmt : ',fmt:10);
  722. Write (' Index : ',Index:3);
  723. Write (' Left : ',left:5);
  724. Write (' Width : ',Width:3);
  725. Write (' Prec : ',prec:3);
  726. Writeln (' Type : ',C);
  727. end;
  728. {$endif}
  729. function Checkarg (AT : Longint;err:boolean):boolean;
  730. {
  731. Check if argument INDEX is of correct type (AT)
  732. If Index=-1, ArgPos is used, and argpos is augmented with 1
  733. DoArg is set to the argument that must be used.
  734. }
  735. begin
  736. result:=false;
  737. if Index=-1 then
  738. begin
  739. DoArg:=Argpos;
  740. inc(ArgPos);
  741. end
  742. else
  743. DoArg:=Index;
  744. If (Doarg>High(Args)) or (Args[Doarg].Vtype<>AT) then
  745. begin
  746. if err then
  747. DoFormatError(feInvalidArgindex);
  748. dec(ArgPos);
  749. exit;
  750. end;
  751. result:=true;
  752. end;
  753. Const Zero = '000000000000000000000000000000000000000000000000000000000000000';
  754. begin
  755. Result:='';
  756. Len:=Length(Fmt);
  757. Chpos:=1;
  758. OldPos:=1;
  759. ArgPos:=0;
  760. While chpos<=len do
  761. begin
  762. While (ChPos<=Len) and (Fmt[chpos]<>'%') do
  763. inc(chpos);
  764. If ChPos>OldPos Then
  765. Result:=Result+Copy(Fmt,OldPos,Chpos-Oldpos);
  766. If ChPos<Len then
  767. begin
  768. FChar:=ReadFormat;
  769. {$ifdef fmtdebug}
  770. DumpFormat(FCHar);
  771. {$endif}
  772. Case FChar of
  773. 'D' : begin
  774. if Checkarg(vtinteger,false) then
  775. Str(Args[Doarg].VInteger,ToAdd)
  776. {$IFNDEF VIRTUALPASCAL}
  777. else if CheckArg(vtInt64,true) then
  778. Str(Args[DoArg].VInt64^,toadd)
  779. {$ENDIF}
  780. ;
  781. Width:=Abs(width);
  782. Index:=Prec-Length(ToAdd);
  783. If ToAdd[1]<>'-' then
  784. ToAdd:=StringOfChar('0',Index)+ToAdd
  785. else
  786. // + 1 to accomodate for - sign in length !!
  787. Insert(StringOfChar('0',Index+1),toadd,2);
  788. end;
  789. 'E' : begin
  790. CheckArg(vtExtended,true);
  791. ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffexponent,Prec,3);
  792. end;
  793. 'F' : begin
  794. CheckArg(vtExtended,true);
  795. ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffFixed,9999,Prec);
  796. end;
  797. 'G' : begin
  798. CheckArg(vtExtended,true);
  799. ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffGeneral,Prec,3);
  800. end;
  801. 'N' : begin
  802. CheckArg(vtExtended,true);
  803. ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffNumber,9999,Prec);
  804. end;
  805. 'M' : begin
  806. CheckArg(vtExtended,true);
  807. ToAdd:=FloatToStrF(Args[doarg].VExtended^,ffCurrency,9999,Prec);
  808. end;
  809. 'S' : begin
  810. if CheckArg(vtString,false) then
  811. hs:=Args[doarg].VString^
  812. else
  813. if CheckArg(vtChar,false) then
  814. hs:=Args[doarg].VChar
  815. else
  816. if CheckArg(vtPChar,false) then
  817. hs:=Args[doarg].VPChar
  818. else
  819. if CheckArg(vtPWideChar,false) then
  820. hs:=char(Args[doarg].VPWideChar^)
  821. else
  822. if CheckArg(vtWideChar,false) then
  823. hs:=char(Args[doarg].VWideChar)
  824. else
  825. if CheckArg(vtWidestring,false) then
  826. hs:=ansistring(Args[doarg].VWideString)
  827. else
  828. if CheckArg(vtAnsiString,true) then
  829. hs:=ansistring(Args[doarg].VAnsiString);
  830. Index:=Length(hs);
  831. If (Prec<>-1) and (Index>Prec) then
  832. Index:=Prec;
  833. ToAdd:=Copy(hs,1,Index);
  834. end;
  835. 'P' : Begin
  836. CheckArg(vtpointer,true);
  837. ToAdd:=HexStr(Longint(Args[DoArg].VPointer),8);
  838. // Insert ':'. Is this needed in 32 bit ? No it isn't.
  839. // Insert(':',ToAdd,5);
  840. end;
  841. 'X' : begin
  842. Checkarg(vtinteger,true);
  843. If Prec>15 then
  844. ToAdd:=HexStr(Args[Doarg].VInteger,15)
  845. else
  846. begin
  847. // determine minimum needed number of hex digits.
  848. Index:=1;
  849. While (DWord(1 shl (Index*4))<=DWord(Args[DoArg].VInteger)) and (index<8) do
  850. inc(Index);
  851. If Index>Prec then
  852. Prec:=Index;
  853. ToAdd:=HexStr(Args[DoArg].VInteger,Prec);
  854. end;
  855. end;
  856. '%': ToAdd:='%';
  857. end;
  858. If Width<>-1 then
  859. If Length(ToAdd)<Width then
  860. If not Left then
  861. ToAdd:=Space(Width-Length(ToAdd))+ToAdd
  862. else
  863. ToAdd:=ToAdd+space(Width-Length(ToAdd));
  864. Result:=Result+ToAdd;
  865. end;
  866. inc(chpos);
  867. Oldpos:=chpos;
  868. end;
  869. end;
  870. Function FormatBuf (Var Buffer; BufLen : Cardinal;
  871. Const Fmt; fmtLen : Cardinal;
  872. Const Args : Array of const) : Cardinal;
  873. Var S,F : String;
  874. begin
  875. Setlength(F,fmtlen);
  876. if fmtlen > 0 then
  877. Move(fmt,F[1],fmtlen);
  878. S:=Format (F,Args);
  879. If Cardinal(Length(S))<Buflen then
  880. Result:=Length(S)
  881. else
  882. Result:=Buflen;
  883. Move(S[1],Buffer,Result);
  884. end;
  885. Procedure FmtStr(Var Res: String; Const Fmt : String; Const args: Array of const);
  886. begin
  887. Res:=Format(fmt,Args);
  888. end;
  889. Function StrFmt(Buffer,Fmt : PChar; Const args: Array of const) : Pchar;
  890. begin
  891. Buffer[FormatBuf(Buffer^,Maxint,Fmt^,strlen(fmt),args)]:=#0;
  892. Result:=Buffer;
  893. end;
  894. Function StrLFmt(Buffer : PCHar; Maxlen : Cardinal;Fmt : PChar; Const args: Array of const) : Pchar;
  895. begin
  896. Buffer[FormatBuf(Buffer^,MaxLen,Fmt^,strlen(fmt),args)]:=#0;
  897. Result:=Buffer;
  898. end;
  899. Function StrToFloat(Const S: String): Extended;
  900. Begin
  901. If Not TextToFloat(Pchar(S),Result) then
  902. Raise EConvertError.createfmt(SInValidFLoat,[S]);
  903. End;
  904. function StrToFloatDef(const S: string; const Default: Extended): Extended;
  905. begin
  906. if not TextToFloat(PChar(S),Result,fvExtended) then
  907. Result:=Default;
  908. end;
  909. Function TextToFloat(Buffer: PChar; Var Value: Extended): Boolean;
  910. Var
  911. E,P : Integer;
  912. S : String;
  913. Begin
  914. S:=StrPas(Buffer);
  915. P:=Pos(DecimalSeparator,S);
  916. If (P<>0) Then
  917. S[P] := '.';
  918. Val(S,Value,E);
  919. Result:=(E=0);
  920. End;
  921. Function TextToFloat(Buffer: PChar; Var Value; ValueType: TFloatValue): Boolean;
  922. Var
  923. E,P : Integer;
  924. S : String;
  925. C : Currency;
  926. Ext : Extended;
  927. Begin
  928. S:=StrPas(Buffer);
  929. P:=Pos(DecimalSeparator,S);
  930. If (P<>0) Then
  931. S[P] := '.';
  932. case ValueType of
  933. fvCurrency:
  934. Val(S,Currency(Value),E);
  935. fvExtended:
  936. Val(S,Extended(Value),E);
  937. fvDouble:
  938. Val(S,Double(Value),E);
  939. fvSingle:
  940. Val(S,Single(Value),E);
  941. fvComp:
  942. Val(S,Comp(Value),E);
  943. fvReal:
  944. Val(S,Real(Value),E);
  945. end;
  946. Result:=(E=0);
  947. End;
  948. Function FloatToStr(Value: Extended): String;
  949. Begin
  950. Result := FloatToStrF(Value, ffGeneral, 15, 0);
  951. End;
  952. Function FloatToText(Buffer: PChar; Value: Extended; format: TFloatFormat; Precision, Digits: Integer): Longint;
  953. Var
  954. Tmp: String[40];
  955. Begin
  956. Tmp := FloatToStrF(Value, format, Precision, Digits);
  957. Result := Length(Tmp);
  958. Move(Tmp[1], Buffer[0], Result);
  959. End;
  960. Function FloatToStrF(Value: Extended; format: TFloatFormat; Precision, Digits: Integer): String;
  961. Var
  962. P: Integer;
  963. Negative, TooSmall, TooLarge: Boolean;
  964. Begin
  965. Case format Of
  966. ffGeneral:
  967. Begin
  968. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  969. TooSmall := (Abs(Value) < 0.00001) and (Value>0.0);
  970. If Not TooSmall Then
  971. Begin
  972. Str(Value:0:999, Result);
  973. P := Pos('.', Result);
  974. Result[P] := DecimalSeparator;
  975. TooLarge := P > Precision + 1;
  976. End;
  977. If TooSmall Or TooLarge Then
  978. begin
  979. Result := FloatToStrF(Value, ffExponent, Precision, Digits);
  980. // Strip unneeded zeroes.
  981. P:=Pos('E',result)-1;
  982. If P<>-1 then
  983. While (P>1) and (Result[P]='0') do
  984. begin
  985. system.Delete(Result,P,1);
  986. Dec(P);
  987. end;
  988. end
  989. else
  990. begin
  991. P := Length(Result);
  992. While Result[P] = '0' Do Dec(P);
  993. If Result[P] = DecimalSeparator Then Dec(P);
  994. SetLength(Result, P);
  995. end;
  996. End;
  997. ffExponent:
  998. Begin
  999. If (Precision = -1) Or (Precision > 15) Then Precision := 15;
  1000. Str(Value:Precision + 8, Result);
  1001. Result[3] := DecimalSeparator;
  1002. P:=4;
  1003. While (P>0) and (Digits < P) And (Result[Precision + 5] = '0') do
  1004. Begin
  1005. If P<>1 then
  1006. system.Delete(Result, Precision + 5, 1)
  1007. else
  1008. system.Delete(Result, Precision + 3, 3);
  1009. Dec(P);
  1010. end;
  1011. If Result[1] = ' ' Then
  1012. System.Delete(Result, 1, 1);
  1013. End;
  1014. ffFixed:
  1015. Begin
  1016. If Digits = -1 Then Digits := 2
  1017. Else If Digits > 15 Then Digits := 15;
  1018. Str(Value:0:Digits, Result);
  1019. If Result[1] = ' ' Then
  1020. System.Delete(Result, 1, 1);
  1021. P := Pos('.', Result);
  1022. If P <> 0 Then Result[P] := DecimalSeparator;
  1023. End;
  1024. ffNumber:
  1025. Begin
  1026. If Digits = -1 Then Digits := 2
  1027. Else If Digits > 15 Then Digits := 15;
  1028. Str(Value:0:Digits, Result);
  1029. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  1030. P := Pos('.', Result);
  1031. If P <> 0 Then
  1032. Result[P] := DecimalSeparator
  1033. else
  1034. P := Length(Result)+1;
  1035. Dec(P, 3);
  1036. While (P > 1) Do
  1037. Begin
  1038. If Result[P - 1] <> '-' Then Insert(ThousandSeparator, Result, P);
  1039. Dec(P, 3);
  1040. End;
  1041. End;
  1042. ffCurrency:
  1043. Begin
  1044. If Value < 0 Then
  1045. Begin
  1046. Negative := True;
  1047. Value := -Value;
  1048. End
  1049. Else Negative := False;
  1050. If Digits = -1 Then Digits := CurrencyDecimals
  1051. Else If Digits > 18 Then Digits := 18;
  1052. Str(Value:0:Digits, Result);
  1053. If Result[1] = ' ' Then System.Delete(Result, 1, 1);
  1054. P := Pos('.', Result);
  1055. If P <> 0 Then Result[P] := DecimalSeparator;
  1056. Dec(P, 3);
  1057. While (P > 1) Do
  1058. Begin
  1059. Insert(ThousandSeparator, Result, P);
  1060. Dec(P, 3);
  1061. End;
  1062. If Not Negative Then
  1063. Begin
  1064. Case CurrencyFormat Of
  1065. 0: Result := CurrencyString + Result;
  1066. 1: Result := Result + CurrencyString;
  1067. 2: Result := CurrencyString + ' ' + Result;
  1068. 3: Result := Result + ' ' + CurrencyString;
  1069. End
  1070. End
  1071. Else
  1072. Begin
  1073. Case NegCurrFormat Of
  1074. 0: Result := '(' + CurrencyString + Result + ')';
  1075. 1: Result := '-' + CurrencyString + Result;
  1076. 2: Result := CurrencyString + '-' + Result;
  1077. 3: Result := CurrencyString + Result + '-';
  1078. 4: Result := '(' + Result + CurrencyString + ')';
  1079. 5: Result := '-' + Result + CurrencyString;
  1080. 6: Result := Result + '-' + CurrencyString;
  1081. 7: Result := Result + CurrencyString + '-';
  1082. 8: Result := '-' + Result + ' ' + CurrencyString;
  1083. 9: Result := '-' + CurrencyString + ' ' + Result;
  1084. 10: Result := CurrencyString + ' ' + Result + '-';
  1085. End;
  1086. End;
  1087. End;
  1088. End;
  1089. End;
  1090. Function FloatToDateTime (Const Value : Extended) : TDateTime;
  1091. begin
  1092. If (Value<MinDateTime) or (Value>MaxDateTime) then
  1093. Raise EConvertError.CreateFmt (SInvalidDateTime,[Value]);
  1094. Result:=Value;
  1095. end;
  1096. Function FloatToCurr (Const Value : Extended) : Currency;
  1097. begin
  1098. end;
  1099. Function CurrToStr(Value: Currency): string;
  1100. begin
  1101. end;
  1102. function StrToCurr(const S: string): Currency;
  1103. begin
  1104. end;
  1105. function StrToBool(const S: string): Boolean;
  1106. Var
  1107. Temp : String;
  1108. D : Double;
  1109. {$IFDEF VIRTUALPASCAL}
  1110. Code: longint;
  1111. {$ELSE}
  1112. Code: word;
  1113. {$ENDIF}
  1114. begin
  1115. Temp:=upcase(S);
  1116. Val(temp,D,code);
  1117. If Code=0 then
  1118. Result:=(D<>0.0)
  1119. else If Temp='TRUE' then
  1120. result:=true
  1121. else if Temp='FALSE' then
  1122. result:=false
  1123. else
  1124. Raise EConvertError.CreateFmt(SInvalidBoolean,[S]);
  1125. end;
  1126. function BoolToStr(B: Boolean): string;
  1127. begin
  1128. If B then
  1129. Result:='TRUE'
  1130. else
  1131. Result:='FALSE';
  1132. end;
  1133. Function FloatToTextFmt(Buffer: PChar; Value: Extended; format: PChar): Integer;
  1134. Var
  1135. Digits: String[40]; { String Of Digits }
  1136. Exponent: String[8]; { Exponent strin }
  1137. FmtStart, FmtStop: PChar; { Start And End Of relevant part }
  1138. { Of format String }
  1139. ExpFmt, ExpSize: Integer; { Type And Length Of }
  1140. { exponential format chosen }
  1141. Placehold: Array[1..4] Of Integer; { Number Of placeholders In All }
  1142. { four Sections }
  1143. thousand: Boolean; { thousand separators? }
  1144. UnexpectedDigits: Integer; { Number Of unexpected Digits that }
  1145. { have To be inserted before the }
  1146. { First placeholder. }
  1147. DigitExponent: Integer; { Exponent Of First digit In }
  1148. { Digits Array. }
  1149. { Find end of format section starting at P. False, if empty }
  1150. Function GetSectionEnd(Var P: PChar): Boolean;
  1151. Var
  1152. C: Char;
  1153. SQ, DQ: Boolean;
  1154. Begin
  1155. Result := False;
  1156. SQ := False;
  1157. DQ := False;
  1158. C := P[0];
  1159. While (C<>#0) And ((C<>';') Or SQ Or DQ) Do
  1160. Begin
  1161. Result := True;
  1162. Case C Of
  1163. #34: If Not SQ Then DQ := Not DQ;
  1164. #39: If Not DQ Then SQ := Not SQ;
  1165. End;
  1166. Inc(P);
  1167. C := P[0];
  1168. End;
  1169. End;
  1170. { Find start and end of format section to apply. If section doesn't exist,
  1171. use section 1. If section 2 is used, the sign of value is ignored. }
  1172. Procedure GetSectionRange(section: Integer);
  1173. Var
  1174. Sec: Array[1..3] Of PChar;
  1175. SecOk: Array[1..3] Of Boolean;
  1176. Begin
  1177. Sec[1] := format;
  1178. SecOk[1] := GetSectionEnd(Sec[1]);
  1179. If section > 1 Then
  1180. Begin
  1181. Sec[2] := Sec[1];
  1182. If Sec[2][0] <> #0 Then
  1183. Inc(Sec[2]);
  1184. SecOk[2] := GetSectionEnd(Sec[2]);
  1185. If section > 2 Then
  1186. Begin
  1187. Sec[3] := Sec[2];
  1188. If Sec[3][0] <> #0 Then
  1189. Inc(Sec[3]);
  1190. SecOk[3] := GetSectionEnd(Sec[3]);
  1191. End;
  1192. End;
  1193. If Not SecOk[1] Then
  1194. FmtStart := Nil
  1195. Else
  1196. Begin
  1197. If Not SecOk[section] Then
  1198. section := 1
  1199. Else If section = 2 Then
  1200. Value := -Value; { Remove sign }
  1201. If section = 1 Then FmtStart := format Else
  1202. Begin
  1203. FmtStart := Sec[section - 1];
  1204. Inc(FmtStart);
  1205. End;
  1206. FmtStop := Sec[section];
  1207. End;
  1208. End;
  1209. { Find format section ranging from FmtStart to FmtStop. }
  1210. Procedure GetFormatOptions;
  1211. Var
  1212. Fmt: PChar;
  1213. SQ, DQ: Boolean;
  1214. area: Integer;
  1215. Begin
  1216. SQ := False;
  1217. DQ := False;
  1218. Fmt := FmtStart;
  1219. ExpFmt := 0;
  1220. area := 1;
  1221. thousand := False;
  1222. Placehold[1] := 0;
  1223. Placehold[2] := 0;
  1224. Placehold[3] := 0;
  1225. Placehold[4] := 0;
  1226. While Fmt < FmtStop Do
  1227. Begin
  1228. Case Fmt[0] Of
  1229. #34:
  1230. Begin
  1231. If Not SQ Then
  1232. DQ := Not DQ;
  1233. Inc(Fmt);
  1234. End;
  1235. #39:
  1236. Begin
  1237. If Not DQ Then
  1238. SQ := Not SQ;
  1239. Inc(Fmt);
  1240. End;
  1241. Else
  1242. { This was 'if not SQ or DQ'. Looked wrong... }
  1243. If Not SQ Or DQ Then
  1244. Begin
  1245. Case Fmt[0] Of
  1246. '0':
  1247. Begin
  1248. Case area Of
  1249. 1:
  1250. area := 2;
  1251. 4:
  1252. Begin
  1253. area := 3;
  1254. Inc(Placehold[3], Placehold[4]);
  1255. Placehold[4] := 0;
  1256. End;
  1257. End;
  1258. Inc(Placehold[area]);
  1259. Inc(Fmt);
  1260. End;
  1261. '#':
  1262. Begin
  1263. If area=3 Then
  1264. area:=4;
  1265. Inc(Placehold[area]);
  1266. Inc(Fmt);
  1267. End;
  1268. '.':
  1269. Begin
  1270. If area<3 Then
  1271. area:=3;
  1272. Inc(Fmt);
  1273. End;
  1274. ',':
  1275. Begin
  1276. thousand := True;
  1277. Inc(Fmt);
  1278. End;
  1279. 'e', 'E':
  1280. If ExpFmt = 0 Then
  1281. Begin
  1282. If (Fmt[0]='E') Then
  1283. ExpFmt:=1
  1284. Else
  1285. ExpFmt := 3;
  1286. Inc(Fmt);
  1287. If (Fmt<FmtStop) Then
  1288. Begin
  1289. Case Fmt[0] Of
  1290. '+':
  1291. Begin
  1292. End;
  1293. '-':
  1294. Inc(ExpFmt);
  1295. Else
  1296. ExpFmt := 0;
  1297. End;
  1298. If ExpFmt <> 0 Then
  1299. Begin
  1300. Inc(Fmt);
  1301. ExpSize := 0;
  1302. While (Fmt<FmtStop) And
  1303. (ExpSize<4) And
  1304. (Fmt[0] In ['0'..'9']) Do
  1305. Begin
  1306. Inc(ExpSize);
  1307. Inc(Fmt);
  1308. End;
  1309. End;
  1310. End;
  1311. End
  1312. Else
  1313. Inc(Fmt);
  1314. Else { Case }
  1315. Inc(Fmt);
  1316. End; { Case }
  1317. End; { Begin }
  1318. End; { Case }
  1319. End; { While .. Begin }
  1320. End;
  1321. Procedure FloatToStr;
  1322. Var
  1323. I, J, Exp, Width, Decimals, DecimalPoint, len: Integer;
  1324. Begin
  1325. If ExpFmt = 0 Then
  1326. Begin
  1327. { Fixpoint }
  1328. Decimals:=Placehold[3]+Placehold[4];
  1329. Width:=Placehold[1]+Placehold[2]+Decimals;
  1330. If (Decimals=0) Then
  1331. Str(Value:Width:0,Digits)
  1332. Else
  1333. Str(Value:Width+1:Decimals,Digits);
  1334. len:=Length(Digits);
  1335. { Find the decimal point }
  1336. If (Decimals=0) Then
  1337. DecimalPoint:=len+1
  1338. Else
  1339. DecimalPoint:=len-Decimals;
  1340. { If value is very small, and no decimal places
  1341. are desired, remove the leading 0. }
  1342. If (Abs(Value) < 1) And (Placehold[2] = 0) Then
  1343. Begin
  1344. If (Placehold[1]=0) Then
  1345. Delete(Digits,DecimalPoint-1,1)
  1346. Else
  1347. Digits[DecimalPoint-1]:=' ';
  1348. End;
  1349. { Convert optional zeroes to spaces. }
  1350. I:=len;
  1351. J:=DecimalPoint+Placehold[3];
  1352. While (I>J) And (Digits[I]='0') Do
  1353. Begin
  1354. Digits[I] := ' ';
  1355. Dec(I);
  1356. End;
  1357. { If integer value and no obligatory decimal
  1358. places, remove decimal point. }
  1359. If (DecimalPoint < len) And (Digits[DecimalPoint + 1] = ' ') Then
  1360. Digits[DecimalPoint] := ' ';
  1361. { Convert spaces left from obligatory decimal point to zeroes. }
  1362. I:=DecimalPoint-Placehold[2];
  1363. While (I<DecimalPoint) And (Digits[I]=' ') Do
  1364. Begin
  1365. Digits[I] := '0';
  1366. Inc(I);
  1367. End;
  1368. Exp := 0;
  1369. End
  1370. Else
  1371. Begin
  1372. { Scientific: exactly <Width> Digits With <Precision> Decimals
  1373. And adjusted Exponent. }
  1374. If Placehold[1]+Placehold[2]=0 Then
  1375. Placehold[1]:=1;
  1376. Decimals := Placehold[3] + Placehold[4];
  1377. Width:=Placehold[1]+Placehold[2]+Decimals;
  1378. Str(Value:Width+8,Digits);
  1379. { Find and cut out exponent. Always the
  1380. last 6 characters in the string.
  1381. -> 0000E+0000 }
  1382. I:=Length(Digits)-5;
  1383. Val(Copy(Digits,I+1,5),Exp,J);
  1384. Exp:=Exp+1-(Placehold[1]+Placehold[2]);
  1385. Delete(Digits, I, 6);
  1386. { Str() always returns at least one digit after the decimal point.
  1387. If we don't want it, we have to remove it. }
  1388. If (Decimals=0) And (Placehold[1]+Placehold[2]<= 1) Then
  1389. Begin
  1390. If (Digits[4]>='5') Then
  1391. Begin
  1392. Inc(Digits[2]);
  1393. If (Digits[2]>'9') Then
  1394. Begin
  1395. Digits[2] := '1';
  1396. Inc(Exp);
  1397. End;
  1398. End;
  1399. Delete(Digits, 3, 2);
  1400. DecimalPoint := Length(Digits) + 1;
  1401. End
  1402. Else
  1403. Begin
  1404. { Move decimal point at the desired position }
  1405. Delete(Digits, 3, 1);
  1406. DecimalPoint:=2+Placehold[1]+Placehold[2];
  1407. If (Decimals<>0) Then
  1408. Insert('.',Digits,DecimalPoint);
  1409. End;
  1410. { Convert optional zeroes to spaces. }
  1411. I := Length(Digits);
  1412. J := DecimalPoint + Placehold[3];
  1413. While (I > J) And (Digits[I] = '0') Do
  1414. Begin
  1415. Digits[I] := ' ';
  1416. Dec(I);
  1417. End;
  1418. { If integer number and no obligatory decimal paces, remove decimal point }
  1419. If (DecimalPoint<Length(Digits)) And
  1420. (Digits[DecimalPoint+1]=' ') Then
  1421. Digits[DecimalPoint]:=' ';
  1422. If (Digits[1]=' ') Then
  1423. Begin
  1424. Delete(Digits, 1, 1);
  1425. Dec(DecimalPoint);
  1426. End;
  1427. { Calculate exponent string }
  1428. Str(Abs(Exp), Exponent);
  1429. While Length(Exponent)<ExpSize Do
  1430. Insert('0',Exponent,1);
  1431. If Exp >= 0 Then
  1432. Begin
  1433. If (ExpFmt In [1,3]) Then
  1434. Insert('+', Exponent, 1);
  1435. End
  1436. Else
  1437. Insert('-',Exponent,1);
  1438. If (ExpFmt<3) Then
  1439. Insert('E',Exponent,1)
  1440. Else
  1441. Insert('e',Exponent,1);
  1442. End;
  1443. DigitExponent:=DecimalPoint-2;
  1444. If (Digits[1]='-') Then
  1445. Dec(DigitExponent);
  1446. UnexpectedDigits:=DecimalPoint-1-(Placehold[1]+Placehold[2]);
  1447. End;
  1448. Function PutResult: LongInt;
  1449. Var
  1450. SQ, DQ: Boolean;
  1451. Fmt, Buf: PChar;
  1452. Dig, N: Integer;
  1453. Begin
  1454. SQ := False;
  1455. DQ := False;
  1456. Fmt := FmtStart;
  1457. Buf := Buffer;
  1458. Dig := 1;
  1459. While (Fmt<FmtStop) Do
  1460. Begin
  1461. //Write(Fmt[0]);
  1462. Case Fmt[0] Of
  1463. #34:
  1464. Begin
  1465. If Not SQ Then
  1466. DQ := Not DQ;
  1467. Inc(Fmt);
  1468. End;
  1469. #39:
  1470. Begin
  1471. If Not DQ Then
  1472. SQ := Not SQ;
  1473. Inc(Fmt);
  1474. End;
  1475. Else
  1476. If Not (SQ Or DQ) Then
  1477. Begin
  1478. Case Fmt[0] Of
  1479. '0', '#', '.':
  1480. Begin
  1481. If (Dig=1) And (UnexpectedDigits>0) Then
  1482. Begin
  1483. { Everything unexpected is written before the first digit }
  1484. For N := 1 To UnexpectedDigits Do
  1485. Begin
  1486. Buf[0] := Digits[N];
  1487. Inc(Buf);
  1488. If thousand And (Digits[N]<>'-') Then
  1489. Begin
  1490. If (DigitExponent Mod 3 = 0) And (DigitExponent>0) Then
  1491. Begin
  1492. Buf[0] := ThousandSeparator;
  1493. Inc(Buf);
  1494. End;
  1495. Dec(DigitExponent);
  1496. End;
  1497. End;
  1498. Inc(Dig, UnexpectedDigits);
  1499. End;
  1500. If (Digits[Dig]<>' ') Then
  1501. Begin
  1502. If (Digits[Dig]='.') Then
  1503. Buf[0] := DecimalSeparator
  1504. Else
  1505. Buf[0] := Digits[Dig];
  1506. Inc(Buf);
  1507. If thousand And (DigitExponent Mod 3 = 0) And (DigitExponent > 0) Then
  1508. Begin
  1509. Buf[0] := ThousandSeparator;
  1510. Inc(Buf);
  1511. End;
  1512. End;
  1513. Inc(Dig);
  1514. Dec(DigitExponent);
  1515. Inc(Fmt);
  1516. End;
  1517. 'e', 'E':
  1518. Begin
  1519. If ExpFmt <> 0 Then
  1520. Begin
  1521. Inc(Fmt);
  1522. If Fmt < FmtStop Then
  1523. Begin
  1524. If Fmt[0] In ['+', '-'] Then
  1525. Begin
  1526. Inc(Fmt, ExpSize);
  1527. For N:=1 To Length(Exponent) Do
  1528. Buf[N-1] := Exponent[N];
  1529. Inc(Buf,Length(Exponent));
  1530. ExpFmt:=0;
  1531. End;
  1532. Inc(Fmt);
  1533. End;
  1534. End
  1535. Else
  1536. Begin
  1537. { No legal exponential format.
  1538. Simply write the 'E' to the result. }
  1539. Buf[0] := Fmt[0];
  1540. Inc(Buf);
  1541. Inc(Fmt);
  1542. End;
  1543. End;
  1544. Else { Case }
  1545. { Usual character }
  1546. If (Fmt[0]<>',') Then
  1547. Begin
  1548. Buf[0] := Fmt[0];
  1549. Inc(Buf);
  1550. End;
  1551. Inc(Fmt);
  1552. End; { Case }
  1553. End
  1554. Else { IF }
  1555. Begin
  1556. { Character inside single or double quotes }
  1557. Buf[0] := Fmt[0];
  1558. Inc(Buf);
  1559. Inc(Fmt);
  1560. End;
  1561. End; { Case }
  1562. End; { While .. Begin }
  1563. Result:=LongInt(Buf)-LongInt(Buffer);
  1564. End;
  1565. Begin
  1566. If (Value>0) Then
  1567. GetSectionRange(1)
  1568. Else If (Value<0) Then
  1569. GetSectionRange(2)
  1570. Else
  1571. GetSectionRange(3);
  1572. If FmtStart = Nil Then
  1573. Begin
  1574. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4);
  1575. End
  1576. Else
  1577. Begin
  1578. GetFormatOptions;
  1579. If (ExpFmt = 0) And (Abs(Value) >= 1E18) Then
  1580. Result := FloatToText(Buffer, Value, ffGeneral, 15, 4)
  1581. Else
  1582. Begin
  1583. FloatToStr;
  1584. Result := PutResult;
  1585. End;
  1586. End;
  1587. End;
  1588. Procedure FloatToDecimal(Var Result: TFloatRec; Value: Extended; Precision, Decimals : integer);
  1589. Var
  1590. Buffer: String[24];
  1591. Error, N: Integer;
  1592. Begin
  1593. Str(Value:23, Buffer);
  1594. Result.Negative := (Buffer[1] = '-');
  1595. Val(Copy(Buffer, 19, 5), Result.Exponent, Error);
  1596. Inc(Result. Exponent);
  1597. Result.Digits[0] := Buffer[2];
  1598. Move(Buffer[4], Result.Digits[1], 14);
  1599. If Decimals + Result.Exponent < Precision Then
  1600. N := Decimals + Result.Exponent
  1601. Else
  1602. N := Precision;
  1603. If N > 15 Then
  1604. N := 15;
  1605. If N = 0 Then
  1606. Begin
  1607. If Result.Digits[0] >= '5' Then
  1608. Begin
  1609. Result.Digits[0] := '1';
  1610. Result.Digits[1] := #0;
  1611. Inc(Result.Exponent);
  1612. End
  1613. Else
  1614. Result.Digits[0] := #0;
  1615. End
  1616. Else If N > 0 Then
  1617. Begin
  1618. If Result.Digits[N] >= '5' Then
  1619. Begin
  1620. Repeat
  1621. Result.Digits[N] := #0;
  1622. Dec(N);
  1623. Inc(Result.Digits[N]);
  1624. Until (N = 0) Or (Result.Digits[N] < ':');
  1625. If Result.Digits[0] = ':' Then
  1626. Begin
  1627. Result.Digits[0] := '1';
  1628. Inc(Result.Exponent);
  1629. End;
  1630. End
  1631. Else
  1632. Begin
  1633. Result.Digits[N] := '0';
  1634. While (Result.Digits[N] = '0') And (N > -1) Do
  1635. Begin
  1636. Result.Digits[N] := #0;
  1637. Dec(N);
  1638. End;
  1639. End;
  1640. End
  1641. Else
  1642. Result.Digits[0] := #0;
  1643. If Result.Digits[0] = #0 Then
  1644. Begin
  1645. Result.Exponent := 0;
  1646. Result.Negative := False;
  1647. End;
  1648. End;
  1649. Function FormatFloat(Const format: String; Value: Extended): String;
  1650. Var
  1651. Temp: ShortString;
  1652. buf : Array[0..1024] of char;
  1653. Begin
  1654. Buf[FloatToTextFmt(@Buf[0],Value,Pchar(Format))]:=#0;
  1655. Result:=StrPas(@Buf);
  1656. End;
  1657. {==============================================================================}
  1658. { extra functions }
  1659. {==============================================================================}
  1660. { LeftStr returns Count left-most characters from S }
  1661. function LeftStr(const S: string; Count: integer): string;
  1662. begin
  1663. result := Copy(S, 1, Count);
  1664. end ;
  1665. { RightStr returns Count right-most characters from S }
  1666. function RightStr(const S: string; Count: integer): string;
  1667. begin
  1668. If Count>Length(S) then
  1669. Count:=Length(S);
  1670. result := Copy(S, 1 + Length(S) - Count, Count);
  1671. end;
  1672. { BCDToInt converts the BCD value Value to an integer }
  1673. function BCDToInt(Value: integer): integer;
  1674. var i, j: integer;
  1675. begin
  1676. result := 0;
  1677. j := 1;
  1678. for i := 0 to SizeOf(Value) shr 1 - 1 do begin
  1679. result := result + j * (Value and 15);
  1680. j := j * 10;
  1681. Value := Value shr 4;
  1682. end ;
  1683. end ;
  1684. Function IsDelimiter(const Delimiters, S: string; Index: Integer): Boolean;
  1685. begin
  1686. Result:=False;
  1687. If Index<=Length(S) then
  1688. Result:=Pos(S[Index],Delimiters)<>0; // Note we don't do MBCS yet
  1689. end;
  1690. Function LastDelimiter(const Delimiters, S: string): Integer;
  1691. begin
  1692. Result:=Length(S);
  1693. While (Result>0) and (Pos(S[Result],Delimiters)=0) do
  1694. Dec(Result);
  1695. end;
  1696. function StringReplace(const S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
  1697. var
  1698. Srch,OldP,RemS: string; // Srch and Oldp can contain uppercase versions of S,OldPattern
  1699. P : Integer;
  1700. begin
  1701. Srch:=S;
  1702. OldP:=OldPattern;
  1703. if rfIgnoreCase in Flags then
  1704. begin
  1705. Srch:=UpperCase(Srch);
  1706. OldP:=UpperCase(OldP);
  1707. end;
  1708. RemS:=S;
  1709. Result:='';
  1710. while (Length(Srch)<>0) do
  1711. begin
  1712. P:=Pos(OldP, Srch);
  1713. if P=0 then
  1714. begin
  1715. Result:=Result+RemS;
  1716. Srch:='';
  1717. end
  1718. else
  1719. begin
  1720. Result:=Result+Copy(RemS,1,P-1)+NewPattern;
  1721. P:=P+Length(OldP);
  1722. RemS:=Copy(RemS,P,Length(RemS)-P+1);
  1723. if not (rfReplaceAll in Flags) then
  1724. begin
  1725. Result:=Result+RemS;
  1726. Srch:='';
  1727. end
  1728. else
  1729. Srch:=Copy(Srch,P,Length(Srch)-P+1);
  1730. end;
  1731. end;
  1732. end;
  1733. {
  1734. Case Translation Tables
  1735. Can be used in internationalization support.
  1736. Although these tables can be obtained through system calls
  1737. it is better to not use those, since most implementation are not 100%
  1738. WARNING:
  1739. before modifying a translation table make sure that the current codepage
  1740. of the OS corresponds to the one you make changes to
  1741. }
  1742. const
  1743. { upper case translation table for character set 850 }
  1744. CP850UCT: array[128..255] of char =
  1745. ('€', 'š', '�', '¶', 'Ž', '¶', '�', '€', 'Ò', 'Ó', 'Ô', 'Ø', '×', 'Þ', 'Ž', '�',
  1746. '�', '’', '’', 'â', '™', 'ã', 'ê', 'ë', 'Y', '™', 'š', '�', 'œ', '�', 'ž', 'Ÿ',
  1747. 'µ', 'Ö', 'à', 'é', '¥', '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1748. '°', '±', '²', '³', '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1749. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1750. 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß',
  1751. 'à', 'á', 'â', 'ã', 'å', 'å', 'æ', 'í', 'è', 'é', 'ê', 'ë', 'í', 'í', 'î', 'ï',
  1752. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1753. { lower case translation table for character set 850 }
  1754. CP850LCT: array[128..255] of char =
  1755. ('‡', '�', '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'Š', '‹', 'Œ', '�', '„', '†',
  1756. '‚', '‘', '‘', '“', '”', '•', '–', '—', '˜', '”', '�', '›', 'œ', '›', 'ž', 'Ÿ',
  1757. ' ', '¡', '¢', '£', '¤', '¤', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯',
  1758. '°', '±', '²', '³', '´', ' ', 'ƒ', '…', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿',
  1759. 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Æ', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï',
  1760. 'Ð', 'Ñ', 'ˆ', '‰', 'Š', 'Õ', '¡', 'Œ', '‹', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', '�', 'ß',
  1761. '¢', 'á', '“', '•', 'ä', 'ä', 'æ', 'í', 'è', '£', '–', '—', 'ì', 'ì', 'î', 'ï',
  1762. 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
  1763. { upper case translation table for character set ISO 8859/1 Latin 1 }
  1764. CPISO88591UCT: array[192..255] of char =
  1765. ( #192, #193, #194, #195, #196, #197, #198, #199,
  1766. #200, #201, #202, #203, #204, #205, #206, #207,
  1767. #208, #209, #210, #211, #212, #213, #214, #215,
  1768. #216, #217, #218, #219, #220, #221, #222, #223,
  1769. #192, #193, #194, #195, #196, #197, #198, #199,
  1770. #200, #201, #202, #203, #204, #205, #206, #207,
  1771. #208, #209, #210, #211, #212, #213, #214, #247,
  1772. #216, #217, #218, #219, #220, #221, #222, #89 );
  1773. { lower case translation table for character set ISO 8859/1 Latin 1 }
  1774. CPISO88591LCT: array[192..255] of char =
  1775. ( #224, #225, #226, #227, #228, #229, #230, #231,
  1776. #232, #233, #234, #235, #236, #237, #238, #239,
  1777. #240, #241, #242, #243, #244, #245, #246, #215,
  1778. #248, #249, #250, #251, #252, #253, #254, #223,
  1779. #224, #225, #226, #227, #228, #229, #230, #231,
  1780. #232, #233, #234, #235, #236, #237, #238, #239,
  1781. #240, #241, #242, #243, #244, #245, #246, #247,
  1782. #248, #249, #250, #251, #252, #253, #254, #255 );
  1783. {
  1784. $Log$
  1785. Revision 1.3 2003-11-03 09:42:28 marco
  1786. * Peter's Cardinal<->Longint fixes patch
  1787. Revision 1.2 2003/10/07 12:02:47 marco
  1788. * sametext and ansisametext added. (simple (ansi)comparetext wrappers)
  1789. Revision 1.1 2003/10/06 21:01:06 peter
  1790. * moved classes unit to rtl
  1791. Revision 1.26 2003/09/06 21:22:07 marco
  1792. * More objpas fixes
  1793. Revision 1.25 2002/12/23 23:26:08 florian
  1794. + addition to previous commit, forgot to save in the editor
  1795. Revision 1.23 2002/11/28 22:26:30 michael
  1796. + Fixed float<>string conversion routines
  1797. Revision 1.22 2002/11/28 20:29:26 michael
  1798. + made it compile again
  1799. Revision 1.21 2002/11/28 20:15:37 michael
  1800. + Fixed comparestr (merge from fix)
  1801. Revision 1.20 2002/09/15 17:50:35 peter
  1802. * Fixed AnsiStrComp crashes
  1803. Revision 1.1.2.16 2002/11/28 22:25:01 michael
  1804. + Fixed float<>string conversion routines
  1805. Revision 1.1.2.15 2002/11/28 20:24:11 michael
  1806. + merged some fixes from mainbranch
  1807. Revision 1.19 2002/09/07 16:01:22 peter
  1808. * old logs removed and tabs fixed
  1809. Revision 1.1.2.14 2002/11/28 20:13:10 michael
  1810. + Fixed comparestr
  1811. Revision 1.1.2.13 2002/10/29 23:41:06 michael
  1812. + Added lots of D4 functions
  1813. Revision 1.18 2002/09/02 06:07:16 michael
  1814. + Fix for formatbuf not applied correct
  1815. Revision 1.17 2002/08/29 10:04:48 michael
  1816. + Fix for bug report 2097 in formatbuf
  1817. Revision 1.16 2002/08/29 10:04:25 michael
  1818. + Fix for bug report 2097 in formatbuf
  1819. Revision 1.15 2002/07/06 12:14:03 daniel
  1820. - Changes from Strasbourg
  1821. Revision 1.14 2002/01/24 12:33:53 jonas
  1822. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1823. longer longint($ffffffff), but just $fffffff in psystem)
  1824. * small additional fix in 64bit rangecheck code generation for 32 bit
  1825. processors
  1826. * adaption of ranges required the matching talgorithm used for selecting
  1827. which overloaded procedure to call to be adapted. It should now always
  1828. select the closest match for ordinal parameters.
  1829. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1830. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1831. fixes were required to be able to add them)
  1832. * is_in_limit() moved from ncal to types unit, should always be used
  1833. instead of direct comparisons of low/high values of orddefs because
  1834. qword is a special case
  1835. }