Hola bucanero,
He estado mirando tu código e implementandolo para mi caso, en compilación no da error, pero como las barras de progreso no se mueven ni un par de etiquetas que muestran el recorrido de lista3 y el listbox per, no sé si realmente funciona o no.
El código resumido seria este:
Código Delphi
[-]unit primi;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ImgList, Menus, StdCtrls, ComCtrls, Gauges, uTAlea, ListViewExt,
ToolWin, Buttons, VirtualListData, System.ImageList, Vcl.Imaging.pngimage;
type
...
private
list:TStringList;
function GetComb(listBox:TListBox):String;
function extraerComunes(const res:int64):string;
procedure CompararCombinaciones(const Cad1, cad2:Int64);
procedure buscarComunes(const Cad1:Int64);
FVirtualData: TVirtualData;
public
end;
TModa = record
Number : Integer;
Count : Integer;
end;
...
const
...
var
...
implementation
{$R *.dfm}
{$M 16384,1999999}
function ValorCombinacion(list:TStrings):Int64;
var
elemento:Byte;
i: Integer;
begin
result := 0;
with list do
for i := 0 to Count - 1 do
begin
elemento := StrToInt(strings[i])-1;
result := result or (Int64(1) shl elemento);
end;
end;
function TForm1.GetComb(listBox:TListBox):String;
begin
result:=form1.per.items[form1.per.itemIndex];
end;
function obtenerComunes(res:int64):string;
var
i:integer;
begin
result:='';
for i :=0 to 49 do
if ((res and (int64(1) shl i))<>0) then
result:=result+IntToStr(i+1)+' ';
end;
function TForm1.extraerComunes(const res:int64):string;
var
i:integer;
begin
result:='';
for i :=0 to 49 do
if ((res and (int64(1) shl i))<>0) then
result:=result+IntToStr(i+1)+' ';
end;
procedure TForm1.CompararCombinaciones(const Cad1, cad2:Int64);
var
res:Int64;
comunes:string;
begin
res:=cad1 and cad2;
if (cad1 = cad2) then begin
ShowMessage('Iguales');
end
else
showMessage('No hay coincidencias');
form1.timer1.Enabled:= false;
form1.Refresh;
exit
end;
procedure TForm1.buscarComunes(const Cad1:Int64);
var
cad2:Int64;
j:integer;
list:TStringList;
begin
for j := 0 to form1.per.Items.Count -1 do
begin
label32.Caption:= IntToStr(j+1);
form1.barra2.Max:= form1.per.Items.Count;
form1.barra2.Position:= j;
form1.label22.Caption:= IntToStr(cad2);
form1.per.ItemIndex := j;
list.delimitedText:=form1.per.items[j];
cad2 := ValorCombinacion(list);
CompararCombinaciones(cad1, cad2);
end;
end;
procedure LoadFromCSV(LV: TListView; const aFileName: string);
var
LI : TListItem;
TS1, TS2: TStrings;
i, j: Integer;
begin
TS1 := TStringList.Create;
TS2 := TStringList.Create;
try
TS1.LoadFromFile(aFileName);
TS2.CommaText := TS1[0];
for i := 0 to TS2.Count-1 do
begin
LV.Columns.Add;
LV.Columns.Items[i].Caption := TS2[i];
LV.Columns[i].Width:= 100; end;
for i := 1 to TS1.Count-1 do
begin
TS2.Clear;
TS2.CommaText := TS1[i];
LI := LV.Items.Add;
LI.Caption := TS2[0];
for j:= 1 to TS2.Count - 1 do
LI.SubItems.Add(TS2[j]);
end;
finally
TS1.Free;
TS2.Free;
end;
end;
procedure combinatoria2(v: array of Integer; Serie: TStrings);
var
a,b,c,d,e: Integer;
begin
if Length(v) <> 5 then
raise Exception.Create('Error: Deben ser 5 elementos');
for a := Low(v) to High(v) do
for b := Low(v) to High(v) do
for c := Low(v) to High(v) do
for d := Low(v) to High(v) do
for e := Low(v) to High(v) do
if not(
(v[a]=v[b])or(v[a]=v[c])or(v[a]=v[d])or(v[a]=v[e])or
(v[b]=v[c])or(v[b]=v[d])or(v[b]=v[e])or
(v[c]=v[d])or(v[c]=v[e])or
(v[d]=v[e])) then
Serie.Add(Format('%d %d %d %d %d',[v[a], v[b], v[c], v[d], v[e]]));
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if Open.Execute then
begin
LoadFromCSV(lista3, open.FileName);
lista3.Column[0].Width:= 85;
lista3.Column[1].Width:=30;
lista3.Column[2].Width:=30;
lista3.Column[3].Width:=30;
lista3.Column[4].Width:=30;
lista3.Column[5].Width:=30;
lista3.Column[6].Width:=30;
stB.Panels.Items[0].Text:= 'Núm. Filas: '+IntToStr(lista.Items.Count);
button9.Enabled:=true;
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
var
i, j, cinco: integer;
res, cad1, cad2:Int64;
comunes:String;
list:TStringList;
begin
Application.ProcessMessages;
stB.Panels.Items[0].Text:= 'Combinaciones: '+IntToStr(lista3.Items.Count);
stB.Panels.Items[1].Text:= 'Permutaciones: '+IntToStr(per.Items.Count);
timer1.Enabled:= true;
cinco:= 0;
for i := 0 to lista3.Items.Count -1 do
begin
barra.Max:= lista3.Items.Count;
barra.Position:= i+1;
with lista3 do
begin
selected := Items[i];
label31.Caption:= IntToStr(i+1); list.delimitedText:= items.Item[i].SubItems[0]+' '+items.Item[i].SubItems[1]+
' '+items.Item[i].SubItems[2]+' '+items.Item[i].SubItems[3]+
' '+items.Item[i].SubItems[4];
cad1:= ValorCombinacion(list);
label21.Caption:= IntToStr(cad1);
buscarcomunes(cad1);
stB.Panels.Items[4].Text:= FormatFloat('0.00',(i * 100) / lista3.items.Count)+'%';
end;
end;
end;
end.
Y
aquí puedes ver el programa en funcionamiento...
Como puedes ver ni las barras de progreso se mueven ni las etiquetas F y P muestran los valores de i y j que serían los elementos seleccionados de lista3 y per.
Un saludo.