Lazarus

Programming => Operating Systems => Topic started by: Handoko on October 20, 2020, 08:00:14 pm

Title: [solved] GetDesktopPath
Post by: Handoko on October 20, 2020, 08:00:14 pm
Can anyone help me test this code on Linuxes and Windows? I tested on Ubuntu Mate and WinXP, it works but I want to make sure it 'really' works. Or maybe you have better suggestion.

Code: Pascal  [Select][+][-]
  1. function GetDesktopPath: string;
  2. var
  3.   S: string;
  4. begin
  5. {$ifdef WINDOWS}
  6.   S := GetEnvironmentVariable('HOMEDRIVE') + GetEnvironmentVariable('HOMEPATH');
  7. {$endif}
  8. {$ifdef LINUX}
  9.   S := GetEnvironmentVariable('HOME');
  10. {$endif}
  11.   Result := S + DirectorySeparator + 'Desktop' + DirectorySeparator;
  12. end;

Note:
SysUtils unit is required.
Title: Re: GetDesktopPath
Post by: ASerge on October 20, 2020, 08:14:22 pm
Can anyone help me test this code on Linuxes and Windows? I tested on Ubuntu Mate and WinXP, it works but I want to make sure it 'really' works. Or maybe you have better suggestion.
Windows 7 - work. But it is more correct to use WinDirs.GetWindowsSpecialDir(CSIDL_DESKTOPDIRECTORY, False);
Title: Re: GetDesktopPath
Post by: Lulu on October 20, 2020, 08:35:18 pm
Tested on win10: both Handoko and ASerge code work
Title: Re: GetDesktopPath
Post by: kapibara on October 20, 2020, 10:37:44 pm
Tested OK with XUbuntu 20.04.
Title: Re: GetDesktopPath
Post by: trev on October 21, 2020, 01:20:33 am
Change:

Code: Pascal  [Select][+][-]
  1. {$ifdef LINUX}

To:

Code: Pascal  [Select][+][-]
  1. {$ifdef UNIX}

And it will now also work in macOS and FreeBSD (tested :-)
Title: Re: GetDesktopPath
Post by: Handoko on October 22, 2020, 07:56:08 pm
Thank you all for testing it and the suggestions.
TinyPortal © 2005-2018