Ver Mensaje Individual
  #1  
Antiguo 12-06-2006
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Reputación: 22
ixMike Va por buen camino
Angry ¡Qué registro más lento!

Hola,
Veréis, estoy haciendo un programa (bueno, casi todos los del foro estamos haciendo alguno, ), en el que tengo un TComboBox, un TButton y un TListView (entre otros, pero al usar éstos es cuando tengo problemas). En el TComboBox escribo una clave de registro (por ejemplo "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion"), y al darle al botón, el TListView se llena con todas las claves y datos que hay en esa clave de registro. El problema está en que cuando escribo algunas claves (como "HKEY_CLASSES_ROOT" o "HKEY_LOCAL_MACHINE\Software\Classes", entre otras), que contienen miles de claves y datos, pues el programa reacciona con una lentitud increíble (hasta 40 segundos).
Pero, ¿qué pasa? ¿Por qué tarda tanto? ¿Cuál es el problema, dónde está el fallo? ¿Alguien tiene alguna sugerencia?
NOTA: Uso Delphi 3 Std en Windows XP, el TListView usa iconos (una para claves, otro para valores alfanuméricos y otro para valores numéricos o binarios), y no solo lee los nombres, sino también los valores. El código para leer el registro hace más cosas, entre comprobaciones y memorizar las claves que se van escribiendo.
Aquí está el código que utilizo (resumido a lo importante):

Código Delphi [-]
 
unit regFondo;
{...}
type
  ERegConvertError = class (ERegistryException);
  TFFondo = class(TForm)
    lista: TListView;  //Esta el la lista que se llena con las claves
    CDireccion: TComboBox;  //AQuí es donde escribo la clave
    BIrDireccion: TSpeedButton; //Este es el botón que pulso para leer las claves
    estado: TStatusBar;
    BAtras: TSpeedButton;;
    BAdelante: TSpeedButton;
    ilListaSmall: TImageList;
    liLista: TImageList;
    {...}
    Procedure LlenarLista;
    procedure Explorar(path: string; editback: boolean);
    procedure BIrDireccionClick(Sender: TObject);
    {...}
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  FFondo: TFFondo;
  CurKey: Integer;
  CurPath: String;
  Registro: TRegistry;
  Atras, Adelante: TStrings;
implementation
{$R *.DFM}
{Aquí hay varias funciones para pasar las claves de String a Integer, y hacer comprobacioens:
RKeyToStr(rkey: integer): String; //Parametro: HKEY_LOCAL_MACHINE; devulve: "HKEY_LOCAL_MACHINE"
StrToRKey(rkey: string): integer; //Al contrario que la anterior
IsValidRoot(root: integer): boolean; //Si el valor introducido no es tipo HKEY_lo_que_sea devulve False
IsValidRootStr(root: string): boolean; //Como la anterior, pero con texto
GetRoot(path: string): integer; //Parametro: "HKEY_LOCAL_MACHINE\Software\Microsoft"; devulve: HKEY_LOCAL_MACHINE}
Procedure TFFondo.LlenarLista;
var
s: tstrings;
n: integer;
nodo: TListItem;
tipo: TRegDataType;
begin
Lista.Items.Clear;
s:=TStringList.Create;
Registro.GetKeyNames(s);
if s.Count>0 then for n:=0 to s.Count-1 do
  begin
  nodo:=Lista.Items.Add;
  nodo.Caption:=s[n];
  nodo.SubItems.Add('Clave de registro');
  end;
s.Clear;
registro.GetValueNames(s);
if s.Count>0 then for n:=0 to s.Count-1 do
  begin
  nodo:=Lista.Items.Add;
  nodo.Caption:=s[n];
  if nodo.Caption='' then nodo.Caption:='(Predeterminado)';
  tipo:=Registro.GetDataType(s[n]);
  Case tipo of
    rdString: begin
       nodo.ImageIndex:=1;
       nodo.SubItems.Add('Alfanumerico');
       nodo.SubItems.Add(Registro.ReadString(s[n]));
       end;
    rdExpandString: begin
      nodo.ImageIndex:=1;
      nodo.SubItems.Add('Alfanumerico expandido');
      nodo.SubItems.Add(Registro.ReadString(s[n]));
      end;
    rdInteger: begin
        nodo.ImageIndex:=2;
        nodo.SubItems.Add('Numerico');
        nodo.SubItems.Add(IntToHex(Registro.ReadInteger(s[n]),8)+'('+IntToStr(Registro.ReadInteger(s[n]))+')');
        end;
    rdBinary: begin
       nodo.ImageIndex:=2;
       nodo.SubItems.Add('Binario');
              //Aquí falta el código para poner en la lista algo tipo "AA BB 2F 3C 43 51 A7 B0 AC ..." pero aún no lo he hecho
       end;
    rdUnknown: begin
        nodo.ImageIndex:=2;
        nodo.SubItems.Add('Desconocido');
        end;
   end;
  end;
s.Free;
end;
Procedure TFFondo.Explorar(path: string; editback: boolean);
var
oldpath: string;
begin
estado.panels[0].Text:='Leyendo registro...';
If editback then oldpath:=RKeyToStr(CurKey)+CurPath;
try
CurKey:=GetRoot(path);
CurPath:=copy(path,length(RKeyToStr(curkey))+1,length(path)-length(RKeyToStr(curkey)));
Registro.RootKey:=CurKey;
CDireccion.Text:=path;
registro.CloseKey;
Registro.OpenKey(CurPath,false);
LlenarLista;
if editback then
  begin
  atras.add(oldpath);
  adelante.add(RKeyToStr(CurKey)+CurPath);
  end;
if Lista.Items.Count>0 then lista.ItemFocused:=Lista.ITems[0];
except
Application.MessageBox('Se produjo un error','Error',Mb_IconError);
end;
end;
procedure TFFondo.BIrDireccionClick(Sender: TObject);
begin
If CDireccion.Text[length(CDireccion.Text)]<>'\'then CDireccion.Text:=CDireccion.Text+'\';
Explorar(CDireccion.Text,true);
CDireccion.SelectAll;
end;
{...}
end.

Gracias.
Responder Con Cita