1 (edited by settimox 2017-02-12 13:58:50)

Topic: Allow only one instances

Hi,

How to allow only one instances of form.

For example:

If user open the application 2 times i want to force it with one msgbox that write "this application is open, you cannot open it another time must close it first"..

Thank you.

Re: Allow only one instances

Hello settimox

Please, does this script answer your question ?

const
  APP_NAME = 'My App Name';

procedure Form1_OnShow (Sender: string; Action: string);
begin
  Form1.Caption := '';
  if FindWindow(nil, APP_NAME) <> 0 then
  begin
      ShowMessage('This application is opened, you cannot open it another time. You must close it first".');
      Form1.Close;
  end;
  Form1.Caption := APP_NAME;
end;


begin

end.

Re: Allow only one instances

Thank you, i test it now .
I think can work..
ps: can load app name in automatic mode?

Re: Allow only one instances

What do you mean "automatic mode"?

Dmitry.

5 (edited by settimox 2017-02-14 22:34:55)

Re: Allow only one instances

Automatic mode, don't allow to open it "block it in hidden mode" without any msg.."
Automatic mode "to retrieve the "app_name" without write it .i think can be done using registry key with app name.

Re: Allow only one instances

settimox wrote:

Automatic mode, don't allow to open it "block it in hidden mode" without any msg.."

Just remove this line

ShowMessage('This application is opened, you cannot open it another time. You must close it first".');

settimox wrote:

Automatic mode "to retrieve the "app_name" without write it .i think can be done using registry key with app name.

What is this for?

Dmitry.

Re: Allow only one instances

Lol, mistake..
Ok now i understand.
Sorry.