Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   application.exename (https://www.delphipraxis.net/193396-application-exename.html)

Uwe Raabe 26. Jul 2017 10:50

AW: application.exename
 
Zitat:

Zitat von Glados (Beitrag 1377503)
Schön wäre es dennoch und kürzeren Code hätte man dann auch.

Bitteschön:
Delphi-Quellcode:
interface

uses
  System.IOUtils;

type
  TPathHelper = record helper for TPath
  private
  public
    function GetDesktopFolder: string;
    function GetStartMenuFolder: string;
  end;

implementation

uses
  Winapi.SHFolder, Winapi.ShlObj;

function TPathHelper.GetDesktopFolder: string;
var
  LStr: array[0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);

  if SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

function TPathHelper.GetStartMenuFolder: string;
var
  LStr: array[0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);

  if SHGetFolderPath(0, CSIDL_STARTMENU, 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

Glados 26. Jul 2017 10:53

AW: application.exename
 
Ok an Class-Helper habe ich ehrlich gesagt nicht gedacht, da ich öfter mal Schlechtes darüber gelesen habe.
:thumb:

Fritzew 26. Jul 2017 11:22

AW: application.exename
 
Klasse!
Nur eine Kleinigkeit , Result sollte initialisiert werden.......



Zitat:

Zitat von Uwe Raabe (Beitrag 1377505)

Bitteschön:
Delphi-Quellcode:
interface

uses
  System.IOUtils;

type
  TPathHelper = record helper for TPath
  private
  public
    function GetDesktopFolder: string;
    function GetStartMenuFolder: string;
  end;

implementation

uses
  Winapi.SHFolder, Winapi.ShlObj;

function TPathHelper.GetDesktopFolder: string;
var
  LStr: array[0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);
  Result := ''; // Wenn schon denn Schon
  if SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

function TPathHelper.GetStartMenuFolder: string;
var
  LStr: array[0 .. MAX_PATH] of Char;
begin
  SetLastError(ERROR_SUCCESS);
 Result := ''; // Wenn schon denn Schon
  if SHGetFolderPath(0, CSIDL_STARTMENU, 0, 0, @LStr) = S_OK then
    Result := LStr;
end;

Zitat:

Zitat von Glados (Beitrag 1377503)
Ok jetzt weiß ich warum die Dinger verpöhnt sind - zumindest ich weiß nicht einmal wie man das benutzt.

Den Helper in eine Unit, diese einbinden wo die Funktionen daraus gebraucht werden und fertig.

Glados 26. Jul 2017 11:52

AW: application.exename
 
Ich habs jetzt so gemacht
Delphi-Quellcode:
var
 PathHelper: TPath;

Fritzew 26. Jul 2017 12:17

AW: application.exename
 
Zitat:

Zitat von Glados (Beitrag 1377511)
Ich habs jetzt so gemacht
Delphi-Quellcode:
var
 PathHelper: TPath;

Das brauchst Du nicht.
Einfach die Unit einbinden und dann zb :

Delphi-Quellcode:
 myDektop := Tpath.GetDesktopFolder;
Der ClassHelper erweitert Tpath um die funktionen

Luckie 26. Jul 2017 14:19

AW: application.exename
 
Ich hätte die Methoden allerdings GetWinDesktopFolder und GetWinStartMenuFolder genannt. Wenn dann noch welche für MacOS oder Linux dazu kommen, kann man sie auch entsprechend benennen und kommt nicht durcheinander.

Fritzew 26. Jul 2017 14:33

AW: application.exename
 
Zitat:

Zitat von Luckie (Beitrag 1377516)
Ich hätte die Methoden allerdings GetWinDesktopFolder und GetWinStartMenuFolder genannt. Wenn dann noch welche für MacOS oder Linux dazu kommen, kann man sie auch entsprechend benennen und kommt nicht durcheinander.

Wieso? Das ist doch der Zweck der CrossPlattform Routinen?
Wenn ich den Desktop will ist es doch egal ob ich aktuell unter Win oder OSX bin.
Ist doch z.B bei TPath.GetDownloadsPath genau so oder?

Luckie 26. Jul 2017 15:06

AW: application.exename
 
Äh. Ja. War ein Denkfehler von mir. :roll:


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:13 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz