Question : delphi Run once

I have many delphi forms in my project...

Where/How am I going to code, if I've declared a run once to my project,  THEN,  if I run again the program with a parameter, it will show the ParamForm.


// i dont think this is a good idea
{
    if Mutex <> 0 then
    begin

if paramstr(1)<>'' then
begin
ParamForm.Show;
end

else
    CloseHandle(Mutex);
    end;
  end;
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
program Project1;

uses
  Forms,
  windows,
  fFwall in 'fFwall.pas' {fMainform},
  uSplash in 'uSplash.pas' {fSplashform},
  fusbscan in 'fusbscan.pas' {usbform},
  dbupdater in 'dbupdater.pas' {dbUpdateForm},
  ParamUnit in 'ParamUnit.pas' {ParamForm};

var
Mutex : THandle;

{$R *.res}

begin
Mutex := CreateMutex(nil, True, 'myapp');
  if (Mutex <> 0) and (GetLastError = 0) then
  begin
   Application.Initialize;

   fSplashForm:=TfSplashForm.Create(Application);
   fSplashForm.Show;

  Application.ShowMainForm := False;
  Application.CreateForm(TfMainform, fMainform);
  Application.CreateForm(Tusbform, usbform);
  Application.CreateForm(TdbUpdateForm, dbUpdateForm);
  Application.CreateForm(TParamForm, ParamForm);
  Application.Run;

    if Mutex <> 0 then CloseHandle(Mutex);
  end;


end.

Answer : delphi Run once

A bit better:

var
  LastPos: TPoint = (x:100; y:100);

procedure TMainForm.WndProc(var Message: TMessage);
var
  NewParamForm: TParamForm;
begin
  if Message.Msg = msg_ShowParamForm then
  begin
    NewParamForm:= TParamForm.Create(Self);
    NewParamForm.Top:= LastPos.x;
    NewParamForm.Left:= LastPos.y;
    Inc(LastPos.x, 30);
    Inc(LastPos.y, 30);
    NewParamForm.Show;
  end
  else
    inherited;
end;
Random Solutions  
 
programming4us programming4us