sysutils.pp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. member of the Free Pascal development team
  5. Sysutils unit for win32
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit sysutils;
  13. interface
  14. {$MODE objfpc}
  15. {$MODESWITCH OUT}
  16. { force ansistrings }
  17. {$H+}
  18. uses
  19. windows;
  20. {$DEFINE HAS_SLEEP}
  21. {$DEFINE HAS_OSERROR}
  22. {$DEFINE HAS_OSCONFIG}
  23. {$DEFINE HAS_OSUSERDIR}
  24. {$DEFINE HAS_CREATEGUID}
  25. {$DEFINE HAS_LOCALTIMEZONEOFFSET}
  26. { Include platform independent interface part }
  27. {$i sysutilh.inc}
  28. type
  29. TSystemTime = Windows.TSystemTime;
  30. EWin32Error = class(Exception)
  31. public
  32. ErrorCode : DWORD;
  33. end;
  34. Var
  35. Win32Platform : Longint;
  36. Win32MajorVersion,
  37. Win32MinorVersion,
  38. Win32BuildNumber : dword;
  39. Win32CSDVersion : ShortString; // CSD record is 128 bytes only?
  40. const
  41. MaxEraCount = 7;
  42. var
  43. EraNames: array [1..MaxEraCount] of String;
  44. EraYearOffsets: array [1..MaxEraCount] of Integer;
  45. { Compatibility with Delphi }
  46. function Win32Check(res:boolean):boolean;inline;
  47. function WinCheck(res:boolean):boolean;
  48. function CheckWin32Version(Major,Minor : Integer ): Boolean;
  49. function CheckWin32Version(Major : Integer): Boolean;
  50. Procedure RaiseLastWin32Error;
  51. function GetFileVersion(const AFileName: string): Cardinal;
  52. procedure GetFormatSettings;
  53. procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings); platform;
  54. implementation
  55. uses
  56. sysconst,
  57. windirs;
  58. function WinCheck(res:boolean):boolean;
  59. begin
  60. if not res then
  61. RaiseLastOSError;
  62. result:=res;
  63. end;
  64. function Win32Check(res:boolean):boolean;inline;
  65. begin
  66. result:=WinCheck(res);
  67. end;
  68. procedure RaiseLastWin32Error;
  69. begin
  70. RaiseLastOSError;
  71. end;
  72. function CheckWin32Version(Major : Integer): Boolean;
  73. begin
  74. Result:=CheckWin32Version(Major,0)
  75. end;
  76. function CheckWin32Version(Major,Minor: Integer): Boolean;
  77. begin
  78. Result:=(Win32MajorVersion>dword(Major)) or
  79. ((Win32MajorVersion=dword(Major)) and (Win32MinorVersion>=dword(Minor)));
  80. end;
  81. function GetFileVersion(const AFileName:string):Cardinal;
  82. var
  83. { useful only as long as we don't need to touch different stack pages }
  84. buf : array[0..3071] of byte;
  85. bufp : pointer;
  86. fn : string;
  87. valsize,
  88. size : DWORD;
  89. h : DWORD;
  90. valrec : PVSFixedFileInfo;
  91. begin
  92. result:=$fffffff;
  93. fn:=AFileName;
  94. UniqueString(fn);
  95. size:=GetFileVersionInfoSize(pchar(fn),@h);
  96. if size>sizeof(buf) then
  97. begin
  98. getmem(bufp,size);
  99. try
  100. if GetFileVersionInfo(pchar(fn),h,size,bufp) then
  101. if VerQueryValue(bufp,'\',valrec,valsize) then
  102. result:=valrec^.dwFileVersionMS;
  103. finally
  104. freemem(bufp);
  105. end;
  106. end
  107. else
  108. begin
  109. if GetFileVersionInfo(pchar(fn),h,size,@buf) then
  110. if VerQueryValue(@buf,'\',valrec,valsize) then
  111. result:=valrec^.dwFileVersionMS;
  112. end;
  113. end;
  114. {$define HASCREATEGUID}
  115. {$define HASEXPANDUNCFILENAME}
  116. {$DEFINE FPC_NOGENERICANSIROUTINES}
  117. {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  118. {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  119. function ConvertEraYearString(Count ,Year,Month,Day : integer) : string; forward;
  120. function ConvertEraString(Count ,Year,Month,Day : integer) : string; forward;
  121. { Include platform independent implementation part }
  122. {$i sysutils.inc}
  123. function GetTempFileName(Dir,Prefix: PChar; uUnique: DWORD; TempFileName: PChar):DWORD;
  124. begin
  125. Result:= Windows.GetTempFileNameA(Dir,Prefix,uUnique,TempFileName);
  126. end;
  127. { UUID generation. }
  128. function CoCreateGuid(out guid: TGUID): HResult; stdcall; external 'ole32.dll' name 'CoCreateGuid';
  129. function SysCreateGUID(out Guid: TGUID): Integer;
  130. begin
  131. Result := Integer(CoCreateGuid(Guid));
  132. end;
  133. function ExpandUNCFileName (const filename:string) : string;
  134. { returns empty string on errors }
  135. var
  136. s : ansistring;
  137. size : dword;
  138. rc : dword;
  139. buf : pchar;
  140. begin
  141. s := ExpandFileName (filename);
  142. s := s + #0;
  143. size := max_path;
  144. getmem(buf,size);
  145. try
  146. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  147. if rc=ERROR_MORE_DATA then
  148. begin
  149. buf:=reallocmem(buf,size);
  150. rc := WNetGetUniversalName (pchar(s), UNIVERSAL_NAME_INFO_LEVEL, buf, @size);
  151. end;
  152. if rc = NO_ERROR then
  153. Result := PRemoteNameInfo(buf)^.lpUniversalName
  154. else if rc = ERROR_NOT_CONNECTED then
  155. Result := filename
  156. else
  157. Result := '';
  158. finally
  159. freemem(buf);
  160. end;
  161. end;
  162. {****************************************************************************
  163. File Functions
  164. ****************************************************************************}
  165. const
  166. AccessMode: array[0..2] of Cardinal = (
  167. GENERIC_READ,
  168. GENERIC_WRITE,
  169. GENERIC_READ or GENERIC_WRITE);
  170. ShareModes: array[0..4] of Integer = (
  171. 0,
  172. 0,
  173. FILE_SHARE_READ,
  174. FILE_SHARE_WRITE,
  175. FILE_SHARE_READ or FILE_SHARE_WRITE);
  176. Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
  177. begin
  178. result := CreateFile(PChar(FileName), dword(AccessMode[Mode and 3]),
  179. dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
  180. FILE_ATTRIBUTE_NORMAL, 0);
  181. //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
  182. end;
  183. Function FileCreate (Const FileName : String) : THandle;
  184. begin
  185. FileCreate:=FileCreate(FileName, fmShareExclusive, 0);
  186. end;
  187. Function FileCreate (Const FileName : String; Rights:longint) : THandle;
  188. begin
  189. FileCreate:=FileCreate(FileName, fmShareExclusive, Rights);
  190. end;
  191. Function FileCreate (Const FileName : String; ShareMode : Integer; Rights : Integer) : THandle;
  192. begin
  193. Result := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE,
  194. dword(ShareModes[(ShareMode and $F0) shr 4]), nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  195. end;
  196. Function FileRead (Handle : THandle; out Buffer; Count : longint) : Longint;
  197. Var
  198. res : dword;
  199. begin
  200. if ReadFile(Handle, Buffer, Count, res, nil) then
  201. FileRead:=Res
  202. else
  203. FileRead:=-1;
  204. end;
  205. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  206. Var
  207. Res : dword;
  208. begin
  209. if WriteFile(Handle, Buffer, Count, Res, nil) then
  210. FileWrite:=Res
  211. else
  212. FileWrite:=-1;
  213. end;
  214. Function FileSeek (Handle : THandle;FOffset,Origin : Longint) : Longint;
  215. begin
  216. Result := longint(SetFilePointer(Handle, FOffset, nil, Origin));
  217. end;
  218. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  219. var
  220. rslt: Int64Rec;
  221. begin
  222. rslt := Int64Rec(FOffset);
  223. rslt.lo := SetFilePointer(Handle, rslt.lo, @rslt.hi, Origin);
  224. if (rslt.lo = $FFFFFFFF) and (GetLastError <> 0) then
  225. rslt.hi := $FFFFFFFF;
  226. Result := Int64(rslt);
  227. end;
  228. Procedure FileClose (Handle : THandle);
  229. begin
  230. if Handle<=4 then
  231. exit;
  232. CloseHandle(Handle);
  233. end;
  234. Function FileTruncate (Handle : THandle;Size: Int64) : boolean;
  235. begin
  236. {
  237. Result:=longint(SetFilePointer(handle,Size,nil,FILE_BEGIN))<>-1;
  238. }
  239. if FileSeek (Handle, Size, FILE_BEGIN) = Size then
  240. Result:=SetEndOfFile(handle)
  241. else
  242. Result := false;
  243. end;
  244. Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):longbool;
  245. var
  246. lft : TFileTime;
  247. begin
  248. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,@lft) and
  249. LocalFileTimeToFileTime(lft,Wtime);
  250. end;
  251. Function WinToDosTime (Var Wtime : TFileTime;var DTime:longint):longbool;
  252. var
  253. lft : TFileTime;
  254. begin
  255. WinToDosTime:=FileTimeToLocalFileTime(WTime,lft) and
  256. FileTimeToDosDateTime(lft,Longrec(Dtime).Hi,LongRec(DTIME).lo);
  257. end;
  258. Function FileAge (Const FileName : String): Longint;
  259. var
  260. Handle: THandle;
  261. FindData: TWin32FindData;
  262. begin
  263. Handle := FindFirstFile(Pchar(FileName), FindData);
  264. if Handle <> INVALID_HANDLE_VALUE then
  265. begin
  266. Windows.FindClose(Handle);
  267. if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
  268. If WinToDosTime(FindData.ftLastWriteTime,Result) then
  269. exit;
  270. end;
  271. Result := -1;
  272. end;
  273. Function FileExists (Const FileName : String) : Boolean;
  274. var
  275. Attr:Dword;
  276. begin
  277. Attr:=GetFileAttributes(PChar(FileName));
  278. if Attr <> $ffffffff then
  279. Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) = 0
  280. else
  281. Result:=False;
  282. end;
  283. Function DirectoryExists (Const Directory : String) : Boolean;
  284. var
  285. Attr:Dword;
  286. begin
  287. Attr:=GetFileAttributes(PChar(Directory));
  288. if Attr <> $ffffffff then
  289. Result:= (Attr and FILE_ATTRIBUTE_DIRECTORY) > 0
  290. else
  291. Result:=False;
  292. end;
  293. Function FindMatch(var f: TSearchRec) : Longint;
  294. begin
  295. { Find file with correct attribute }
  296. While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
  297. begin
  298. if not FindNextFile (F.FindHandle,F.FindData) then
  299. begin
  300. Result:=GetLastError;
  301. exit;
  302. end;
  303. end;
  304. { Convert some attributes back }
  305. WinToDosTime(F.FindData.ftLastWriteTime,F.Time);
  306. f.size:=F.FindData.NFileSizeLow+(qword(maxdword)+1)*F.FindData.NFileSizeHigh;
  307. f.attr:=F.FindData.dwFileAttributes;
  308. f.Name:=StrPas(@F.FindData.cFileName[0]);
  309. Result:=0;
  310. end;
  311. Function FindFirst (Const Path : String; Attr : Longint; out Rslt : TSearchRec) : Longint;
  312. begin
  313. Rslt.Name:=Path;
  314. Rslt.Attr:=attr;
  315. Rslt.ExcludeAttr:=(not Attr) and ($1e);
  316. { $1e = faHidden or faSysFile or faVolumeID or faDirectory }
  317. { FindFirstFile is a Win32 Call }
  318. Rslt.FindHandle:=FindFirstFile (PChar(Path),Rslt.FindData);
  319. If Rslt.FindHandle=Invalid_Handle_value then
  320. begin
  321. Result:=GetLastError;
  322. exit;
  323. end;
  324. { Find file with correct attribute }
  325. Result:=FindMatch(Rslt);
  326. end;
  327. Function FindNext (Var Rslt : TSearchRec) : Longint;
  328. begin
  329. if FindNextFile(Rslt.FindHandle, Rslt.FindData) then
  330. Result := FindMatch(Rslt)
  331. else
  332. Result := GetLastError;
  333. end;
  334. Procedure FindClose (Var F : TSearchrec);
  335. begin
  336. if F.FindHandle <> INVALID_HANDLE_VALUE then
  337. Windows.FindClose(F.FindHandle);
  338. end;
  339. Function FileGetDate (Handle : THandle) : Longint;
  340. Var
  341. FT : TFileTime;
  342. begin
  343. If GetFileTime(Handle,nil,nil,@ft) and
  344. WinToDosTime(FT,Result) then
  345. exit;
  346. Result:=-1;
  347. end;
  348. Function FileSetDate (Handle : THandle;Age : Longint) : Longint;
  349. Var
  350. FT: TFileTime;
  351. begin
  352. Result := 0;
  353. if DosToWinTime(Age,FT) and
  354. SetFileTime(Handle, nil, nil, @FT) then
  355. Exit;
  356. Result := GetLastError;
  357. end;
  358. Function FileGetAttr (Const FileName : String) : Longint;
  359. begin
  360. Result:=Longint(GetFileAttributes(PChar(FileName)));
  361. end;
  362. Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
  363. begin
  364. if SetFileAttributes(PChar(FileName), Attr) then
  365. Result:=0
  366. else
  367. Result := GetLastError;
  368. end;
  369. Function DeleteFile (Const FileName : String) : Boolean;
  370. begin
  371. Result:=Windows.DeleteFile(Pchar(FileName));
  372. end;
  373. Function RenameFile (Const OldName, NewName : String) : Boolean;
  374. begin
  375. Result := MoveFile(PChar(OldName), PChar(NewName));
  376. end;
  377. {****************************************************************************
  378. Disk Functions
  379. ****************************************************************************}
  380. type
  381. TGetDiskFreeSpaceEx = function(drive:pchar;var availableforcaller,total,free):longbool;stdcall;
  382. var
  383. GetDiskFreeSpaceEx : TGetDiskFreeSpaceEx;
  384. function diskfree(drive : byte) : int64;
  385. var
  386. disk : array[1..4] of char;
  387. secs,bytes,
  388. free,total : dword;
  389. qwtotal,qwfree,qwcaller : int64;
  390. begin
  391. if drive=0 then
  392. begin
  393. disk[1]:='\';
  394. disk[2]:=#0;
  395. end
  396. else
  397. begin
  398. disk[1]:=chr(drive+64);
  399. disk[2]:=':';
  400. disk[3]:='\';
  401. disk[4]:=#0;
  402. end;
  403. if assigned(GetDiskFreeSpaceEx) then
  404. begin
  405. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  406. diskfree:=qwfree
  407. else
  408. diskfree:=-1;
  409. end
  410. else
  411. begin
  412. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  413. diskfree:=int64(free)*secs*bytes
  414. else
  415. diskfree:=-1;
  416. end;
  417. end;
  418. function disksize(drive : byte) : int64;
  419. var
  420. disk : array[1..4] of char;
  421. secs,bytes,
  422. free,total : dword;
  423. qwtotal,qwfree,qwcaller : int64;
  424. begin
  425. if drive=0 then
  426. begin
  427. disk[1]:='\';
  428. disk[2]:=#0;
  429. end
  430. else
  431. begin
  432. disk[1]:=chr(drive+64);
  433. disk[2]:=':';
  434. disk[3]:='\';
  435. disk[4]:=#0;
  436. end;
  437. if assigned(GetDiskFreeSpaceEx) then
  438. begin
  439. if GetDiskFreeSpaceEx(@disk[1],qwcaller,qwtotal,qwfree) then
  440. disksize:=qwtotal
  441. else
  442. disksize:=-1;
  443. end
  444. else
  445. begin
  446. if GetDiskFreeSpace(@disk[1],secs,bytes,free,total) then
  447. disksize:=int64(total)*secs*bytes
  448. else
  449. disksize:=-1;
  450. end;
  451. end;
  452. Function GetCurrentDir : String;
  453. begin
  454. GetDir(0, result);
  455. end;
  456. Function SetCurrentDir (Const NewDir : String) : Boolean;
  457. begin
  458. Result:=SetCurrentDirectory(PChar(NewDir));
  459. end;
  460. Function CreateDir (Const NewDir : String) : Boolean;
  461. begin
  462. Result:=CreateDirectory(PChar(NewDir),nil);
  463. end;
  464. Function RemoveDir (Const Dir : String) : Boolean;
  465. begin
  466. Result:=RemoveDirectory(PChar(Dir));
  467. end;
  468. {****************************************************************************
  469. Time Functions
  470. ****************************************************************************}
  471. Procedure GetLocalTime(var SystemTime: TSystemTime);
  472. begin
  473. windows.Getlocaltime(SystemTime);
  474. end;
  475. function GetLocalTimeOffset: Integer;
  476. var
  477. TZInfo: TTimeZoneInformation;
  478. begin
  479. case GetTimeZoneInformation(TZInfo) of
  480. TIME_ZONE_ID_UNKNOWN:
  481. Result := TZInfo.Bias;
  482. TIME_ZONE_ID_STANDARD:
  483. Result := TZInfo.Bias + TZInfo.StandardBias;
  484. TIME_ZONE_ID_DAYLIGHT:
  485. Result := TZInfo.Bias + TZInfo.DaylightBias;
  486. else
  487. Result := 0;
  488. end;
  489. end;
  490. {****************************************************************************
  491. Misc Functions
  492. ****************************************************************************}
  493. procedure sysbeep;
  494. begin
  495. MessageBeep(0);
  496. end;
  497. {****************************************************************************
  498. Locale Functions
  499. ****************************************************************************}
  500. function GetLocaleStr(LID, LT: Longint; const Def: string): ShortString;
  501. var
  502. L: Integer;
  503. Buf: array[0..255] of Char;
  504. begin
  505. L := GetLocaleInfo(LID, LT, Buf, SizeOf(Buf));
  506. if L > 0 then
  507. SetString(Result, @Buf[0], L - 1)
  508. else
  509. Result := Def;
  510. end;
  511. function GetLocaleChar(LID, LT: Longint; Def: Char): Char;
  512. var
  513. Buf: array[0..3] of Char; // sdate allows 4 chars.
  514. begin
  515. if GetLocaleInfo(LID, LT, Buf, sizeof(buf)) > 0 then
  516. Result := Buf[0]
  517. else
  518. Result := Def;
  519. end;
  520. function ConvertEraString(Count ,Year,Month,Day : integer) : string;
  521. var
  522. ASystemTime: TSystemTime;
  523. buf: array[0..100] of char;
  524. ALCID : LCID;
  525. PriLangID : Word;
  526. SubLangID : Word;
  527. begin
  528. Result := ''; if (Count<=0) then exit;
  529. DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
  530. ALCID := GetThreadLocale;
  531. // ALCID := SysLocale.DefaultLCID;
  532. if GetDateFormat(ALCID , DATE_USE_ALT_CALENDAR
  533. , @ASystemTime, PChar('gg')
  534. , @buf, SizeOf(buf)) > 0 then
  535. begin
  536. Result := buf;
  537. if Count = 1 then
  538. begin
  539. PriLangID := ALCID and $3FF;
  540. SubLangID := (ALCID and $FFFF) shr 10;
  541. case PriLangID of
  542. LANG_JAPANESE:
  543. begin
  544. Result := Copy(WideString(Result),1,1);
  545. end;
  546. LANG_CHINESE:
  547. if (SubLangID = SUBLANG_CHINESE_TRADITIONAL) then
  548. begin
  549. Result := Copy(WideString(Result),1,1);
  550. end;
  551. end;
  552. end;
  553. end;
  554. // if Result = '' then Result := StringOfChar('G',Count);
  555. end;
  556. function ConvertEraYearString(Count ,Year,Month,Day : integer) : string;
  557. var
  558. ALCID : LCID;
  559. ASystemTime : TSystemTime;
  560. AFormatText : string;
  561. buf : array[0..100] of Char;
  562. begin
  563. Result := '';
  564. DateTimeToSystemTime(EncodeDate(Year,Month,Day),ASystemTime);
  565. if Count <= 2 then
  566. AFormatText := 'yy'
  567. else
  568. AFormatText := 'yyyy';
  569. ALCID := GetThreadLocale;
  570. // ALCID := SysLocale.DefaultLCID;
  571. if GetDateFormat(ALCID, DATE_USE_ALT_CALENDAR
  572. , @ASystemTime, PChar(AFormatText)
  573. , @buf, SizeOf(buf)) > 0 then
  574. begin
  575. Result := buf;
  576. if (Count = 1) and (Result[1] = '0') then
  577. Result := Copy(Result, 2, Length(Result)-1);
  578. end;
  579. end;
  580. Function GetLocaleInt(LID,TP,Def: LongInt): LongInt;
  581. Var
  582. S: String;
  583. C: Integer;
  584. Begin
  585. S:=GetLocaleStr(LID,TP,'0');
  586. Val(S,Result,C);
  587. If C<>0 Then
  588. Result:=Def;
  589. End;
  590. function EnumEraNames(Names: PChar): WINBOOL; stdcall;
  591. var
  592. i : integer;
  593. begin
  594. Result := False;
  595. for i := Low(EraNames) to High(EraNames) do
  596. if (EraNames[i] = '') then
  597. begin
  598. EraNames[i] := Names;
  599. Result := True;
  600. break;
  601. end;
  602. end;
  603. function EnumEraYearOffsets(YearOffsets: PChar): WINBOOL; stdcall;
  604. var
  605. i : integer;
  606. begin
  607. Result := False;
  608. for i := Low(EraYearOffsets) to High(EraYearOffsets) do
  609. if (EraYearOffsets[i] = -1) then
  610. begin
  611. EraYearOffsets[i] := StrToIntDef(YearOffsets, 0);
  612. Result := True;
  613. break;
  614. end;
  615. end;
  616. procedure GetEraNamesAndYearOffsets;
  617. var
  618. ACALID : CALID;
  619. ALCID : LCID;
  620. buf : array[0..10] of char;
  621. i : integer;
  622. begin
  623. for i:= 1 to MaxEraCount do
  624. begin
  625. EraNames[i] := ''; EraYearOffsets[i] := -1;
  626. end;
  627. ALCID := GetThreadLocale;
  628. if GetLocaleInfo(ALCID , LOCALE_IOPTIONALCALENDAR, buf, sizeof(buf)) <= 0 then exit;
  629. ACALID := StrToIntDef(buf,1);
  630. if ACALID in [3..5] then
  631. begin
  632. EnumCalendarInfoA(@EnumEraNames, ALCID, ACALID , CAL_SERASTRING);
  633. EnumCalendarInfoA(@EnumEraYearOffsets, ALCID, ACALID, CAL_IYEAROFFSETRANGE);
  634. end;
  635. (*
  636. 1 CAL_GREGORIAN Gregorian (localized)
  637. 2 CAL_GREGORIAN_US Gregorian (English strings always)
  638. 3 CAL_JAPAN Japanese Emperor Era
  639. 4 CAL_TAIWAN Taiwan Calendar
  640. 5 CAL_KOREA Korean Tangun Era
  641. 6 CAL_HIJRI Hijri (Arabic Lunar)
  642. 7 CAL_THAI Thai
  643. 8 CAL_HEBREW Hebrew (Lunar)
  644. 9 CAL_GREGORIAN_ME_FRENCH Gregorian Middle East French
  645. 10 CAL_GREGORIAN_ARABIC Gregorian Arabic
  646. 11 CAL_GREGORIAN_XLIT_ENGLISH Gregorian transliterated English
  647. 12 CAL_GREGORIAN_XLIT_FRENCH Gregorian transliterated French
  648. 23 CAL_UMALQURA Windows Vista or later: Um Al Qura (Arabic lunar) calendar
  649. *)
  650. end;
  651. procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings);
  652. var
  653. HF : Shortstring;
  654. LID : Windows.LCID;
  655. I,Day : longint;
  656. begin
  657. LID := LCID;
  658. with FormatSettings do
  659. begin
  660. { Date stuff }
  661. for I := 1 to 12 do
  662. begin
  663. ShortMonthNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVMONTHNAME1+I-1,ShortMonthNames[i]);
  664. LongMonthNames[I]:=GetLocaleStr(LID,LOCALE_SMONTHNAME1+I-1,LongMonthNames[i]);
  665. end;
  666. for I := 1 to 7 do
  667. begin
  668. Day := (I + 5) mod 7;
  669. ShortDayNames[I]:=GetLocaleStr(LID,LOCALE_SABBREVDAYNAME1+Day,ShortDayNames[i]);
  670. LongDayNames[I]:=GetLocaleStr(LID,LOCALE_SDAYNAME1+Day,LongDayNames[i]);
  671. end;
  672. DateSeparator := GetLocaleChar(LID, LOCALE_SDATE, '/');
  673. ShortDateFormat := GetLocaleStr(LID, LOCALE_SSHORTDATE, 'm/d/yy');
  674. LongDateFormat := GetLocaleStr(LID, LOCALE_SLONGDATE, 'mmmm d, yyyy');
  675. { Time stuff }
  676. TimeSeparator := GetLocaleChar(LID, LOCALE_STIME, ':');
  677. TimeAMString := GetLocaleStr(LID, LOCALE_S1159, 'AM');
  678. TimePMString := GetLocaleStr(LID, LOCALE_S2359, 'PM');
  679. if StrToIntDef(GetLocaleStr(LID, LOCALE_ITLZERO, '0'), 0) = 0 then
  680. HF:='h'
  681. else
  682. HF:='hh';
  683. // No support for 12 hour stuff at the moment...
  684. ShortTimeFormat := HF+':nn';
  685. LongTimeFormat := HF + ':nn:ss';
  686. { Currency stuff }
  687. CurrencyString:=GetLocaleStr(LID, LOCALE_SCURRENCY, '');
  688. CurrencyFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRENCY, '0'), 0);
  689. NegCurrFormat:=StrToIntDef(GetLocaleStr(LID, LOCALE_INEGCURR, '0'), 0);
  690. { Number stuff }
  691. ThousandSeparator:=GetLocaleChar(LID, LOCALE_STHOUSAND, ',');
  692. DecimalSeparator:=GetLocaleChar(LID, LOCALE_SDECIMAL, '.');
  693. CurrencyDecimals:=StrToIntDef(GetLocaleStr(LID, LOCALE_ICURRDIGITS, '0'), 0);
  694. ListSeparator := GetLocaleChar(LID, LOCALE_SLIST, ',');
  695. end;
  696. end;
  697. procedure GetFormatSettings;
  698. begin
  699. GetlocaleFormatSettings(GetThreadLocale, DefaultFormatSettings);
  700. end;
  701. Procedure InitInternational;
  702. var
  703. { A call to GetSystemMetrics changes the value of the 8087 Control Word on
  704. Pentium4 with WinXP SP2 }
  705. old8087CW: word;
  706. DefaultCustomLocaleID : LCID; // typedef DWORD LCID;
  707. DefaultCustomLanguageID : Word; // typedef WORD LANGID;
  708. begin
  709. /// workaround for Windows 7 bug, see bug report #18574
  710. SetThreadLocale(GetUserDefaultLCID);
  711. InitInternationalGeneric;
  712. old8087CW:=Get8087CW;
  713. SysLocale.MBCS:=GetSystemMetrics(SM_DBCSENABLED)<>0;
  714. SysLocale.RightToLeft:=GetSystemMetrics(SM_MIDEASTENABLED)<>0;
  715. SysLocale.DefaultLCID := $0409;
  716. SysLocale.PriLangID := LANG_ENGLISH;
  717. SysLocale.SubLangID := SUBLANG_ENGLISH_US;
  718. // probably needs update with getthreadlocale. post 2.0.2
  719. DefaultCustomLocaleID := GetThreadLocale;
  720. if DefaultCustomLocaleID <> 0 then
  721. begin
  722. { Locale Identifiers
  723. +-------------+---------+-------------------------+
  724. | Reserved | Sort ID | Language ID |
  725. +-------------+---------+-------------------------+
  726. 31 20 19 16 15 0 bit }
  727. DefaultCustomLanguageID := DefaultCustomLocaleID and $FFFF; // 2^16
  728. if DefaultCustomLanguageID <> 0 then
  729. begin
  730. SysLocale.DefaultLCID := DefaultCustomLocaleID;
  731. { Language Identifiers
  732. +-------------------------+-------------------------+
  733. | SubLanguage ID | Primary Language ID |
  734. +-------------------------+-------------------------+
  735. 15 10 9 0 bit }
  736. SysLocale.PriLangID := DefaultCustomLanguageID and $3ff; // 2^10
  737. SysLocale.SubLangID := DefaultCustomLanguageID shr 10;
  738. end;
  739. end;
  740. Set8087CW(old8087CW);
  741. GetFormatSettings;
  742. if SysLocale.FarEast then GetEraNamesAndYearOffsets;
  743. end;
  744. {****************************************************************************
  745. Target Dependent
  746. ****************************************************************************}
  747. function SysErrorMessage(ErrorCode: Integer): String;
  748. const
  749. MaxMsgSize = Format_Message_Max_Width_Mask;
  750. var
  751. MsgBuffer: pChar;
  752. begin
  753. GetMem(MsgBuffer, MaxMsgSize);
  754. FillChar(MsgBuffer^, MaxMsgSize, #0);
  755. FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM,
  756. nil,
  757. ErrorCode,
  758. MakeLangId(LANG_NEUTRAL, SUBLANG_DEFAULT),
  759. MsgBuffer, { This function allocs the memory }
  760. MaxMsgSize, { Maximum message size }
  761. nil);
  762. SysErrorMessage := StrPas(MsgBuffer);
  763. FreeMem(MsgBuffer, MaxMsgSize);
  764. end;
  765. {****************************************************************************
  766. Initialization code
  767. ****************************************************************************}
  768. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  769. var
  770. s : string;
  771. i : longint;
  772. hp,p : pchar;
  773. begin
  774. Result:='';
  775. p:=GetEnvironmentStrings;
  776. hp:=p;
  777. while hp^<>#0 do
  778. begin
  779. s:=strpas(hp);
  780. i:=pos('=',s);
  781. if uppercase(copy(s,1,i-1))=upcase(envvar) then
  782. begin
  783. Result:=copy(s,i+1,length(s)-i);
  784. break;
  785. end;
  786. { next string entry}
  787. hp:=hp+strlen(hp)+1;
  788. end;
  789. FreeEnvironmentStrings(p);
  790. end;
  791. Function GetEnvironmentVariableCount : Integer;
  792. var
  793. hp,p : pchar;
  794. begin
  795. Result:=0;
  796. p:=GetEnvironmentStrings;
  797. hp:=p;
  798. If (Hp<>Nil) then
  799. while hp^<>#0 do
  800. begin
  801. Inc(Result);
  802. hp:=hp+strlen(hp)+1;
  803. end;
  804. FreeEnvironmentStrings(p);
  805. end;
  806. Function GetEnvironmentString(Index : Integer) : String;
  807. var
  808. hp,p : pchar;
  809. begin
  810. Result:='';
  811. p:=GetEnvironmentStrings;
  812. hp:=p;
  813. If (Hp<>Nil) then
  814. begin
  815. while (hp^<>#0) and (Index>1) do
  816. begin
  817. Dec(Index);
  818. hp:=hp+strlen(hp)+1;
  819. end;
  820. If (hp^<>#0) then
  821. Result:=StrPas(HP);
  822. end;
  823. FreeEnvironmentStrings(p);
  824. end;
  825. function ExecuteProcess(Const Path: AnsiString; Const ComLine: AnsiString;Flags:TExecuteFlags=[]):integer;
  826. // win specific function
  827. var
  828. SI: TStartupInfo;
  829. PI: TProcessInformation;
  830. Proc : THandle;
  831. l : DWord;
  832. CommandLine : ansistring;
  833. e : EOSError;
  834. ExecInherits : longbool;
  835. begin
  836. FillChar(SI, SizeOf(SI), 0);
  837. SI.cb:=SizeOf(SI);
  838. SI.wShowWindow:=1;
  839. { always surround the name of the application by quotes
  840. so that long filenames will always be accepted. But don't
  841. do it if there are already double quotes, since Win32 does not
  842. like double quotes which are duplicated!
  843. }
  844. if pos('"',path)=0 then
  845. CommandLine:='"'+path+'"'
  846. else
  847. CommandLine:=path;
  848. if ComLine <> '' then
  849. CommandLine:=Commandline+' '+ComLine+#0
  850. else
  851. CommandLine := CommandLine + #0;
  852. ExecInherits:=ExecInheritsHandles in Flags;
  853. if not CreateProcess(nil, pchar(CommandLine),
  854. Nil, Nil, ExecInherits,$20, Nil, Nil, SI, PI) then
  855. begin
  856. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  857. e.ErrorCode:=GetLastError;
  858. raise e;
  859. end;
  860. Proc:=PI.hProcess;
  861. if WaitForSingleObject(Proc, dword($ffffffff)) <> $ffffffff then
  862. begin
  863. GetExitCodeProcess(Proc,l);
  864. CloseHandle(Proc);
  865. CloseHandle(PI.hThread);
  866. result:=l;
  867. end
  868. else
  869. begin
  870. e:=EOSError.CreateFmt(SExecuteProcessFailed,[CommandLine,GetLastError]);
  871. e.ErrorCode:=GetLastError;
  872. CloseHandle(Proc);
  873. CloseHandle(PI.hThread);
  874. raise e;
  875. end;
  876. end;
  877. function ExecuteProcess(Const Path: AnsiString; Const ComLine: Array of AnsiString;Flags:TExecuteFlags=[]):integer;
  878. var
  879. CommandLine: AnsiString;
  880. I: integer;
  881. begin
  882. Commandline := '';
  883. for I := 0 to High (ComLine) do
  884. if Pos (' ', ComLine [I]) <> 0 then
  885. CommandLine := CommandLine + ' ' + '"' + ComLine [I] + '"'
  886. else
  887. CommandLine := CommandLine + ' ' + Comline [I];
  888. ExecuteProcess := ExecuteProcess (Path, CommandLine,Flags);
  889. end;
  890. Procedure Sleep(Milliseconds : Cardinal);
  891. begin
  892. Windows.Sleep(MilliSeconds)
  893. end;
  894. Function GetLastOSError : Integer;
  895. begin
  896. Result:=GetLastError;
  897. end;
  898. {****************************************************************************
  899. Initialization code
  900. ****************************************************************************}
  901. var
  902. kernel32dll : THandle;
  903. Procedure LoadVersionInfo;
  904. // and getfreespaceex
  905. Var
  906. versioninfo : TOSVERSIONINFO;
  907. begin
  908. GetDiskFreeSpaceEx:=nil;
  909. versioninfo.dwOSVersionInfoSize:=sizeof(versioninfo);
  910. GetVersionEx(versioninfo);
  911. Win32Platform:=versionInfo.dwPlatformId;
  912. Win32MajorVersion:=versionInfo.dwMajorVersion;
  913. Win32MinorVersion:=versionInfo.dwMinorVersion;
  914. Win32BuildNumber:=versionInfo.dwBuildNumber;
  915. Move (versioninfo.szCSDVersion ,Win32CSDVersion[1],128);
  916. win32CSDVersion[0]:=chr(strlen(pchar(@versioninfo.szCSDVersion)));
  917. kernel32dll:=GetModuleHandle('kernel32');
  918. if kernel32dll<>0 then
  919. GetDiskFreeSpaceEx:=TGetDiskFreeSpaceEx(GetProcAddress(kernel32dll,'GetDiskFreeSpaceExA'));
  920. end;
  921. Function GetAppConfigDir(Global : Boolean) : String;
  922. begin
  923. If Global then
  924. Result:=GetWindowsSpecialDir(CSIDL_COMMON_APPDATA)
  925. else
  926. Result:=GetWindowsSpecialDir(CSIDL_LOCAL_APPDATA);
  927. If (Result<>'') then
  928. begin
  929. if VendorName<>'' then
  930. Result:=IncludeTrailingPathDelimiter(Result+VendorName);
  931. Result:=IncludeTrailingPathDelimiter(Result+ApplicationName);
  932. end
  933. else
  934. Result:=IncludeTrailingPathDelimiter(DGetAppConfigDir(Global));
  935. end;
  936. Function GetAppConfigFile(Global : Boolean; SubDir : Boolean) : String;
  937. begin
  938. result:=DGetAppConfigFile(Global,SubDir);
  939. end;
  940. Function GetUserDir : String;
  941. begin
  942. Result:=GetWindowsSpecialDir(CSIDL_PROFILE);
  943. end;
  944. Procedure InitSysConfigDir;
  945. begin
  946. SetLength(SysConfigDir, MAX_PATH);
  947. SetLength(SysConfigDir, GetWindowsDirectory(PChar(SysConfigDir), MAX_PATH));
  948. end;
  949. {****************************************************************************
  950. Target Dependent WideString stuff
  951. ****************************************************************************}
  952. { This is the case of Win9x. Limited to current locale of course, but it's better
  953. than not working at all. }
  954. function DoCompareStringA(P1, P2: PWideChar; L1, L2: PtrUInt; Flags: DWORD): PtrInt;
  955. var
  956. a1, a2: AnsiString;
  957. begin
  958. if L1>0 then
  959. widestringmanager.Wide2AnsiMoveProc(P1,a1,L1);
  960. if L2>0 then
  961. widestringmanager.Wide2AnsiMoveProc(P2,a2,L2);
  962. SetLastError(0);
  963. Result:=CompareStringA(LOCALE_USER_DEFAULT,Flags,pchar(a1),
  964. length(a1),pchar(a2),length(a2))-2;
  965. end;
  966. function DoCompareStringW(P1, P2: PWideChar; L1, L2: PtrUInt; Flags: DWORD): PtrInt;
  967. begin
  968. SetLastError(0);
  969. Result:=CompareStringW(LOCALE_USER_DEFAULT,Flags,P1,L1,P2,L2)-2;
  970. if GetLastError=0 then
  971. Exit;
  972. if GetLastError=ERROR_CALL_NOT_IMPLEMENTED then // Win9x case
  973. Result:=DoCompareStringA(P1, P2, L1, L2, Flags);
  974. if GetLastError<>0 then
  975. RaiseLastOSError;
  976. end;
  977. function Win32CompareWideString(const s1, s2 : WideString) : PtrInt;
  978. begin
  979. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), 0);
  980. end;
  981. function Win32CompareTextWideString(const s1, s2 : WideString) : PtrInt;
  982. begin
  983. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), NORM_IGNORECASE);
  984. end;
  985. function Win32AnsiUpperCase(const s: string): string;
  986. begin
  987. if length(s)>0 then
  988. begin
  989. result:=s;
  990. UniqueString(result);
  991. CharUpperBuff(pchar(result),length(result));
  992. end
  993. else
  994. result:='';
  995. end;
  996. function Win32AnsiLowerCase(const s: string): string;
  997. begin
  998. if length(s)>0 then
  999. begin
  1000. result:=s;
  1001. UniqueString(result);
  1002. CharLowerBuff(pchar(result),length(result));
  1003. end
  1004. else
  1005. result:='';
  1006. end;
  1007. function Win32AnsiCompareStr(const S1, S2: string): PtrInt;
  1008. begin
  1009. result:=CompareString(LOCALE_USER_DEFAULT,0,pchar(s1),length(s1),
  1010. pchar(s2),length(s2))-2;
  1011. end;
  1012. function Win32AnsiCompareText(const S1, S2: string): PtrInt;
  1013. begin
  1014. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,pchar(s1),length(s1),
  1015. pchar(s2),length(s2))-2;
  1016. end;
  1017. function Win32AnsiStrComp(S1, S2: PChar): PtrInt;
  1018. begin
  1019. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,-1,s2,-1)-2;
  1020. end;
  1021. function Win32AnsiStrIComp(S1, S2: PChar): PtrInt;
  1022. begin
  1023. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,-1,s2,-1)-2;
  1024. end;
  1025. function Win32AnsiStrLComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1026. begin
  1027. result:=CompareString(LOCALE_USER_DEFAULT,0,s1,maxlen,s2,maxlen)-2;
  1028. end;
  1029. function Win32AnsiStrLIComp(S1, S2: PChar; MaxLen: PtrUInt): PtrInt;
  1030. begin
  1031. result:=CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,s1,maxlen,s2,maxlen)-2;
  1032. end;
  1033. function Win32AnsiStrLower(Str: PChar): PChar;
  1034. begin
  1035. CharLower(str);
  1036. result:=str;
  1037. end;
  1038. function Win32AnsiStrUpper(Str: PChar): PChar;
  1039. begin
  1040. CharUpper(str);
  1041. result:=str;
  1042. end;
  1043. function Win32CompareUnicodeString(const s1, s2 : UnicodeString) : PtrInt;
  1044. begin
  1045. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), 0);
  1046. end;
  1047. function Win32CompareTextUnicodeString(const s1, s2 : UnicodeString) : PtrInt;
  1048. begin
  1049. Result:=DoCompareStringW(PWideChar(s1), PWideChar(s2), Length(s1), Length(s2), NORM_IGNORECASE);
  1050. end;
  1051. { there is a similiar procedure in the system unit which inits the fields which
  1052. are relevant already for the system unit }
  1053. procedure InitWin32Widestrings;
  1054. begin
  1055. { return value: number of code points in the string. Whenever an invalid
  1056. code point is encountered, all characters part of this invalid code point
  1057. are considered to form one "character" and the next character is
  1058. considered to be the start of a new (possibly also invalid) code point }
  1059. //!!! CharLengthPCharProc : function(const Str: PChar): PtrInt;
  1060. { return value:
  1061. -1 if incomplete or invalid code point
  1062. 0 if NULL character,
  1063. > 0 if that's the length in bytes of the code point }
  1064. //!!!! CodePointLengthProc : function(const Str: PChar; MaxLookAead: PtrInt): Ptrint;
  1065. widestringmanager.CompareWideStringProc:=@Win32CompareWideString;
  1066. widestringmanager.CompareTextWideStringProc:=@Win32CompareTextWideString;
  1067. widestringmanager.UpperAnsiStringProc:=@Win32AnsiUpperCase;
  1068. widestringmanager.LowerAnsiStringProc:=@Win32AnsiLowerCase;
  1069. widestringmanager.CompareStrAnsiStringProc:=@Win32AnsiCompareStr;
  1070. widestringmanager.CompareTextAnsiStringProc:=@Win32AnsiCompareText;
  1071. widestringmanager.StrCompAnsiStringProc:=@Win32AnsiStrComp;
  1072. widestringmanager.StrICompAnsiStringProc:=@Win32AnsiStrIComp;
  1073. widestringmanager.StrLCompAnsiStringProc:=@Win32AnsiStrLComp;
  1074. widestringmanager.StrLICompAnsiStringProc:=@Win32AnsiStrLIComp;
  1075. widestringmanager.StrLowerAnsiStringProc:=@Win32AnsiStrLower;
  1076. widestringmanager.StrUpperAnsiStringProc:=@Win32AnsiStrUpper;
  1077. widestringmanager.CompareUnicodeStringProc:=@Win32CompareUnicodeString;
  1078. widestringmanager.CompareTextUnicodeStringProc:=@Win32CompareTextUnicodeString;
  1079. end;
  1080. Initialization
  1081. InitWin32Widestrings;
  1082. InitExceptions; { Initialize exceptions. OS independent }
  1083. InitInternational; { Initialize internationalization settings }
  1084. LoadVersionInfo;
  1085. InitSysConfigDir;
  1086. OnBeep:=@SysBeep;
  1087. Finalization
  1088. DoneExceptions;
  1089. end.