How can I handle parameters with spaces in Delphi?

My program accepts input file names either as command line parameters, either in a drag and drop operation or in Explorer, clicking on file names with the extension associated with my program.

The command line and drag and drop work fine, but click on the file names in Explorer, which cause problems when the file paths of the files they were clicked on have spaces in them, for example:

c:\temp\file one.txt c:\my directory\filetwo.txt c:\my directory\file three.txt 

then the ParamStr function returns me:

 ParamStr(1): c:\temp\file ParamStr(2): one.txt ParamStr(3): c:\my ParamStr(4): directory\filetwo.txt ParamStr(5): c:\my ParamStr(6): directory\file ParamStr(7): three.txt 

How can I best restore them back to the three file names that I need?

+4
source share
3 answers

Your shell file association may not include the "" pair.

Like these for opening:

 "C:\Program Files\WinRAR\WinRAR.exe" "%1" 

or with a DDE message:

 [open("%1")] 
+7
source

Command line options with spaces in them, such as file names, must be specified. This makes the parser-parser realize that it needs to keep them together. If the user does not quote the file name, this is an operator error.

If the drag and drop system does this, on the other hand, then you have a bug in your drag and drop library and you need to talk to the person who created it. I'm a little confused, however, about why drag and drop operations are messy with ParamStr. This should be set only by the parameters passed to your program at the time of its call, and not after its launch and launch. Maybe I missed something?

+3
source

I am using the CmdLineHelper block, from here .

+2
source

All Articles