Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.415 Beiträge
 
Delphi 7 Professional
 
#7

AW: ShellExcecute Formulierung

  Alt 4. Feb 2022, 09:59
Das ist aber eher Zufall:
Delphi-Quellcode:
InPath := '"C:\Users\Geldis\Projekt 7\IN"';
Params := InPath + '\sample.jpg -w 256 -h 256 -ft tga -o ' + OutPath;
Das müsste wohl eher so aussehen:
Delphi-Quellcode:
InPath := 'C:\Users\Geldis\Projekt 7\IN';
Params := '"' + InPath + '\sample.jpg" -w 256 -h 256 -ft tga -o ' + OutPath;
Die doppelten Hochkommata müssen (eigentlich) den kompletten Dateinamen, also Pfad und Dateinamen, umschließen und nicht nur den Pfad.

Wie wird das denn, wenn der Dateiname auch Leerzeichen enthält?
Delphi-Quellcode:
InPath := '"C:\Users\Geldis\Projekt 7\IN"';
Params := InPath + '"\sample 1.jpg" -w 256 -h 256 -ft tga -o ' + OutPath;
oder
Delphi-Quellcode:
InPath := '"C:\Users\Geldis\Projekt 7\IN"';
Params := InPath + '\"sample 1.jpg" -w 256 -h 256 -ft tga -o ' + OutPath;
Bei mir sähe das eher so aus:
Delphi-Quellcode:
WorkFile := '"C:\Users\Geldis\Projekt 7\PIC\polon.exe"';
OutPath := 'C:\Users\Geldis\Projekt 7\OUT\';
InPath := 'C:\Users\Geldis\Projekt 7\IN\';
InFile := 'sample.jpg';
Params := Format('"%s%s" -w 256 -h 256 -ft tga -o "%s"',[InPath,InFile,OutPath]);
if ShellExecute(0, 'open', PChar(WorkFile), PChar(Params), nil, SW_HIDE) <= 32 then
begin
  Fehlerbehandlung, Fehlermeldung ...
end;
Und der Rückgabewert von ShellExecute wird abgefragt. Immer!

Das Ganze erscheint mir noch überarbeitungswürdig. Eine verlässliche Funktionsweise würd' ich bei Deiner momentane Lösung eher nicht erwarten.

Geändert von Delphi.Narium ( 4. Feb 2022 um 10:04 Uhr) Grund: Fehler korrigiert
  Mit Zitat antworten Zitat