Solved

my program can take parameters

Posted on 2000-03-06
11
155 Views
Last Modified: 2010-04-04

1. How can i let my program take parameters?

2. My program generate file with extension .myprogram. I like
    to be able when i double click on this file my program will open and load
    this file

Is this all possible for 100 points maybe more?

Esk

0
Comment
Question by:esk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2589112
you can see the parameters with the paramStr function:

ParamStr returns a specified parameter from the command-line.

function ParamStr(Index: Integer): string;

as for the extension you need to create a handler for it in the shell

GL
Mike
0
 
LVL 6

Expert Comment

by:edey
ID: 2589126
ohh, oops, ment to include this link in my previous comment:


http://x42.deja.com/[ST_rn=ps]/getdoc.xp?AN=537133713&CONTEXT=952377217.1711800325&hitnum=2


I have used code based in this article before.


GL
Mike
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 2589277
Hi Esk, reading your question I think you want to register/associate filetypes, so I stripped this code from one of my previous answers:


Put registry in the uses clause and use this code:

// Associate a file type
procedure TForm1.Button1Click(Sender: TObject);
var reg: TRegistry;
begin
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CLASSES_ROOT;
    OpenKey('\.xxx', True);
    WriteString('', 'xxxfile');
    OpenKey('\xxxfile\Shell\Open\command', True);
    WriteString('', '"c:\program files\yourapp\app.exe" "%1"');
    Free;
  end;
end;

// Deassociate a file type
procedure TForm1.Button2Click(Sender: TObject);
var reg: TRegistry;
begin
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CLASSES_ROOT;
    DeleteKey('\.xxx');
    DeleteKey('\xxxfile\Shell\Open\command');
    DeleteKey('\xxxfile\Shell\Open');
    DeleteKey('\xxxfile\Shell');
    DeleteKey('\xxxfile');
    Free;
  end;
end;

// Check the file type
procedure TForm1.Button3Click(Sender: TObject);
var reg: TRegistry;
begin
  reg := TRegistry.Create;
  with reg do
  begin
    RootKey := HKEY_CLASSES_ROOT;
    if not OpenKey('\.xxx', False) or
       not OpenKey('\xxxfile\Shell\Open\command', False) then
      ShowMessage('Type not associated')
    else begin
      if ReadString('') = '"c:\program files\yourapp\app.exe" "%1"' then
        ShowMessage('Type associated to your app')
      else
        ShowMessage('Type associated to another app');
    end;
    Free;
  end;
end
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:Epsylon
ID: 2589294
Usually install managers like WISE and Install Shield do these things.
0
 

Author Comment

by:esk
ID: 2589678
I like to my program after i have create the extension .mykey to the files that my program saves, so if i click this file with this extensions i like my program be able to open this file in his editor

Esk
0
 

Author Comment

by:esk
ID: 2589700
Like Microsoft Word , if i click on .doc then Word will opens with this document

Esk
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2589722
Yes, that's what it does....

Just replace the xxx's with your extension.
0
 

Author Comment

by:esk
ID: 2589736
Like Microsoft Word , if i click on .doc then Word will opens with this document

Esk
0
 
LVL 17

Expert Comment

by:inthe
ID: 2590425
try epsylons code its definetly what your need to do this..
0
 
LVL 1

Expert Comment

by:Azerthur
ID: 2602291
Yes, epsylons code is what you want !
But I think I know what you forgot !

The  file opened when you click will not display by magic !
It will be stored in paramstr[1], then from this param you'll be able to open it. exemple Memo1.loadformfile(Paramstr[1]), ok ?

If user clicks on aaaa.myprogram the paramstr[1] will be
'c:\directory\'aaa.myprogram'

If you want to prevent double instance in your app ( because I think you don't want 100 app running when you open 100 different files

const
  CM_RESTORE = WM_USER + $1000;
var
  RvHandle : hWnd;

begin

RvHandle := FindWindow('Mi programa Delphi', NIL);
  if RvHandle > 0 then
  begin
    PostMessage(RvHandle, CM_RESTORE, 0, 0);
    Exit;
  end;
Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.



0
 

Author Comment

by:esk
ID: 2603699
Thanks to all!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question