Recent

Author Topic: [solved] GetDesktopPath  (Read 5715 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
[solved] GetDesktopPath
« 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.
« Last Edit: October 22, 2020, 07:56:24 pm by Handoko »

ASerge

  • Hero Member
  • *****
  • Posts: 2212
Re: GetDesktopPath
« Reply #1 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);

Lulu

  • Full Member
  • ***
  • Posts: 226
Re: GetDesktopPath
« Reply #2 on: October 20, 2020, 08:35:18 pm »
Tested on win10: both Handoko and ASerge code work
wishing you a nice life

kapibara

  • Hero Member
  • *****
  • Posts: 610
Re: GetDesktopPath
« Reply #3 on: October 20, 2020, 10:37:44 pm »
Tested OK with XUbuntu 20.04.
Lazarus trunk / fpc 3.2.2 / Kubuntu 22.04 - 64 bit

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: GetDesktopPath
« Reply #4 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 :-)

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: GetDesktopPath
« Reply #5 on: October 22, 2020, 07:56:08 pm »
Thank you all for testing it and the suggestions.

 

TinyPortal © 2005-2018