Recent

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

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • 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: 1694
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: 126
Re: GetDesktopPath
« Reply #2 on: October 20, 2020, 08:35:18 pm »
Tested on win10: both Handoko and ASerge code work
fpc 3.2.0 Lazarus 2.0.10  -  AMD A8-6600K  -  Windows 10  64bits

kapibara

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

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1071
  • 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 :-)
o Lazarus v2.1.0 r63871, FPC v3.3.1 r47164, macOS 10.14.6, Xcode 11.3.1
o Lazarus v2.1.0 r64160, FPC v3.3.1 Nov 27 21:16:31, macOS 11.0.1 (aarch64), Xcode 12.2
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware VM)
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 20.04 (PD VM)

Handoko

  • Hero Member
  • *****
  • Posts: 3913
  • 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