Ver Mensaje Individual
  #9  
Antiguo 29-07-2011
jars jars is offline
Miembro
 
Registrado: mar 2004
Posts: 279
Reputación: 21
jars Va por buen camino
Hola, yo uso este codigo en todos mis programas y funciona bien, sin dejar procesos en memoria:

Código:
  public
    constructor Create(AOwner: TComponent); override;



//======================================================================================================================
constructor TfrmMain.Create(AOwner: TComponent);
//======================================================================================================================
type
  PHWND = ^HWND;
var
  createerror: DWORD;
  FHMapObject: Integer;
begin
    FHMapObject := CreateFileMapping(
      $FFFFFFFF,                                 // use paging file
      nil,                                       // no security attributes
      PAGE_READWRITE,                            // read/write access
      0,                                         // size: high 32-bits
      1,                                         // size: low 32-bits
      PChar('Nombre_de_tu_programa'));           // name of map object
    createerror := GetLastError;
    if FHMapObject = 0 then
    begin
      MessageDlg(Format('CreateFileMapping=$%x', [createerror]),
        mtError, [mbOK], 0);
      Exit;
    end;

    if GetLastError = ERROR_ALREADY_EXISTS then
    begin
      CloseHandle(FHMapObject);
      MessageDlg('Ya hay una instancia ejecutandose', mtError, [mbOK], 0);
      Application.Terminate;
      Halt;
    end;
  Inherited;
end;
Espero te sea util.
Jorge
Responder Con Cita