AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Parsen von EnvironmentPath

Ein Thema von EWeiss · begonnen am 14. Aug 2018 · letzter Beitrag vom 14. Aug 2018
Antwort Antwort
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#1

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 07:38
Ich nutze eine Unit von Delphidabbler für Environment Parsing.
Wenn Dich das Interessieren sollte, hier ist der Link dahin.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Benutzerbild von Jasocul
Jasocul

Registriert seit: 22. Sep 2004
Ort: Delmenhorst
1.344 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 07:55
Ich nutze überhaupt nicht die Environment-Variablen, sondern die API-Funktion SHGetSpecialFolderLocation.
Meine Funktion sieht so aus (irgendwo mal aus dem Internet gefischt und angepasst):
Delphi-Quellcode:
function GetSpecialPath(aCSIDL : Integer) : String;
var
  shellMalloc: IMalloc;
  ppidl: PItemIdList;
begin
  ppidl := nil;
  try
    if SHGetMalloc(shellMalloc) = NOERROR then
    begin
      SHGetSpecialFolderLocation(Application.Handle, aCSIDL, ppidl);
      SetLength(Result, MAX_PATH);
      if not SHGetPathFromIDList(ppidl, PChar(Result)) then
      begin
        Result := '';
      end
      else
      begin
        SetLength(Result, lStrLen(PChar(Result)));
      end;
    end;
  finally
    if ppidl <> nil then
    begin
      shellMalloc.free(ppidl);
    end;
  end;
end;
Eine Liste der CSIDL-Werte ist hier zu finden:
https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
In deinem Fall müsste es wohl CSIDL_PROFILE sein.
Peter
  Mit Zitat antworten Zitat
Schokohase
(Gast)

n/a Beiträge
 
#3

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 07:59
Warum so kompliziert? Laut der Doku MSDN: ExpandEnvironmentStrings gilt für den lpSrc Parameter
Zitat:
A buffer that contains one or more environment-variable strings in the form: %variableName%. For each such reference, the %variableName% portion is replaced with the current value of that environment variable.
Also kann man sich das Ganze Aufsplitten sparen und '%HOMEDRIVE%%HOMEPATH%' in einem übergeben.

BTW:

Wer mit PWideChar arbeitet sollte auch konsequenterweise mit ExpandEnvironmentStringsW arbeiten, sonst ist bei der nächsten Umstellung (wie bei ANSI auf Unicode) das Geschrei wieder riesengross.

PS:

So würde diese Funktion bei mir aussehen:
Delphi-Quellcode:
function ExpandEnvironment( const AInput: string ): string;
var
  lResult: Cardinal;
begin
  lResult := Winapi.Windows.ExpandEnvironmentStrings( PChar(AInput), nil, 0 );

  if lResult = 0 then
    RaiseLastOSError( );

  SetLength( Result, lResult );
  lResult := Winapi.Windows.ExpandEnvironmentStrings( PChar(AInput), PChar( Result ), lResult );

  if lResult = 0 then
    RaiseLastOSError( );

  SetLength( Result, lResult - 1 );
end;

Geändert von Schokohase (14. Aug 2018 um 08:03 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 08:19
Ein wenig gekürzt bei gleicher funktionsweise abgesehen vom Errorcheck
Delphi-Quellcode:
function ExpandEnvironment(const AInput: string): string;
const
  MAXSIZE = 32768;
begin
  SetLength(Result, MAXSIZE);
  SetLength(Result, ExpandEnvironmentStrings(PChar(AInput), @Result[1], Length(Result)) - 1);
end;
edit
Wobei mir Jasoculs Vorschlag in diesen Zusammenhang auch besser gefällt.
Gruß vom KodeZwerg

Geändert von KodeZwerg (14. Aug 2018 um 08:54 Uhr)
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#5

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 12:20
Zitat:
sollte auch konsequenterweise mit ExpandEnvironmentStringsW arbeiten
Das Macht der Compiler btw. (Delphi) selbst wenn man mit WideChar arbeitet

Danke an alle werde es mal umsetzen..
Zitat:
Wobei mir Jasoculs Vorschlag in diesen Zusammenhang auch besser gefällt.
Die ist aber in dem Kontext nicht anwendbar.

Die übergabe des Arbeitspfad ist nun mal von MS festgelegt die da lautet %HOMEDRIVE%%HOMEPATH% und hat nichts mit einer CSIDL zu tun.
Es geht nicht darum was ich gern möchte sondern was vorgegeben ist.

Code:
"c:\program files (x86)\internet explorer\iexplore.exe, IExplorer, @PATH@UserIcon\48x48\IExplorer.png, @PATH@, , 1"
zu
Code:
"c:\program files (x86)\internet explorer\iexplore.exe, IExplorer, @PATH@UserIcon\48x48\IExplorer.png, %HOMEDRIVE%%HOMEPATH%, , 1"
gruss

Geändert von EWeiss (14. Aug 2018 um 12:35 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von Jasocul
Jasocul

Registriert seit: 22. Sep 2004
Ort: Delmenhorst
1.344 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Parsen von EnvironmentPath

  Alt 14. Aug 2018, 12:42
Die ist aber in dem Kontext nicht anwendbar.
Ah, du hast nur die die Environment-Variablen und willst deren Inhalt ermitteln. Dann hast du natürlich recht.
Peter
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz