Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Error al escribir en el Registro. (https://www.clubdelphi.com/foros/showthread.php?t=7900)

nesetru 01-03-2004 18:35:16

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 :rolleyes: 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. :eek: Dan error al ejecutarse y no puedo escribir ningún dato.

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

Saludos.

__cadetill 01-03-2004 18:59:19

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)

nesetru 01-03-2004 19:30:20

Sigue sin funcionar :confused:

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.

__cadetill 01-03-2004 20:46:06

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

nesetru 02-03-2004 18:35:12

Muchísimas gracias por la ayuda. :D

Te lo agradezco, de veras.

Saludos.

Coolliam777 18-03-2011 10:29:28

aciram.. check your reverse nickname.
 
You should change it..

in spanish is like gay.

Best Regards
Coollliam (L)


La franja horaria es GMT +2. Ahora son las 16:56:33.

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