Solved

my program can take parameters

Posted on 2000-03-06
11
154 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

Suggested Solutions

Title # Comments Views Activity
Twebbrowser add css to the header 3 53
can i put an image from resource into image tag ? 6 40
Broadcast a message using ICS 2 50
TAction.OnAfterExecute? 2 31
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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

732 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