was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

35 Visitors Online


 
...Windows, System, Temporär Verzeichnis ermitteln?
Autor: Rainer Kümmerle
Homepage: http://www.thinklazy.de
[ Tip ausdrucken ]  

Tip Bewertung (16):  
     


{ Getting the Windows Directory }

function GetWinDir: string;
var
  
dir: array [0..MAX_PATH] of Char;
begin
  
GetWindowsDirectory(dir, MAX_PATH);
  Result := StrPas(dir);
end;

// or:

function WindowsDirectory: string;
var
  
WinDir: PChar;
begin
  
WinDir := StrAlloc(MAX_PATH);
  GetWindowsDirectory(WinDir, MAX_PATH);
  Result := string(WinDir);
  if Result[Length(Result)] <> '\' then
    
Result := Result + '\';
  StrDispose(WinDir);
end;

// or:

function GetWindowsDirectory(var S: String): Boolean;
var
  
Len: Integer;
begin
  
Len := Windows.GetWindowsDirectory(nil, 0);
  if Len > 0 then
  begin
    
SetLength(S, Len);
    Len := Windows.GetWindowsDirectory(PChar(S), Len);
    SetLength(S, Len);
    Result := Len > 0;
  end else
    
Result := False;
end;

{ Getting the System Directory }

function SystemDir: string;
var
  
dir: array [0..MAX_PATH] of Char;
begin
  
GetSystemDirectory(dir, MAX_PATH);
  Result := StrPas(dir);
end;

// or:

function SystemDirectory: string;
var
  
SysDir: PChar;
begin
  
SysDir := StrAlloc(MAX_PATH);
  GetSystemDirectory(SysDir, MAX_PATH);
  Result := string(SysDir);
  if Result[Length(Result)] <> '\' then
    
Result := Result + '\';
  StrDispose(SysDir);
end;

// or:

function GetSystemDirectory(var S: String): Boolean;
var
  
Len: Integer;
begin
  
Len := Windows.GetSystemDirectory(nil, 0);
  if Len > 0 then
  begin
    
SetLength(S, Len);
    Len := Windows.GetSystemDirectory(PChar(S), Len);
    SetLength(S, Len);
    Result := Len > 0;
  end else
    
Result := False;
end;

{ Getting the Temporary Directory }

function GetTempDir: string;
var
  
Buffer: array[0..MAX_PATH] of Char;
begin
  
GetTempPath(SizeOf(Buffer) - 1, Buffer);
  Result := StrPas(Buffer);
end;

// or:

function GetTempPath: string;
var
  
TmpDir: PChar;
begin
  
TmpDir := StrAlloc(MAX_PATH);
  GetTempPath(TmpDir, MAX_PATH);
  Result := string(TmpDir);
  if Result[Length(Result)] <> '\' then
    
Result := Result + '\';
  StrDispose(TmpDir);
end;

// or:

function GetTempPath(var S: String): Boolean;
var
  
Len: Integer;
begin
  
Len := Windows.GetTempPath(0, nil);
  if Len > 0 then
  begin
    
SetLength(S, Len);
    Len := Windows.GetTempPath(Len, PChar(S));
    SetLength(S, Len);
    Result := Len > 0;
  end else
    
Result := False;
end;

// ****************************

// Example Calls:

procedure TForm1.Button1Click(Sender: TObject);
begin
  
label1.Caption := GetWinDir;
  label2.Caption := GetSysDir;
  label3.Caption := GetTempDir;
end;






 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners