[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get Windows, System and Temp dir ?

Posted on 2006-05-10
7
Medium Priority
?
1,066 Views
Last Modified: 2010-08-05
I need a code to get Windows, System and Temp dir. I'm using delphi 2005.

Thank you !
0
Comment
Question by:65zgtre45rr
  • 3
  • 3
7 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 16655040
Mind you, I don't know delphi, so if this doesn't work for you, I don't know what else to tell you, but I would suggest getting the environment variables and referencing those.  This link explains how to do that (or so it seems):

http://www.chami.com/tips/delphi/010997D.html
0
 
LVL 10

Expert Comment

by:Jacco
ID: 16655291
Hi

Uses Windows;

 function GetTempDir: string;
  begin;
    SetLength(Result, MAX_PATH);
    SetLength(Result, GetTempPath(MAX_PATH, (PChar(Result))));
  end;

  function GetSystemDir: string;
  begin;
    SetLength(Result, MAX_PATH);
    SetLength(Result, GetSystemDirectory((PChar(Result)), MAX_PATH));
  end;

  function GetWindowsDir: string;
  begin;
    SetLength(Result, MAX_PATH);
    SetLength(Result, GetWindowsDirectory(PChar(Result), MAX_PATH));
  end;

Regards Jacco

0
 

Author Comment

by:65zgtre45rr
ID: 16695426
I get this error with your code:

[Error] Main.pas(83): E2089 Invalid typecast

on line SetLength(Result, GetTempPath(MAX_PATH, (PChar(Result))));

There is somthing wrong with paramter (PChar(Result)))


I'm using delphi 2005
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:Jacco
ID: 16696158
What personality do you use? I gave the Win32 version not a .NET one (either VCL.NET or WinForms)

I tested with Delphi 2005 without problem (Win32 VCL application).

Regards Jacco

0
 

Author Comment

by:65zgtre45rr
ID: 16701583
i'm using .net vcl
0
 

Author Comment

by:65zgtre45rr
ID: 16722636
So can some one solve this, problem is with Pchar
0
 
LVL 10

Accepted Solution

by:
Jacco earned 750 total points
ID: 16723758
uses
  System.Text;

  function GetTempDir: string;
  var
    s: StringBuilder;
  begin;
    s := StringBuilder.Create(MAX_PATH);
    GetTempPath(MAX_PATH, s);
    Result := s.ToString;
  end;

  function GetSystemDir: string;
  var
    s: StringBuilder;
  begin;
    s := StringBuilder.Create(MAX_PATH);
    GetSystemDirectory(s, MAX_PATH);
    Result := s.ToString;
  end;

  function GetWindowsDir: string;
  var
    s: StringBuilder;
  begin;
    s := StringBuilder.Create(MAX_PATH);
    GetWindowsDirectory(s, MAX_PATH);
    Result := s.ToString;
  end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add(GetTempDir);
  Memo1.Lines.Add(GetSystemDir);
  Memo1.Lines.Add(GetWindowsDir);
end;

Regards Jacco
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question