Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7008169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:02+00:00 2026-05-27T21:42:02+00:00

I am handling from my Application associated extension files from Windows. So when you

  • 0

I am handling from my Application associated extension files from Windows. So when you double click a file from Windows it will execute my program, and I handle the file from there, something like:

procedure TMainForm.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to ParamCount -1 do
  begin
    if SameText(ExtractFileExt(ParamStr(i)), '.ext1') then
    begin
      // handle my file..

      // break if needed
    end else
    if SameText(ExtractFileExt(ParamStr(i)), '.ext2') then
    begin
      // handle my file..

      // break if needed
    end else
  end;
end;

That works pretty much how I want it to, but when I was testing I realised it does not consider using only one instance of my program.

So for example, if I selected several Files from Windows and opened them all at the same time, this will create the same number of instances of my program with the number of Files being opened.

What would be a good way to approach this, so that instead of several instances of my program being opened, any additional Files from Windows being opened will simply focus back to the one and only instance, and I handle the Files as normal?

Thanks

UPDATE

I found a good article here: http://www.delphidabbler.com/articles?article=13&part=2 which I think is what I need, and shows how to work with the Windows API as mentioned by rhooligan. I am going to read through it now..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:42:02+00:00Added an answer on May 27, 2026 at 9:42 pm

    Here is some simple example code that gets the job done. I hope it is self-explanatory.

    program StartupProject;
    
    uses
      SysUtils,
      Messages,
      Windows,
      Forms,
      uMainForm in 'uMainForm.pas' {MainForm};
    
    {$R *.res}
    
    procedure Main;
    var
      i: Integer;
      Arg: string;
      Window: HWND;
      CopyDataStruct: TCopyDataStruct;
    begin
      Window := FindWindow(SWindowClassName, nil);
      if Window=0 then begin
        Application.Initialize;
        Application.MainFormOnTaskbar := True;
        Application.CreateForm(TMainForm, MainForm);
        Application.Run;
      end else begin
        FillChar(CopyDataStruct, Sizeof(CopyDataStruct), 0);
        for i := 1 to ParamCount do begin
          Arg := ParamStr(i);
          CopyDataStruct.cbData := (Length(Arg)+1)*SizeOf(Char);
          CopyDataStruct.lpData := PChar(Arg);
          SendMessage(Window, WM_COPYDATA, 0, NativeInt(@CopyDataStruct));
        end;
        SetForegroundWindow(Window);
      end;
    end;
    
    begin
      Main;
    end.
    

     

    unit uMainForm;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls;
    
    type
      TMainForm = class(TForm)
        ListBox1: TListBox;
        procedure FormCreate(Sender: TObject);
      protected
        procedure CreateParams(var Params: TCreateParams); override;
        procedure WMCopyData(var Message: TWMCopyData); message WM_COPYDATA;
      public
        procedure ProcessArgument(const Arg: string);
      end;
    
    var
      MainForm: TMainForm;
    
    const
      SWindowClassName = 'VeryUniqueNameToAvoidUnexpectedCollisions';
    
    implementation
    
    {$R *.dfm}
    
    { TMainForm }
    
    procedure TMainForm.CreateParams(var Params: TCreateParams);
    begin
      inherited;
      Params.WinClassName := SWindowClassName;
    end;
    
    procedure TMainForm.FormCreate(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 1 to ParamCount do begin
        ProcessArgument(ParamStr(i));
      end;
    end;
    
    procedure TMainForm.ProcessArgument(const Arg: string);
    begin
      ListBox1.Items.Add(Arg);
    end;
    
    procedure TMainForm.WMCopyData(var Message: TWMCopyData);
    var
      Arg: string;
    begin
      SetString(Arg, PChar(Message.CopyDataStruct.lpData), (Message.CopyDataStruct.cbData div SizeOf(Char))-1);
      ProcessArgument(Arg);
      Application.Restore;
      Application.BringToFront;
    end;
    
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know from wikipedia for example that exception handling is used in an application
I'm in the process of porting an application from Windows to Mac OS X.
I'm currently porting an application from iPhone to Windows Phone. The behaviour of buttons
I have an Exception Handling project in my application that can be called from
Question related to PHP memory-handling from someone not yet very experienced in PHP: If
I'm looking at the TPL exception handling example from MSDN @ http://msdn.microsoft.com/en-us/library/dd537614(v=VS.100).aspx The basic
I am wondering what everyone thinks the best method of handling results from your
What is the best way of handling trying to get data from a DataReader
SSEPlus is an open source library from AMD for unified handling of SSE processor
I want to make a general error handling package that should be called from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.