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; CDireccion: TComboBox; BIrDireccion: TSpeedButton; estado: TStatusBar;
BAtras: TSpeedButton;;
BAdelante: TSpeedButton;
ilListaSmall: TImageList;
liLista: TImageList;
Procedure LlenarLista;
procedure Explorar(path: string; editback: boolean);
procedure BIrDireccionClick(Sender: TObject);
private
public
end;
var
FFondo: TFFondo;
CurKey: Integer;
CurPath: String;
Registro: TRegistry;
Atras, Adelante: TStrings;
implementation
{$R *.DFM}
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');
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.