Mar 14
Copy Code To Clipboard
  1. { Getting the Windows Directory }    
  2.   
  3. function GetWinDir: string;    
  4. var    
  5.   dir: array [0..MAX_PATH] of Char;    
  6. begin    
  7.   GetWindowsDirectory(dir, MAX_PATH);    
  8.   Result := StrPas(dir);    
  9. end;    
  10.   
  11. function WindowsDirectory: string;    
  12. var    
  13.   WinDir: PChar;    
  14. begin    
  15.   WinDir := StrAlloc(MAX_PATH);    
  16.   GetWindowsDirectory(WinDir, MAX_PATH);    
  17.   Result := string(WinDir);    
  18.   if Result[Length(Result)] <> '\' then    
  19.     Result := Result + '\';    
  20.   StrDispose(WinDir);    
  21. end;    
  22.   
  23. function GetWindowsDirectory(var S: String): Boolean;    
  24. var    
  25.   Len: Integer;    
  26. begin    
  27.   Len := Windows.GetWindowsDirectory(nil, 0);    
  28.   if Len > 0 then    
  29.   begin    
  30.     SetLength(S, Len);    
  31.     Len := Windows.GetWindowsDirectory(PChar(S), Len);    
  32.     SetLength(S, Len);    
  33.     Result := Len > 0;    
  34.   end else    
  35.     Result := False;    
  36. end;    
  37. { Getting the System Directory }    
  38.   
  39. function SystemDir: string;    
  40. var    
  41.   dir: array [0..MAX_PATH] of Char;    
  42. begin    
  43.   GetSystemDirectory(dir, MAX_PATH);    
  44.   Result := StrPas(dir);    
  45. end;    
  46.   
  47. function SystemDirectory: string;    
  48. var    
  49.   SysDir: PChar;    
  50. begin    
  51.   SysDir := StrAlloc(MAX_PATH);    
  52.   GetSystemDirectory(SysDir, MAX_PATH);    
  53.   Result := string(SysDir);    
  54.   if Result[Length(Result)] <> '\' then    
  55.     Result := Result + '\';    
  56.   StrDispose(SysDir);    
  57. end;    
  58.   
  59. function GetSystemDirectory(var S: String): Boolean;    
  60. var    
  61.   Len: Integer;    
  62. begin    
  63.   Len := Windows.GetSystemDirectory(nil, 0);    
  64.   if Len > 0 then    
  65.   begin    
  66.     SetLength(S, Len);    
  67.     Len := Windows.GetSystemDirectory(PChar(S), Len);    
  68.     SetLength(S, Len);    
  69.     Result := Len > 0;    
  70.   end else    
  71.     Result := False;    
  72. end;    
  73. { Getting the Temporary Directory }    
  74.   
  75. function GetTempDir: string;    
  76. var    
  77.   Buffer: array[0..MAX_PATH] of Char;    
  78. begin    
  79.   GetTempPath(SizeOf(Buffer) - 1, Buffer);    
  80.   Result := StrPas(Buffer);    
  81. end;    
  82.   
  83. function GetTempPath: string;    
  84. var    
  85.   TmpDir: PChar;    
  86. begin    
  87.   TmpDir := StrAlloc(MAX_PATH);    
  88.   GetTempPath(TmpDir, MAX_PATH);    
  89.   Result := string(TmpDir);    
  90.   if Result[Length(Result)] <> '\' then    
  91.     Result := Result + '\';    
  92.   StrDispose(TmpDir);    
  93. end;    
  94.   
  95. function GetTempPath(var S: String): Boolean;    
  96. var    
  97.   Len: Integer;    
  98. begin    
  99.   Len := Windows.GetTempPath(0, nil);    
  100.   if Len > 0 then    
  101.   begin    
  102.     SetLength(S, Len);    
  103.     Len := Windows.GetTempPath(Len, PChar(S));    
  104.     SetLength(S, Len);    
  105.     Result := Len > 0;    
  106.   end else    
  107.     Result := False;    
  108. end;    
  109.   
  110. procedure TForm1.Button1Click(Sender: TObject);    
  111. begin    
  112.   label1.Caption := GetWinDir;    
  113.   label2.Caption := GetSysDir;    
  114.   label3.Caption := GetTempDir;    
  115. end;   

 

Tags: , , ,
分页: 1/1 第一页 1 最后页 [ 显示模式: 摘要 | 列表 ]