Solved

my program can take parameters

Posted on 2000-03-06
11
148 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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now