I.T. Discussion Community!
-Collapse +Expand
Search Delphi Group:

-Collapse +Expand Delphi To/From
-Collapse +Expand Delphi Store

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Single User Apps Topic   Print This     

How toSimultaneously load a data file and applicat

How toSimultaneously load a data file and applicat in Delphi Single User Apps topic (part of our Pascal and Delphi Coding group).

Quick Search: toSimultaneously   applicat   How toSimultaneously   How toSimultaneously load   data file  
-- USA
How do you get an application to simultaneously load and load a data file that has been double clicked on or opened? Of course, I realize that you need to associate the file with the program first.
 Posted 14 years ago (Thread Starter)
Comment Quote
About kes103 -Collapse +Expand
Visit Profile
Membership pending.
Member subscribes to this thread but email is NOT VERIFIED.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #11480, 1 replies
Thread Started 6/7/2006 1:20:00 PM
View Counter=2348
Location=-- USA 
Joined=14 years ago   MB Posts=5  
Most Recent Post
Wes Peterson
Prestwood IT
Prestwood IT office in Citrus Heights, CA
It's quite easy, and the mechansim for doing it has been around since the DOS days.

When the OS launches your program, it hands your progam a list of one or more parameters. These are always strings, and there is always at least one.

That first parameter is always your program's fully qualified path name:

"C:\Program Files\Me\MyProgram.exe" for instance.

That may seem silly, but it's actually quite useful. More about that after answering your question.

If a user double-clicks a file in Windows Explorer, and its file extension is registred with your program, Windows launches your program and passes the clicked file's fully qualified path as the second parameter.

So, in your program's startup code, you'd inspect the list of parameters to see if there's a second one and, if so, open that file.

It gets better. Suppose the user has shift-clicked on several files, then right-clicks and selects Open. The OS passes them all in the list of parameters. If your program is capable of opening multiple files simultaneously, it would scan the list of parameters, from the second one to the last one, and open each file.

OK, so how do you access that list of parameters?

It depends on your programming language. Delphi provides a global, ParamCount, which tells you how many parameters were passed to your program when the OS launched it. Delphi also provides a function, ParamStr which will provide the string at a given index within the list.

ParamStr(0) will always return your programs own path. So you're interested in ParamStr(1) and, possibly, 2, 3 and so on.

Here's a code snippet that demonstrates one way to do what you want:

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
  for i := 1 to ParamCount - 1 do

Of course, if your program can deal with only one file at a time, you can ignore the business of iterating over all the params and just use ParamStr(1).

Now - what's the use of ParamStr(0)? Why would your program ever need its own program name?

It wouldn't. But having its fully qualified path can be very handy indeed. Your program may be started from virutally any directory available. Remember, no matter how carefully you craft your installation program to ensure that it installs shortcuts that start it in its own installation folder, users (dang them critters) may create less meticulous shortucts - or do other strange things to start your program.

If your program has help files, an INI file, a license file, data files, or other important files in (or below) its installation folder, you need a bulletproof way to find them - no matter how the user caused your program to be launched.

ExtractFilePath(ParamStr(0)) will always return your program's installation folder.

Wes Peterson
Senior Software Engineer
Prestwood IT Solutions

 Posted 14 years ago
Comment Quote
About Wes Peterson -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About Wes Peterson

Wes Peterson is a Senior Programmer Analyst with Prestwood IT Solutions where he develops custom Windows software and custom websites using .Net and Delphi. When Wes is not coding for clients, he participates in this online community. Prior to his 10-year love-affair with Delphi, he worked with several other tools and databases. Currently he specializes in VS.Net using C# and VB.Net. To Wes, the .NET revolution is as exciting as the birth of Delphi.

Post ID #11481 (Level 1.1)  Reply to 11480
Thread Started 6/7/2006 3:00:00 PM
View Counter=2
Location=Prestwood IT office in Citrus Heights, CA 
Joined=16 years ago   MB Posts=158   KB Posts=163   KB Comments=34   BLOG, Topics=20  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1223A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #11480 Counter
Since 4/2/2008

Follow PrestwoodBoards on: 

©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech