Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

my program can take parameters

Posted on 2000-03-06
11
Medium Priority
?
156 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

705 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