Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 01-03-2004
nesetru nesetru is offline
Miembro
 
Registrado: may 2003
Posts: 50
Poder: 21
nesetru Va por buen camino
Talking Error al escribir en el Registro.

Hola Amigos.

Estoy intentando escribir unos valores en el Registro pero me da un Error. Me dice que es imposible escribir el dato.

Uso Windows professional y hago es lo siguiente:

Reg.CreateKey('\Software\Microsoft\Windows\Bmnse');
Reg.WriteDate('MyAppDate',StrToDate('15/03/04'));
Reg.WriteInteger('MyAppData',0);

Creo la clave 'Bmnse' e intuyo que dentro de la misma me crea lo siguiente:
MyAppDate donde guarda 15/03/04
MyAppData donde guarda 0

Pues nada, ni una ni la otra. Dan error al ejecutarse y no puedo escribir ningún dato.

Estoy mirando la ayuda pero no consigo ver dónde fallo.

Saludos.
Responder Con Cita
  #2  
Antiguo 01-03-2004
__cadetill __cadetill is offline
Miembro
 
Registrado: may 2003
Posts: 3.387
Poder: 24
__cadetill Va por buen camino
En el help de Delphi viene este ejemplo

Código:
procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegIniFile;
begin
  if Length(NameofKey.Text) or Length(ValueforKey.Text) <=0 then
    Showmessage('Either the key name or value is missing.')
  else begin
    Reg:=TRegIniFile.Create('MyApp');
    try
      Reg.RootKey:=HKey_Local_Machine; // Section to look for within the registry
      if not Reg.OpenKey(NameofKey.Text,False) then
        if MessageDlg('The specified key does not exist, create it?'

                 ,Mtinformation,[mbYes,mbNo],0)=mryes then
        begin
          Reg.CreateKey(NameofKey.Text);
          if not Reg.OpenKey(NameofKey.Text,False) then
            ShowMessage('Error in Opening Created Key')
          else
            Reg.WriteString('Main Section','Value1',ValueForKey.Text);
        end
     else
       Reg.WriteString('Main Section','Value1',ValueForKey.Text);
    finally

      Reg.Free;
    end;
  end;
end;
Recuerda que has de tener derechos de administrador para acceder al registro (almenos para modificarlo)
Responder Con Cita
  #3  
Antiguo 01-03-2004
nesetru nesetru is offline
Miembro
 
Registrado: may 2003
Posts: 50
Poder: 21
nesetru Va por buen camino
Talking

Sigue sin funcionar

Tengo el suiguiente código

Código:
If Reg.KeyExists('\Software\Microsoft\Windows\Bmnse') then
    begin
       If (Today > Reg.ReadDate('MyApp')) then
       begin
          Application.MessageBox('Mensaje','Atención',MB_OK+MB_IconError);
          Halt;
       end
       else
          Application.Run;
    end
    else
    begin
       Reg.CreateKey('\Software\Microsoft\Windows\Bmnse');
       Reg.WriteDate('MyAppDate',StrToDate('15/03/04'));
       Reg.WriteInteger('MyAppData',0);
       If (Today > Reg.ReadDate('MyApp')) then
       begin
          Application.MessageBox('Mensaje','Atención',MB_OK+MB_IconError);
          Halt;
       end;
    end
  finally
    Reg.Free;
  end;
Pero nada, da error al ejecutar las líneas:
Código:
Reg.WriteDate('MyAppDate',StrToDate('15/03/04'));
Reg.WriteInteger('MyAppData',0);
Lo que yo quiero hacer es que dentro de la clave 'Bmnse' hayan dos secciones o variables o como queráis llamarlos donde poder almacenar sendos datos.

A ver si así sale...

Saludos.
Responder Con Cita
  #4  
Antiguo 01-03-2004
__cadetill __cadetill is offline
Miembro
 
Registrado: may 2003
Posts: 3.387
Poder: 24
__cadetill Va por buen camino
Bueno, me lo he estado mirando (movido por la curiosidad) y he visto porque no te funciona. Te pego el código, pero te aconsejo te fijes en los errores que te da y en la ayuda

Código:
procedure TForm1.Button1Click(Sender: TObject);
const
  PathReg = '\Software\Microsoft\Windows\Bmnse';
var
  Reg : TRegistry;
  Today: TDate;
begin
  Today := Date;
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKey_Local_Machine;
    If Reg.KeyExists(PathReg) then
    begin
      If (Today > Reg.ReadDate('MyAppDate')) then
      begin
        Application.MessageBox('Mensaje','Atención',MB_OK+MB_IconError);
        Halt;
      end
      else
        Application.Run;
    end
    else
    begin
      if not Reg.OpenKey(PathReg, true) then
      begin
        Application.MessageBox('Mensaje', 'Atención', MB_OK or MB_IconError);
        Halt;
      end;
      Reg.WriteInteger('MyAppData', 0);
      Reg.WriteDate('MyAppDate', EncodeDate(2004, 3, 15));
      If (Today > Reg.ReadDate('MyAppDate')) then
      begin
        Application.MessageBox('Mensaje', 'Atención', MB_OK or MB_IconError);
        Halt;
      end;
    end
  finally
    Reg.Free;
  end;
end;
Es decir, lo que te falta es ABRIR la clave del registro

PD: a parte de eso, he hecho algún que otro cambio más ya que me parece algo más.... ¿correcto?

Espero te sirva
Responder Con Cita
  #5  
Antiguo 02-03-2004
nesetru nesetru is offline
Miembro
 
Registrado: may 2003
Posts: 50
Poder: 21
nesetru Va por buen camino
Muchísimas gracias por la ayuda.

Te lo agradezco, de veras.

Saludos.
Responder Con Cita
  #6  
Antiguo 18-03-2011
Coolliam777 Coolliam777 is offline
No confirmado
 
Registrado: jul 2010
Posts: 1
Poder: 0
Coolliam777 Va por buen camino
Exclamation aciram.. check your reverse nickname.

You should change it..

in spanish is like gay.

Best Regards
Coollliam (L)
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 22:12:08.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi