Solved

How do I get System Path(Desktop) with Delphi2010?

Posted on 2011-03-22
6
4,302 Views
Last Modified: 2012-05-11
function GetSystemPath(Folder: Integer): string;
var
  PIDL: PItemIDList;
  Path: LPSTR;
  AMalloc: IMalloc;
begin
  Path := StrAlloc(MAX_PATH);
  SHGetSpecialFolderLocation(Application.Handle, Folder, PIDL);

  if SHGetPathFromIDList(PIDL, Path) then Result := Path;

  SHGetMalloc(AMalloc);
  AMalloc.Free(PIDL);
  StrDispose(Path);
end;

Open in new window



Usage:

Showmessage(GetSystemPath(CSIDL_DESKTOPDIRECTORY));

-----------------------------------------------------------------------------

I normaly use function above on Delphi7, How do i convert it into Delphi 2010?

Thanks Expert!

0
Comment
Question by:charin1904
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 35192906
You can use this under Delphi 2010...
function GetSysDir: string;
var
  Buffer: array[0..MAX_PATH + 1] of Char;
begin
  GetSystemDirectory(Buffer, MAX_PATH);
  Result := Buf;
end;

Open in new window

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 500 total points
ID: 35192940
If you absolutely want to use SHGetSpecialFolderLocation(), then try this...


function GetFolderLocation(Handle: HWnd; dir: Integer): string;
var
  pidl: PItemIDList;
  buffer: array[0..MAX_PATH] of Char;
begin
  if Succeeded(SHGetSpecialFolderLocation(Handle, dir, pidl)) then begin
    if SHGetPathFromIDList(pidl, buffer) then
      Result:=buffer;
    CoTaskMemFree(pidl);
  end
  else
    Result:=SysErrorMessage(GetLastError());
end;

Open in new window

0
 

Author Comment

by:charin1904
ID: 35192985
Hi Thommy,

I"m sorry, question not clear, I need a "Desktop" Folder not system's folder :)

It something like:   C:\Users\Charin\Desktop

How do i get it?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

Accepted Solution

by:
charin1904 earned 0 total points
ID: 35193128
uses      ShlObj, ComObj, ActiveX,

procedure TForm1.Button1Click(Sender: TObject);
var
  PIDL: PItemIDList;
  Path: array[0..MAX_PATH] of Char;
begin
  SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, PIDL);
  SHGetPathFromIDList(PIDL, Path);
  showmessage(StrPas(Path));
end;

Open in new window


OK., I got it!
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35196495
Thank you for the points...

:o)))
0
 

Author Closing Comment

by:charin1904
ID: 35225431
I got solution guided by Thommy.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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