Solved

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

Posted on 2011-03-22
6
4,097 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now