Solved

my program can take parameters

Posted on 2000-03-06
11
152 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
  • 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Correct Component for Shopping Cart. 2 113
HTML text in the body of an email (delphi code) 12 173
How to renew a Delphi rad-studio licence? 5 70
RESTRequest Parameter 4 43
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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