H
Hexi
Unregistered / Unconfirmed
GUEST, unregistred user!
我在Delphi5中运行下面的程序,明明ListBox2.Item.Count>0,
却运行到for i:=0 to ListBox2.Items.Count-1do
ListBox2.Selected:=True;
时所ListBox越界out of bound(0);
这是不是TListBox的一个bug?
type
TForm3 = class(TForm)
SpeedButton1: TSpeedButton;//将ListBox1中的选项剪切到ListBox2
SpeedButton2: TSpeedButton;//将剪切所有1->2
SpeedButton3: TSpeedButton;//将ListBox2中的选项剪切到ListBox1
SpeedButton4: TSpeedButton;//将剪切所有2->1
ListBox1: TListBox;
ListBox2: TListBox;
procedure ListBox1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure ListBox2DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CheckValid;//设置按钮有效性
procedure MoveItems(FromL,ToL:TListBox);//剪切所选项
end;
procedure TForm3.CheckValid;
begin
if (ListBox1.Items.Count=0) or (ListBox1.SelCount=0) then
SpeedButton1.Enabled:=False
else
SpeedButton1.Enabled:=True;
if (ListBox1.Items.Count=0) then
SpeedButton2.Enabled:=False
else
SpeedButton2.Enabled:=True;
if (ListBox2.Items.Count=0) or (ListBox2.SelCount=0) then
SpeedButton3.Enabled:=False
else
SpeedButton3.Enabled:=True;
if (ListBox2.Items.Count=0) then
SpeedButton4.Enabled:=False
else
SpeedButton4.Enabled:=True;
end;
procedure TForm3.ListBox1Click(Sender: TObject);
begin
CheckValid;
end;
procedure TForm3.MoveItems(FromL, ToL:TListBox);
var
i:Integer;
begin
for i:=0 to FromL.Items.Count-1do
if FromL.Selected then
ToL.Items.Add(FromL.Items);
for i:=FromL.Items.Count-1do
wnto 0do
if FromL.Selected then
FromL.Items.Delete(i);
CheckValid;
end;
procedure TForm3.SpeedButton1Click(Sender: TObject);
begin
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.SpeedButton3Click(Sender: TObject);
begin
MoveItems(ListBox2, ListBox1);
end;
procedure TForm3.SpeedButton2Click(Sender: TObject);
var i:Integer;
begin
for i:=0 to ListBox1.Items.Count-1do
ListBox1.Selected:=True;
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.SpeedButton4Click(Sender: TObject);
var i:Integer;
begin
for i:=0 to ListBox2.Items.Count-1do
ListBox2.Selected:=True;
MoveItems(ListBox2, ListBox1);
end;
procedure TForm3.ListBox1DblClick(Sender: TObject);
begin
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.ListBox2DblClick(Sender: TObject);
begin
MoveItems(ListBox2, ListBox1);
end;
end.
却运行到for i:=0 to ListBox2.Items.Count-1do
ListBox2.Selected:=True;
时所ListBox越界out of bound(0);
这是不是TListBox的一个bug?
type
TForm3 = class(TForm)
SpeedButton1: TSpeedButton;//将ListBox1中的选项剪切到ListBox2
SpeedButton2: TSpeedButton;//将剪切所有1->2
SpeedButton3: TSpeedButton;//将ListBox2中的选项剪切到ListBox1
SpeedButton4: TSpeedButton;//将剪切所有2->1
ListBox1: TListBox;
ListBox2: TListBox;
procedure ListBox1Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure ListBox1DblClick(Sender: TObject);
procedure ListBox2DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CheckValid;//设置按钮有效性
procedure MoveItems(FromL,ToL:TListBox);//剪切所选项
end;
procedure TForm3.CheckValid;
begin
if (ListBox1.Items.Count=0) or (ListBox1.SelCount=0) then
SpeedButton1.Enabled:=False
else
SpeedButton1.Enabled:=True;
if (ListBox1.Items.Count=0) then
SpeedButton2.Enabled:=False
else
SpeedButton2.Enabled:=True;
if (ListBox2.Items.Count=0) or (ListBox2.SelCount=0) then
SpeedButton3.Enabled:=False
else
SpeedButton3.Enabled:=True;
if (ListBox2.Items.Count=0) then
SpeedButton4.Enabled:=False
else
SpeedButton4.Enabled:=True;
end;
procedure TForm3.ListBox1Click(Sender: TObject);
begin
CheckValid;
end;
procedure TForm3.MoveItems(FromL, ToL:TListBox);
var
i:Integer;
begin
for i:=0 to FromL.Items.Count-1do
if FromL.Selected then
ToL.Items.Add(FromL.Items);
for i:=FromL.Items.Count-1do
wnto 0do
if FromL.Selected then
FromL.Items.Delete(i);
CheckValid;
end;
procedure TForm3.SpeedButton1Click(Sender: TObject);
begin
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.SpeedButton3Click(Sender: TObject);
begin
MoveItems(ListBox2, ListBox1);
end;
procedure TForm3.SpeedButton2Click(Sender: TObject);
var i:Integer;
begin
for i:=0 to ListBox1.Items.Count-1do
ListBox1.Selected:=True;
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.SpeedButton4Click(Sender: TObject);
var i:Integer;
begin
for i:=0 to ListBox2.Items.Count-1do
ListBox2.Selected:=True;
MoveItems(ListBox2, ListBox1);
end;
procedure TForm3.ListBox1DblClick(Sender: TObject);
begin
MoveItems(ListBox1, ListBox2);
end;
procedure TForm3.ListBox2DblClick(Sender: TObject);
begin
MoveItems(ListBox2, ListBox1);
end;
end.