Tema: Instalador
Ver Mensaje Individual
  #6  
Antiguo 20-06-2007
afxe afxe is offline
Miembro
 
Registrado: jul 2004
Ubicación: Malaga-España
Posts: 273
Reputación: 20
afxe Va por buen camino
Sobre TRegistry

Jhonny tiene razón, en la ayuda viene todo muy bien documentado, no obstante te propongo una introducción simple:

Código Delphi [-]
 
  vPath   := '';
  vIP     := '';
  vIP     := Lee_Registro(HKey_Local_Machine, 'SOFTWARE\MiEmpresa\DATABASES\', 'IP',     '127.0.0.1' );
  vPath   := Lee_Registro(HKey_Local_Machine, 'SOFTWARE\MiEmpresa\DATABASES\', 'Path',   ''   );
  vUsua   := Lee_Registro(HKey_Current_user, 'SOFTWARE\MiEmpresa\USERS\'    , 'Codigo', '1'  );
  if (Trim(vPath) = '') then begin
    InputQuery('Crear/Cambiar Servidor de Datos', 'Direccion IP Servidor:', vIP);
    InputQuery('Crear/Cambiar Servidor de Datos', 'Nueva Base de datos:', vPath);
  end;
  if Trim(vPath) = '' then begin
    MsgError('No ha definido correctamente el servidor de datos');
    Application.Terminate;
    EXIT;
  end;
 
 
    DM.MiBaseDatos.DatabaseName := vIP+':'+vPath;
    try
      DM.MiBaseDatos.Open;
      Escribe_Registro(HKey_Local_Machine, 'SOFTWARE\MiEmpresa\DATABASES\', 'IP', vIP);
      Escribe_Registro(HKey_Local_Machine, 'SOFTWARE\MiEmpresa\DATABASES\', 'Path', vPath);
      Try
        QryUsu.Open;
        QryUsu.FetchAll;
        if QryUsu.Locate('CODIGO', vUsua, [loCaseInsensitive]) then
          ShowMessage('Bienvenido ' + QryUsuNOMBRE.AsString);
      except
        on E: Exception do begin
           MsgError('Ocurre algún problema al acceder a los datos: ' + #10+#13 + E.Message);
           Application.Terminate;
        end;
      end;
    except
      on E: Exception do begin
         MsgError('Ocurre algún problema al abrir la base de datos: ' + #10+#13 + E.Message);
         Application.Terminate;
      end;
    end;

Ya te adjunto las dos rutinas de lectura y escritura...

Código Delphi [-]
 
Function Lee_Registro(Raiz :HKEY; Seccion, Clave, ValorPorDefecto: String): String;
var
  Reg: TRegistry;
begin
  Result := ValorPorDefecto;
  Reg    := TRegistry.Create;
  try
    Reg.RootKey := Raiz;
    if Reg.OpenKey(Seccion, False) then Result := Reg.ReadString(Clave);
    if Result = '' then Result := ValorPorDefecto;
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;
 
Procedure Escribe_Registro(Raiz :HKEY; Seccion, Clave, Valor: String);
var
  Reg: TRegistry;
begin
  Reg    := TRegistry.Create;
  try
    Reg.RootKey := Raiz;
    Reg.OpenKey(Seccion, True);
    Reg.WriteString(Clave, Valor);
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

No sé si habré copiado algo mal, pero seguro que te dará una idea. No dejes de leer la ayuda para afianzar los conocimientos sobre TRegistry.

Saludos.
Responder Con Cita