Mega Code Archive

 
Categories / Delphi / Strings
 

Parameter Strings

Title: Parameter Strings Question: How to use parameters that windows send. Answer: When you edit a file type in explorer and add a new action (Win98 View-Folder Options File Types Tag) you can specify the name of your own application. Windows will send you a parameter that will tell you what the file is that the user clicked on when he performed the action you created. To get the file name you can use the following code (This code is not tested in Delphi but should work) function GetFile:String; var i:integer; begin Result:=''; for i:=1 to ParamCount do Result:=Result+ParamStr(I); end; This will give a result like eg:'C:\Autoexec.bat' The reason for using a loop is that every space in a file name is treated as a break in the parameter and is send as a different one. The filename "c:\program files\accesories\wordpad.exe" will be split into 2 parameters between "program" and "files" If you want the location of you exe do the following var Location:String begin Location:=ParamStr(0); end; In this case even if the filename of your exe contains a space it will return the whole path