Ver Mensaje Individual
  #4  
Antiguo 13-01-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola paquechu.

Estuve leyendo el enlace que mencionas y no veo como una sola variable te puede servir para recorrer y verificar los n items del CheckListBox... Lo que se me ocurre, es mantener un arreglo de boolean paralelo al CheckListBox y realizar las búsquedas sobre él.

Hice una prueba con 1.400.000 items y obtuve estos resultados:
Código:
Busqueda sobre el CheckListBox : 3.030.443 µs.
Busqueda sobre el arreglo      :     1.921 µs.
Claro está que el tiempo de carga aumenta un poco ya que también hay que asignar los valores al arreglo...

La prueba:
Código Delphi [-]
...
type
  TForm1 = class(TForm)
    CheckListBox1 : TCheckListBox;
    ListBox1: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    btnSearchInChkLstBox: TButton;
    btnSearchInArray: TButton;
    procedure FormCreate(Sender: TObject);
    procedure CheckListBox1ClickCheck(Sender: TObject);
    procedure btnSearchInChkLstBoxClick(Sender: TObject);
    procedure btnSearchInArrayClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    FFreq, FIni, FEnd: Int64;
    procedure InitClock;
    function EndClock: string;
  public
  end;
...

implementation

const
  MAX = 1400000;

var
  ChkArray : array of Boolean;

procedure TForm1.InitClock;
begin
  QueryPerformanceFrequency(FFreq);
  QueryPerformanceCounter(FIni);
end;

function TForm1.EndClock: string;
begin
  QueryPerformanceCounter(FEnd);
  Result := FormatFloat('0,', (FEnd - FIni) * 1000000 div FFreq);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Randomize;
  SetLength(ChkArray, MAX);
  for i:= 0 to MAX-1 do
    with CheckListBox1 do
    begin
      Items.Add(IntToStr(i));
      Checked[i]:= Boolean(Random(2));
      ChkArray[i]:= Checked[i];
    end;
end;

procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
  with CheckListBox1 do
    ChkArray[ItemIndex]:= Checked[ItemIndex];
end;

procedure TForm1.btnSearchInChkLstBoxClick(Sender: TObject);
var
  i,x : Integer;
begin
  x:= 0;
  InitClock;
  for i:= 0 to CheckListBox1.Items.Count-1 do
    if CheckListBox1.Checked[i] then
      Inc(x); // una acción
  Label1.Caption:= EndClock;
end;

procedure TForm1.btnSearchInArrayClick(Sender: TObject);
var
  i,x: Integer;
begin
  x:= 0;
  InitClock;
  for i:= Low(ChkArray) to High(ChkArray) do
    if ChkArray[i] then
      Inc(x); // una acción
  Label2.Caption:= EndClock;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Finalize(ChkArray);
end;
end.

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita