home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / StartRight / source.zip / UnitUtils.pas < prev   
Pascal/Delphi Source File  |  2004-10-05  |  1KB  |  57 lines

  1. unit UnitUtils;
  2. {
  3.     Purpose: Miscelanous procedures that don't belong anywhere
  4. }
  5.  
  6. {///////////////}
  7. {//}interface{//}
  8. {///////////////}
  9.  
  10. procedure MySleep(milli : integer);
  11. function GetUsername: String;
  12. const UNKNOWN_USER = 'UnknownUser';
  13.  
  14. {////////////////////}
  15. {//}implementation{//}
  16. {////////////////////}
  17.  
  18. uses SysUtils, Windows, Forms;
  19.  
  20. procedure MySleep(milli : integer);
  21. var i, j : integer;
  22. begin
  23.     i := Windows.GetTickCount;
  24.     j := Windows.GetTickCount;
  25.     while ((j - i) <milli) do begin
  26.         Application.ProcessMessages;
  27.         sleep(100);
  28.         if (Application.Terminated) then EXIT;
  29.         j := Windows.GetTickCount;
  30.     end;
  31. end;
  32.  
  33.  
  34. function GetUsername: String;
  35. var userName : array[0..MAX_PATH] of char;
  36.     r : Integer;
  37.     len : cardinal;
  38. begin
  39.     result := UNKNOWN_USER;
  40.     {
  41.     try
  42.     }
  43.         FillChar(userName, sizeof(userName), #0);
  44.         len := sizeof(userName) - 1;
  45.  
  46.         r := WNetGetUser(PChar(nil), userName, len);
  47.         if (r = 0) then begin
  48.            result := string(userName);
  49.         end;
  50.     {
  51.     except
  52.     end;
  53.     }
  54. end;
  55.  
  56. end.
  57.