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

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-06-2006
Avatar de ixMike
ixMike ixMike is offline
Miembro
 
Registrado: feb 2004
Posts: 1.151
Poder: 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
 



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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Muy lento Sql IVAND SQL 8 27-01-2010 03:59:52
Comparar un registro de un edit con un registro de una tabla en una consulta Damian666 SQL 10 01-10-2005 00:43:20
Muy lento al insertar registro >100.000 pjjorda Firebird e Interbase 16 22-07-2005 01:23:46
ADO lento CHiCoLiTa Conexión con bases de datos 6 28-07-2004 17:59:46
MDI lento tomasgarcia OOP 1 27-07-2004 20:28:05


La franja horaria es GMT +2. Ahora son las 12:48:11.


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