3

I want to write a small app that does some data manipulation on the contents of a simple text file.

I just want to be able to right click such a file, choose 'Open with' in Windows, select my app, then the app opens, parses the file, does some stuff and closes immediately again.

Question: when my app starts, how do I get the file name that triggered the app to start?

Thanks!

9
  • @kobik - That would be the answer. Commented Oct 3, 2012 at 15:03
  • Oh great! I knew it must have been somthing simple like that, but when I tried Googling it, I really couldn't find this... Thanks! Commented Oct 3, 2012 at 15:04
  • @Son - Don't forget to test for ParamCount. Commented Oct 3, 2012 at 15:08
  • @SertacAkyuz, I wonder who deleted my comment and why? Commented Oct 3, 2012 at 17:14
  • @kobik - Interesting. I wonder why who deleted your comment did not delete mine.. Commented Oct 3, 2012 at 17:22

1 Answer 1

6

You get the file as parameter number 1.
You can get it with the function ParamStr(1).

Have a look here for more details:
http://www.delphibasics.co.uk/RTL.asp?Name=ParamStr

For your information, ParamStr(0) is the filename (including complete path) of your EXE application.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm curious. Why link to delphibasics rather than the actual documentation? docwiki.embarcadero.com/Libraries/en/System.ParamStr
And ParamStr(0) is the same thing as Application.ExeName, btw.
@DavidHeffernan Very bad experience with Delphi documentation (you know, since Delphi7 blablabla ...) so I'm still using so (old) bookmark :)
@DavidHeffernan Because DelphiBasics is awesome and Embarcadero documentation is total crap. They should just take the good, old Delphi7 documentation and publish on the website.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.