Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Packages in anderem Verzeichnis (https://www.delphipraxis.net/215891-packages-anderem-verzeichnis.html)

himitsu 23. Sep 2024 14:35

AW: Packages in anderem Verzeichnis
 
Anstatt des Suchpfad des Parent-Prozesses zu verpfuschen,
wäre es bestimmt schöner das Environment als Parameter an CreateProcess zu übergeben. :stupid:

Kas Ob. 23. Sep 2024 16:49

AW: Packages in anderem Verzeichnis
 
Zitat:

Zitat von himitsu (Beitrag 1541415)
Anstatt des Suchpfad des Parent-Prozesses zu verpfuschen,
wäre es bestimmt schöner das Environment als Parameter an CreateProcess zu übergeben. :stupid:

Not sure about how nicer it will be (nicer is what translation gave me), see if Environment block is nil then process called with CreateProcess will use the parent process, if you to fill or pass anything in CreateProcess then it will be used instead of the default, meaning you should pass the same as parent process, or you are in lot of missing variables and default paths, and here comes the headache,..
Reading the Environment to pass it from parent to child, the block in whole should be read and passed, and it will be in this structure
Zitat:

name=value\0
Yes each variable will be null-terminated line, handling this is ... well doable but avoidable, and i prefer to avoid messing and parsing so much null-terminated lines, just to find PATH variable and then add my paths, then pass it with CreateProcess.

So, no.. (for me at least) it is not nicer at all.

himitsu 23. Sep 2024 19:08

AW: Packages in anderem Verzeichnis
 
Delphi-Quellcode:
  var Environment := TStringList.Create;
  Environment.TrailingLineBreak := True;
  Environment.LineBreak := #0;

  //Environment.StrictDelimiter := True;
  //Environment.Delimiter := #0;
  //Environment.DelimitedText := GetEnvironmentStrings;
  var P := GetEnvironmentStrings;
  var S: String;
  while P <> '' do begin
    Environment.Add(P);
    Inc(P, Succ(Length(P)));
  end;

  Environment.Values['PATH'] := Environment.Values['PATH'] + ';' + TPath.Combine(TPath.GetAppPath, 'Version_1.0.0');

  var Test := Environment.Text;
  //CreateProcess(ApplicationName, CommandLine, ProcessAttributes, ThreadAttributes, InheritHandles, CreationFlags, PChar(Environment.Text), CurrentDirectory, StartupInfo, ProcessInformation);

Kas Ob. 24. Sep 2024 07:34

AW: Packages in anderem Verzeichnis
 
Zitat:

Zitat von himitsu (Beitrag 1541428)
Delphi-Quellcode:
  var Environment := TStringList.Create;
  Environment.TrailingLineBreak := True;
  Environment.LineBreak := #0;

  //Environment.StrictDelimiter := True;
  //Environment.Delimiter := #0;
  //Environment.DelimitedText := GetEnvironmentStrings;
  var P := GetEnvironmentStrings;
  var S: String;
  while P <> '' do begin
    Environment.Add(P);
    Inc(P, Succ(Length(P)));
  end;

  Environment.Values['PATH'] := Environment.Values['PATH'] + ';' + TPath.Combine(TPath.GetAppPath, 'Version_1.0.0');

  var Test := Environment.Text;
  //CreateProcess(ApplicationName, CommandLine, ProcessAttributes, ThreadAttributes, InheritHandles, CreationFlags, PChar(Environment.Text), CurrentDirectory, StartupInfo, ProcessInformation);

Well, that is nice !

Alas, i can't repeat it on my XE8, and neither it will work on older versions.

On side note: Environment.Text should add an extra null char (two zeros bytes when used with CreateProcess), so it should be PChar(Environment.Text + #0), of course assuming the last line has the null terminator, if not then it should be added also, and that honestly because i never used StringList with #0 as LineBreak, it gives me goosebumps.


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:59 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