sysutils.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. { Read filename handling functions implementation }
  12. {$i fina.inc}
  13. { variant error codes }
  14. {$i varerror.inc}
  15. Function FileSearch (Const Name, DirList : String; Options : TFileSearchoptions = [sfoImplicitCurrentDir]) : String;
  16. Var
  17. I : longint;
  18. Temp : String;
  19. begin
  20. Result:=Name;
  21. temp:=SetDirSeparators(DirList);
  22. // Start with checking the file in the current directory
  23. If (sfoImplicitCurrentDir in Options) and (Result <> '') and FileExists(Result) Then
  24. exit;
  25. while True do begin
  26. If Temp = '' then
  27. Break; // No more directories to search - fail
  28. I:=pos(PathSeparator,Temp);
  29. If I<>0 then
  30. begin
  31. Result:=Copy (Temp,1,i-1);
  32. system.Delete(Temp,1,I);
  33. end
  34. else
  35. begin
  36. Result:=Temp;
  37. Temp:='';
  38. end;
  39. If Result<>'' then
  40. begin
  41. If (sfoStripQuotes in Options) and (Result[1]='"') and (Result[Length(Result)]='"') then
  42. Result:=Copy(Result,2,Length(Result)-2);
  43. if (Result<>'') then
  44. Result:=IncludeTrailingPathDelimiter(Result)+name;
  45. end;
  46. If (Result <> '') and FileExists(Result) Then
  47. exit;
  48. end;
  49. result:='';
  50. end;
  51. Function FileSearch (Const Name, DirList : String; ImplicitCurrentDir : Boolean) : String;
  52. begin
  53. if ImplicitCurrentDir then
  54. Result:=FileSearch(Name,DirList,[sfoImplicitCurrentDir])
  55. else
  56. Result:=FileSearch(Name,DirList,[]);
  57. end;
  58. Function ExeSearch (Const Name : String; Const DirList : String ='' ) : String;
  59. Var
  60. D : String;
  61. O : TFileSearchOptions;
  62. begin
  63. D:=DirList;
  64. if (D='') then
  65. D:=GetEnvironmentVariable('PATH');
  66. {$ifdef unix}
  67. O:=[];
  68. {$else unix}
  69. O:=[sfoImplicitCurrentDir,sfoStripQuotes];
  70. {$endif unix}
  71. Result := FileSearch(Name, D, False);
  72. end;
  73. {$ifndef OS_FILEISREADONLY}
  74. Function FileIsReadOnly(const FileName: String): Boolean;
  75. begin
  76. Result := (FileGetAttr(FileName) and faReadOnly) <> 0;
  77. end;
  78. {$endif OS_FILEISREADONLY}
  79. {$ifndef OS_FILESETDATEBYNAME}
  80. Function FileSetDate (Const FileName : String;Age : Longint) : Longint;
  81. Var
  82. fd : THandle;
  83. begin
  84. { at least windows requires fmOpenWrite here }
  85. fd:=FileOpen(FileName,fmOpenWrite);
  86. If (Fd<>feInvalidHandle) then
  87. try
  88. Result:=FileSetDate(fd,Age);
  89. finally
  90. FileClose(fd);
  91. end
  92. else
  93. {$ifdef HAS_OSERROR}
  94. Result:=GetLastOSError;
  95. {$else}
  96. Result:=-1;
  97. {$endif}
  98. end;
  99. {$endif}
  100. { Read String Handling functions implementation }
  101. {$i sysstr.inc}
  102. { Read date & Time function implementations }
  103. {$ifndef FPUNONE}
  104. {$i dati.inc}
  105. {$endif}
  106. { Read pchar handling functions implementation }
  107. {$i syspch.inc}
  108. { generic internationalisation code }
  109. {$i sysint.inc}
  110. { MCBS functions }
  111. {$i sysansi.inc}
  112. { wide string functions }
  113. {$i syswide.inc}
  114. {$ifdef FPC_HAS_UNICODESTRING}
  115. { unicode string functions }
  116. {$i sysuni.inc}
  117. {$endif FPC_HAS_UNICODESTRING}
  118. { threading stuff }
  119. {$i sysuthrd.inc}
  120. { OS utility code }
  121. {$i osutil.inc}
  122. procedure FreeAndNil(var obj);
  123. var
  124. temp: tobject;
  125. begin
  126. temp:=tobject(obj);
  127. pointer(obj):=nil;
  128. temp.free;
  129. end;
  130. { Interfaces support }
  131. {$i sysuintf.inc}
  132. constructor Exception.Create(const msg : string);
  133. begin
  134. inherited create;
  135. fmessage:=msg;
  136. end;
  137. constructor Exception.CreateFmt(const msg : string; const args : array of const);
  138. begin
  139. inherited create;
  140. fmessage:=Format(msg,args);
  141. end;
  142. constructor Exception.CreateRes(ResString: PString);
  143. begin
  144. inherited create;
  145. fmessage:=ResString^;
  146. end;
  147. constructor Exception.CreateResFmt(ResString: PString; const Args: array of const);
  148. begin
  149. inherited create;
  150. fmessage:=Format(ResString^,args);
  151. end;
  152. constructor Exception.CreateHelp(const Msg: string; AHelpContext: Integer);
  153. begin
  154. inherited create;
  155. fmessage:=Msg;
  156. fhelpcontext:=AHelpContext;
  157. end;
  158. constructor Exception.CreateFmtHelp(const Msg: string; const Args: array of const;
  159. AHelpContext: Integer);
  160. begin
  161. inherited create;
  162. fmessage:=Format(Msg,args);
  163. fhelpcontext:=AHelpContext;
  164. end;
  165. constructor Exception.CreateResHelp(ResString: PString; AHelpContext: Integer);
  166. begin
  167. inherited create;
  168. fmessage:=ResString^;
  169. fhelpcontext:=AHelpContext;
  170. end;
  171. constructor Exception.CreateResFmtHelp(ResString: PString; const Args: array of const;
  172. AHelpContext: Integer);
  173. begin
  174. inherited create;
  175. fmessage:=Format(ResString^,args);
  176. fhelpcontext:=AHelpContext;
  177. end;
  178. procedure EHeapMemoryError.FreeInstance;
  179. begin
  180. if AllowFree then
  181. inherited FreeInstance;
  182. end;
  183. Constructor EVariantError.CreateCode (Code : longint);
  184. begin
  185. case Code of
  186. VAR_OK:
  187. Create(SNoError);
  188. VAR_PARAMNOTFOUND:
  189. Create(SVarParamNotFound);
  190. VAR_TYPEMISMATCH:
  191. Create(SInvalidVarCast);
  192. VAR_BADVARTYPE:
  193. Create(SVarBadType);
  194. VAR_OVERFLOW:
  195. Create(SVarOverflow);
  196. VAR_BADINDEX:
  197. Create(SVarArrayBounds);
  198. VAR_ARRAYISLOCKED:
  199. Create(SVarArrayLocked);
  200. VAR_NOTIMPL:
  201. Create(SVarNotImplemented);
  202. VAR_OUTOFMEMORY:
  203. Create(SVarOutOfMemory);
  204. VAR_INVALIDARG:
  205. Create(SVarInvalid);
  206. VAR_UNEXPECTED,
  207. VAR_EXCEPTION:
  208. Create(SVarUnexpected);
  209. else
  210. CreateFmt(SUnknownErrorCode,[Code]);
  211. end;
  212. ErrCode:=Code;
  213. end;
  214. {$push}
  215. {$S-}
  216. Procedure CatchUnhandledException (Obj : TObject; Addr: Pointer; FrameCount: Longint; Frames: PPointer);[public,alias:'FPC_BREAK_UNHANDLED_EXCEPTION'];
  217. Var
  218. Message : String;
  219. i : longint;
  220. hstdout : ^text;
  221. begin
  222. hstdout:=@stdout;
  223. Writeln(hstdout^,'An unhandled exception occurred at $',HexStr(PtrUInt(Addr),sizeof(PtrUInt)*2),' :');
  224. if Obj is exception then
  225. begin
  226. Message:=Exception(Obj).ClassName+' : '+Exception(Obj).Message;
  227. Writeln(hstdout^,Message);
  228. end
  229. else
  230. Writeln(hstdout^,'Exception object ',Obj.ClassName,' is not of class Exception.');
  231. Writeln(hstdout^,BackTraceStrFunc(Addr));
  232. if (FrameCount>0) then
  233. begin
  234. for i:=0 to FrameCount-1 do
  235. Writeln(hstdout^,BackTraceStrFunc(Frames[i]));
  236. end;
  237. Writeln(hstdout^,'');
  238. end;
  239. Var OutOfMemory : EOutOfMemory;
  240. InValidPointer : EInvalidPointer;
  241. Procedure RunErrorToExcept (ErrNo : Longint; Address,Frame : Pointer);
  242. Var E : Exception;
  243. HS : PString;
  244. begin
  245. Case Errno of
  246. 1,203 : E:=OutOfMemory;
  247. 204 : E:=InvalidPointer;
  248. 2,3,4,5,6,100,101,102,103,105,106 : { I/O errors }
  249. begin
  250. Case Errno of
  251. 2 : HS:=@SFileNotFound;
  252. 3 : HS:=@SInvalidFileName;
  253. 4 : HS:=@STooManyOpenFiles;
  254. 5 : HS:=@SAccessDenied;
  255. 6 : HS:=@SInvalidFileHandle;
  256. 15 : HS:=@SInvalidDrive;
  257. 100 : HS:=@SEndOfFile;
  258. 101 : HS:=@SDiskFull;
  259. 102 : HS:=@SFileNotAssigned;
  260. 103 : HS:=@SFileNotOpen;
  261. 104 : HS:=@SFileNotOpenForInput;
  262. 105 : HS:=@SFileNotOpenForOutput;
  263. 106 : HS:=@SInvalidInput;
  264. end;
  265. E:=EinOutError.Create (HS^);
  266. // this routine can be called from FPC_IOCHECK,
  267. // which clears inoutres and then passes its
  268. // original value to HandleErrorFrame() (which calls
  269. // us). So use errno rather than IOResult, and clear
  270. // InOutRes explicitly in case we can also be called
  271. // from a place that does not clear InOutRes explicitly
  272. EInoutError(E).ErrorCode:=errno;
  273. inoutres:=0;
  274. end;
  275. // We don't set abstracterrorhandler, but we do it here.
  276. // Unless the use sets another handler we'll get here anyway...
  277. 200 : E:=EDivByZero.Create(SDivByZero);
  278. 201 : E:=ERangeError.Create(SRangeError);
  279. 205 : E:=EOverflow.Create(SOverflow);
  280. 206 : E:=EOverflow.Create(SUnderflow);
  281. 207 : E:=EInvalidOp.Create(SInvalidOp);
  282. 211 : E:=EAbstractError.Create(SAbstractError);
  283. 212 : E:=EExternalException.Create(SExternalException);
  284. 214 : E:=EBusError.Create(SBusError);
  285. 215 : E:=EIntOverflow.Create(SIntOverflow);
  286. 216 : E:=EAccessViolation.Create(SAccessViolation);
  287. 217 : E:=EControlC.Create(SControlC);
  288. 218 : E:=EPrivilege.Create(SPrivilege);
  289. 219 : E:=EInvalidCast.Create(SInvalidCast);
  290. 220 : E:=EVariantError.Create(SInvalidVarCast);
  291. 221 : E:=EVariantError.Create(SInvalidVarOp);
  292. 222 : E:=EVariantError.Create(SDispatchError);
  293. 223 : E:=EVariantError.Create(SVarArrayCreate);
  294. 224 : E:=EVariantError.Create(SVarNotArray);
  295. 225 : E:=EVariantError.Create(SVarArrayBounds);
  296. 227 : E:=EAssertionFailed.Create(SAssertionFailed);
  297. 228 : E:=EIntfCastError.Create(SIntfCastError);
  298. 229 : E:=ESafecallException.Create(SSafecallException);
  299. 231 : E:=EConvertError.Create(SiconvError);
  300. 232 : E:=ENoThreadSupport.Create(SNoThreadSupport);
  301. 233 : E:=ENoWideStringSupport.Create(SSigQuit);
  302. 234 : E:=ENoWideStringSupport.Create(SMissingWStringManager);
  303. else
  304. E:=Exception.CreateFmt (SUnKnownRunTimeError,[Errno]);
  305. end;
  306. Raise E at Address,Frame;
  307. end;
  308. {$IFDEF HAS_OSERROR}
  309. Procedure RaiseLastOSError;
  310. var
  311. ECode: Cardinal;
  312. E : EOSError;
  313. begin
  314. ECode := GetLastOSError;
  315. If (ECode<>0) then
  316. E:=EOSError.CreateFmt(SOSError, [ECode, SysErrorMessage(ECode)])
  317. else
  318. E:=EOSError.Create(SUnkOSError);
  319. E.ErrorCode:=ECode;
  320. Raise E;
  321. end;
  322. {$else}
  323. Procedure RaiseLastOSError;
  324. begin
  325. Raise Exception.Create('RaiseLastOSError not implemented on this platform.');
  326. end;
  327. {$endif}
  328. Procedure AssertErrorHandler (Const Msg,FN : ShortString;LineNo:longint; TheAddr : pointer);
  329. Var
  330. S : String;
  331. begin
  332. If Msg='' then
  333. S:=SAssertionFailed
  334. else
  335. S:=Msg;
  336. Raise EAssertionFailed.Createfmt(SAssertError,[S,Fn,LineNo]) at get_caller_addr(theAddr), get_caller_frame(theAddr);
  337. end;
  338. {$pop} //{$S-} for Error handling functions
  339. Procedure InitExceptions;
  340. {
  341. Must install uncaught exception handler (ExceptProc)
  342. and install exceptions for system exceptions or signals.
  343. (e.g: SIGSEGV -> ESegFault or so.)
  344. }
  345. begin
  346. ExceptionClass := Exception;
  347. ExceptProc:=@CatchUnhandledException;
  348. // Create objects that may have problems when there is no memory.
  349. OutOfMemory:=EOutOfMemory.Create(SOutOfMemory);
  350. OutOfMemory.AllowFree:=false;
  351. InvalidPointer:=EInvalidPointer.Create(SInvalidPointer);
  352. InvalidPointer.AllowFree:=false;
  353. AssertErrorProc:=@AssertErrorHandler;
  354. ErrorProc:=@RunErrorToExcept;
  355. OnShowException:=Nil;
  356. end;
  357. Procedure DoneExceptions;
  358. begin
  359. OutOfMemory.AllowFree:=true;
  360. OutOfMemory.Free;
  361. InValidPointer.AllowFree:=true;
  362. InValidPointer.Free;
  363. end;
  364. { Exception handling routines }
  365. function ExceptObject: TObject;
  366. begin
  367. If RaiseList=Nil then
  368. Result:=Nil
  369. else
  370. Result:=RaiseList^.FObject;
  371. end;
  372. function ExceptAddr: Pointer;
  373. begin
  374. If RaiseList=Nil then
  375. Result:=Nil
  376. else
  377. Result:=RaiseList^.Addr;
  378. end;
  379. function ExceptFrameCount: Longint;
  380. begin
  381. If RaiseList=Nil then
  382. Result:=0
  383. else
  384. Result:=RaiseList^.Framecount;
  385. end;
  386. function ExceptFrames: PPointer;
  387. begin
  388. If RaiseList=Nil then
  389. Result:=Nil
  390. else
  391. Result:=RaiseList^.Frames;
  392. end;
  393. function ExceptionErrorMessage(ExceptObject: TObject; ExceptAddr: Pointer;
  394. Buffer: PChar; Size: Integer): Integer;
  395. Var
  396. S : AnsiString;
  397. Len : Integer;
  398. begin
  399. S:=Format(SExceptionErrorMessage,[ExceptAddr,ExceptObject.ClassName]);
  400. If ExceptObject is Exception then
  401. S:=Format('%s:'#10'%s',[S,Exception(ExceptObject).Message]);
  402. Len:=Length(S);
  403. If S[Len]<>'.' then
  404. begin
  405. S:=S+'.';
  406. Inc(len);
  407. end;
  408. If Len>Size then
  409. Len:=Size;
  410. if Len > 0 then
  411. Move(S[1],Buffer^,Len);
  412. Result:=Len;
  413. end;
  414. procedure ShowException(ExceptObject: TObject; ExceptAddr: Pointer);
  415. // use shortstring. On exception, the heap may be corrupt.
  416. Var
  417. Buf : ShortString;
  418. begin
  419. SetLength(Buf,ExceptionErrorMessage(ExceptObject,ExceptAddr,@Buf[1],255));
  420. If IsConsole Then
  421. writeln(Buf)
  422. else
  423. If Assigned(OnShowException) Then
  424. OnShowException (Buf);
  425. end;
  426. procedure Abort;
  427. begin
  428. Raise EAbort.Create(SAbortError) at Pointer(Get_Caller_addr(Get_Frame));
  429. end;
  430. procedure OutOfMemoryError;
  431. begin
  432. Raise OutOfMemory;
  433. end;
  434. { ---------------------------------------------------------------------
  435. Initialization/Finalization/exit code
  436. ---------------------------------------------------------------------}
  437. Type
  438. PPRecord = ^TPRecord;
  439. TPRecord = Record
  440. Func : TTerminateProc;
  441. NextFunc : PPRecord;
  442. end;
  443. Const
  444. TPList : PPRecord = Nil;
  445. procedure AddTerminateProc(TermProc: TTerminateProc);
  446. Var
  447. TPR : PPRecord;
  448. begin
  449. New(TPR);
  450. With TPR^ do
  451. begin
  452. NextFunc:=TPList;
  453. Func:=TermProc;
  454. end;
  455. TPList:=TPR;
  456. end;
  457. function CallTerminateProcs: Boolean;
  458. Var
  459. TPR : PPRecord;
  460. begin
  461. Result:=True;
  462. TPR:=TPList;
  463. While Result and (TPR<>Nil) do
  464. begin
  465. Result:=TPR^.Func();
  466. TPR:=TPR^.NextFunc;
  467. end;
  468. end;
  469. { ---------------------------------------------------------------------
  470. Diskh functions, OS independent.
  471. ---------------------------------------------------------------------}
  472. function ForceDirectories(Const Dir: string): Boolean;
  473. var
  474. E: EInOutError;
  475. ADrv : String;
  476. function DoForceDirectories(Const Dir: string): Boolean;
  477. var
  478. ADir : String;
  479. APath: String;
  480. begin
  481. Result:=True;
  482. ADir:=ExcludeTrailingPathDelimiter(Dir);
  483. if (ADir='') then Exit;
  484. if Not DirectoryExists(ADir) then
  485. begin
  486. APath := ExtractFilePath(ADir);
  487. //this can happen on Windows if user specifies Dir like \user\name/test/
  488. //and would, if not checked for, cause an infinite recusrsion and a stack overflow
  489. if (APath = ADir) then Result := False
  490. else Result:=DoForceDirectories(APath);
  491. If Result then
  492. Result := CreateDir(ADir);
  493. end;
  494. end;
  495. function IsUncDrive(const Drv: String): Boolean;
  496. begin
  497. Result := (Length(Drv) > 2) and (Drv[1] = PathDelim) and (Drv[2] = PathDelim);
  498. end;
  499. begin
  500. Result := False;
  501. ADrv := ExtractFileDrive(Dir);
  502. if (ADrv<>'') and (not DirectoryExists(ADrv))
  503. {$IFNDEF FORCEDIR_NO_UNC_SUPPORT} and (not IsUncDrive(ADrv)){$ENDIF} then Exit;
  504. if Dir='' then
  505. begin
  506. E:=EInOutError.Create(SCannotCreateEmptyDir);
  507. E.ErrorCode:=3;
  508. Raise E;
  509. end;
  510. Result := DoForceDirectories(SetDirSeparators(Dir));
  511. end;
  512. Var
  513. GUIDCalledRandomize : Boolean = False;
  514. Procedure GetRandomBytes(Var Buf; NBytes : Integer);
  515. Var
  516. I : Integer;
  517. P : PByte;
  518. begin
  519. P:=@Buf;
  520. If Not GUIDCalledRandomize then
  521. begin
  522. Randomize;
  523. GUIDCalledRandomize:=True;
  524. end;
  525. For I:=0 to NBytes-1 do
  526. P[i]:=Random(256);
  527. end;
  528. {$IFDEF HASCREATEGUID}
  529. Function SysCreateGUID(out GUID : TGUID) : Integer; forward;
  530. {$ENDIF}
  531. Function CreateGUID(out GUID : TGUID) : Integer;
  532. begin
  533. If Assigned(OnCreateGUID) then
  534. Result:=OnCreateGUID(GUID)
  535. else
  536. begin
  537. {$IFDEF HASCREATEGUID}
  538. Result:=SysCreateGUID(GUID);
  539. {$ELSE}
  540. GetRandomBytes(GUID,SizeOf(Guid));
  541. guid.clock_seq_hi_and_reserved:=(guid.clock_seq_hi_and_reserved and $3F) + 64;
  542. guid.time_hi_and_version :=(guid.time_hi_and_version and $0FFF)+ $4000;
  543. Result:=0;
  544. {$ENDIF}
  545. end;
  546. end;
  547. function SafeLoadLibrary(const FileName: AnsiString;
  548. ErrorMode: DWord = {$ifdef windows}SEM_NOOPENFILEERRORBOX{$else windows}0{$endif windows}): HMODULE;
  549. {$if defined(cpui386) or defined(cpux86_64)}
  550. var
  551. mode : DWord;
  552. fpucw : Word;
  553. ssecw : DWord;
  554. {$endif}
  555. begin
  556. {$if defined(win64) or defined(win32)}
  557. mode:=SetErrorMode(ErrorMode);
  558. {$endif}
  559. try
  560. {$if defined(cpui386) or defined(cpux86_64)}
  561. fpucw:=Get8087CW;
  562. {$ifdef cpui386}
  563. if has_sse_support then
  564. {$endif cpui386}
  565. ssecw:=GetSSECSR;
  566. {$endif}
  567. {$if defined(windows) or defined(win32)}
  568. Result:=LoadLibraryA(PChar(Filename));
  569. {$else}
  570. Result:=0;
  571. {$endif}
  572. finally
  573. {$if defined(cpui386) or defined(cpux86_64)}
  574. Set8087CW(fpucw);
  575. {$ifdef cpui386}
  576. if has_sse_support then
  577. {$endif cpui386}
  578. SetSSECSR(ssecw);
  579. {$endif}
  580. {$if defined(win64) or defined(win32)}
  581. SetErrorMode(mode);
  582. {$endif}
  583. end;
  584. end;
  585. function GetModuleName(Module: HMODULE): string;
  586. begin
  587. {$ifdef MSWINDOWS}
  588. SetLength(Result,MAX_PATH);
  589. SetLength(Result,GetModuleFileName(Module, Pchar(Result),Length(Result)));
  590. {$ELSE}
  591. Result:='';
  592. {$ENDIF}
  593. end;
  594. { Beep support }
  595. procedure Beep;
  596. begin
  597. If Assigned(OnBeep) then
  598. OnBeep;
  599. end;