Ver Mensaje Individual
  #6  
Antiguo 05-08-2015
noobdelphi5 noobdelphi5 is offline
Miembro
NULL
 
Registrado: ene 2015
Posts: 22
Reputación: 0
noobdelphi5 Va por buen camino
Smile Solución

Si ya resolví el problema, todas las respuestas me funcionaron, yo use el código de nlsgarcia, el único código que no pude correr fue el de Roman, después lo checo con mas calma, me salía:

[Fatal Error] UIApp_fmx.pas(24): File not found: 'FMX.Forms.dcu'
[Fatal Error] UIApp_fmx.pas(24): File not found: 'FMX.Platform.Win.dcu'

Codigo de eficsa

Código Delphi [-]
program Project1;

uses
  Forms,
  Windows,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

  resourcestring
   SAlreadyRunning =
      'Existe otra instancia activa de esta aplicación.'#13 +
      'La presente instancia se detendrá ahora mismo.';

  function AlreadyRunning(const AIdentifier: string): Boolean;
begin
  CreateMutex(nil, False, PChar(AIdentifier));
  AlreadyRunning := GetLastError = ERROR_ALREADY_EXISTS;
end;

  begin
   if AlreadyRunning('Empresa.Aplicación.Versión') then
   begin
      MessageBox(0, PChar(SAlreadyRunning), 'Error', MB_ICONSTOP or MB_OK);
      Halt(1);
   end;
   Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;

end.


Otra forma:

Código Delphi [-]
program Project1;

uses
  Forms, Windows,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}
var
  Mutex : THandle;
begin
  Mutex := CreateMutex(nil, True, 'My_Unique_Application_Mutex_Name'); 
  if (Mutex = 0) OR (GetLastError = ERROR_ALREADY_EXISTS) then
  begin

    // code to searh for, and activate 
    // the previous (first) instance

  end
  else
  begin
    Application.Initialize;
    Application.CreateForm(TForm1, Form1);
    Application.Run;
    if Mutex  0 then
      CloseHandle(Mutex); 
    end;
  end;
end.

Gracias!!
Responder Con Cita