views:

1045

answers:

4

I am currently using:

if ParamStr(1)<>'%1' then
begin
  address.Text:=ParamStr(1);
  autoconfigfile;
end;

to pick up the name of the file that was used to open the file with via file association.

I now want to develop the ability to operate on multiple files. I.e. if I select 5 files and right click and select open with "EncryptionSystem". I have the registry entry:

  reg.OpenKey('*\shell\Encrypt\command', true);
  reg.WriteString('','C:\Program Files\EncryptionSystem\EncryptionSystem.exe "%1"');
  reg.CloseKey;

To add a right click open ability to all files. I would then want the ability to detect

  1. how many files
  2. the pathname of each file
A: 

Not sure what you really want. But you can find the number of parameters with:

ParamCount;

Each param is then found with

ParamStr(1);
ParamStr(2);
ParamStr(3);

Until ParamCount.

Gamecat
the paramcount passed the number of parameters add on the end of the file name.. apon opening 5 files there is just 1 param.
Arthur
A: 

I note that you are only registering it with %1.

I would try %1 %2 %3 %4 %5 etc in the registry.

I have never played with shell extensions to see what else might be making this fail. All I've done is registered file associations and they behave exactly as I would expect.

Loren Pechtel
+4  A: 

If you try to open multiple files at once you will generally get multiple instances of the registered program, each opening one of the files.

Now judging from your recent questions

How do i tell if one instance of my program is running?
How do I send a string from one instance of my Delphi program to another?

you do not wish to allow multiple instances of the program, so you will need to either reconsider that design decision, or implement one of the ways outlined in the answers to the second question to send the command line parameter of the secondary instances of your program to the first instance. Please note that timing is important here, because the first instance may well not yet be ready to receive the data from the other instances. Especially with solutions using the window handle of the main form, or some form of pipe- or file-based communication mechanism will involve waiting for the first instance to be ready. It may therefore be much easier to simply allow multiple instances of the program.

You may also want to look into this Microsoft Knowledge Base entry or search for more information about the DDE Execute command.

Edit: You could also try with "%*" instead of "%1" in the registry key, as detailed in the "Old New Thing" comment the answer by gabr mentioned. I haven't tested this, but it looks like it could work.

mghie
%* looks to be the one i want, will test it when i get home, does this supply the longname or the dos 8.3 version with "~"
Arthur
+4  A: 

Besides everything else, you should use %l instead of %1. That way your program will get a full (long) name of the file, not the short (DOS 8.3) one.

EDIT: An answer to Rob's question in comments

It seems that it's almost impossible to search for '%l' and '%1' (including percent sign) either using Google or MSDN search. :( However, I found a pretty good description in The Old New Thing - '%1' autodetects whether your program supports long file names and passes either short or long name. It seems that all modern systems pass long name unless your exe cannot be found (at least that's how I understand the Raymond's expose).

If you scroll further down in the comments (search for '%l' on the page) you'll find a list of all supported parameters, taken from some page that doesn't exist anymore (but I found an old copy in the Internet Archive). That page doesn't include no reference to Microsoft documentation either, so I can't give you an authoritative link :(

Rob, thank's for asking - I now know more about %1/%l than before :) +1 for that.

gabr
Got a citation for that?
Rob Kennedy
What's this - Wikipedia? ;)
gabr
If someone can fix the formatting of my edit, please go ahead - I can't find the problem (have no idea what causes whole paragraph and more to turn into hyperlink).
gabr
@gabr: Thanks for the link, there is indeed interesting information in the comment you mentioned.
mghie
Found the problem - double 'http:' in the Internet Archive links breaks the parser. Can be 'fixed' by escaping any of those four characters.
gabr