Buenos dias,
La aplicacion ya funciona con sus mas y sus menos, pero si una vez cargado el archivo con el contenido de la lista intengo continuar con el proceso me dice:
"Access violation at address 00000000. Read of address 00000000" Pero si agrego un boton de prueba y dentro escribro:
Código Delphi
[-]...
lista.items.add.subitems.add('prueba');
...
Se agrega un nuevo item al final de la lista y no da error. ¿alguna sugerencia?
El codigo que genera numeros es este:
Código Delphi
[-]unit uTAlea;
interface
uses Windows,SysUtils, Math;
type
TArrayBool = array[0..0] of boolean;
PArrayBool = ^TArrayBool;
TAlea = class
Maximo : integer; Lista : PArrayBool;
FaltanDeSacar : integer;
constructor Create(Rango:integer);
destructor Destroy; override;
procedure Reset; function PillaNumero:integer; end;
implementation
constructor TAlea.Create(Rango:integer);
begin
inherited Create;
Maximo:=Rango;
FaltanDeSacar:=Rango;
GetMem(Lista, 1+Maximo * SizeOf(Boolean));
ZeroMemory(Lista,1+Maximo * SizeOf(Boolean));
end;
destructor TAlea.Destroy;
begin
if Assigned(Lista) then FreeMem(Lista, 1+Maximo * SizeOf(Boolean));
inherited Destroy;
end;
function TAlea.PillaNumero:integer;
var
Numero: integer;
begin
if FaltanDeSacar=0 then raise exception.create( 'Error. No se pude sacar otro numero sin repetir'+#13+#10+
'Error. No more numbers are available');
repeat
Numero:=RandomRange(1,49)
until NOT Lista^[Numero];
Lista^[Numero]:=TRUE;
Dec(FaltanDeSacar);
Result:=Numero;
end;
procedure TAlea.Reset;
begin
ZeroMemory(Lista,1+Maximo * SizeOf(Boolean));
FaltanDeSacar:=Maximo;
end;
end.
Y la llamada a la funcion esta:
Código Delphi
[-]...
case comb.ItemIndex of
0: begin
timer1.Enabled:= true;
barra.MinValue:= 0;
barra.Maxvalue:= 50000;
for i:= 0 to 49999 do
begin
label4.Caption:= IntToStr((i)+1);
Ristra:=TAlea.Create(49);
with lista.Items.Add do
begin
subitems.Add(IntToStr(ristra.PillaNumero));
subitems.Add(IntToStr(ristra.PillaNumero));
subitems.Add(IntToStr(ristra.PillaNumero));
subitems.Add(IntToStr(ristra.PillaNumero));
subitems.Add(IntToStr(ristra.PillaNumero));
subitems.Add(IntToStr(ristra.PillaNumero));
Ristra.Free;
end;
barra.Progress:= i;
label20.Caption:= FormatFloat('0.00',((i*100)/50000))+'%';
end;
end;
...
¿Por que no pueden agregarse items al final del listado previamente cargado desde fichero?
Gracias y un saludo.