遇到一个奇怪的问题:
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
s: myrecord;
begin
HashList := THashedStringList.Create ;
for i:= 1 to 20 do
begin
s := myrecord.Create ;
s.name :='sdf';
s.age := i ;
if i= 100 then
HashList.AddObject(inttostr(i),s)
else
HashList.AddObject(inttostr(i),s);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
for i:= HashList.Count -1 downto 0 do
begin
memo1.Lines.Add(myrecord(HashList.Objects).name + IntTostr(myrecord(HashList.Objects).age ))
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
index: integer ;
str: string ;
i: integer;
begin
for i:= 1 to 20 do
begin
str:= inttostr(i);
if HashList.Find(str, index) then
memo1.Lines.Add(myrecord(HashList.Objects[index]).name + IntTostr(myrecord(HashList.Objects[index]).age ))
end;
end;
先电击了button1创建了20个对象,点击button2,Memo1中可以从
sdf20
sdf19
sdf18
sdf17
sdf16
sdf15
sdf14
sdf13
sdf12
sdf11
sdf10
sdf9
sdf8
sdf7
sdf6
sdf5
sdf4
sdf3
sdf2
sdf1 //也就是全部都显示出来了
可是点button3显示出来的只有
sdf1
sdf10
sdf11
sdf12
sdf13
sdf14
sdf15
sdf16
sdf17
sdf18
sdf19
sdf20
请高手解决