J
jackyxinli
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个CD播放器,我在播放时将CD上的track写到PopupMenu的Item里,这我已经做到了,但我在程序中弹出CD时想将我写到PopupMenu里的Item删除,并用以下语句:
procedure TMainForm.DeleteItem;
var
CDIndex: Integer;
begin
for CDIndex := 1 to CDTracks.Count do
CDTracks.Delete(0);
//CDTracks是PopupMenu上的一个菜单项
end;
procedure TMainForm.Additem;
var
CDIndex: Integer;
TrackItem: TMenuItem;
begin
TrackItem := TMenuItem.Create(CDTracks);
for CDIndex := 1 to CDTracks.Count do
CDTracks.Delete(0);
for CDIndex := 1 to MediaPlayer.Tracks do
begin
if CDIndex < 10 then
TrackItem.Caption := 'Track 0'+ IntToStr(CDIndex)
else
TrackItem.Caption := 'Track '+ IntToStr(CEIndex);
PopupMenu.Items[1].Add(TrackItem);
end;
end;
我写了以上的代码,但在删除Item是delphi出错,错误为:'List Index Out of bounds(0)',但我检查了代码,没发现有错。
请高手指点指点,谢谢!!
procedure TMainForm.DeleteItem;
var
CDIndex: Integer;
begin
for CDIndex := 1 to CDTracks.Count do
CDTracks.Delete(0);
//CDTracks是PopupMenu上的一个菜单项
end;
procedure TMainForm.Additem;
var
CDIndex: Integer;
TrackItem: TMenuItem;
begin
TrackItem := TMenuItem.Create(CDTracks);
for CDIndex := 1 to CDTracks.Count do
CDTracks.Delete(0);
for CDIndex := 1 to MediaPlayer.Tracks do
begin
if CDIndex < 10 then
TrackItem.Caption := 'Track 0'+ IntToStr(CDIndex)
else
TrackItem.Caption := 'Track '+ IntToStr(CEIndex);
PopupMenu.Items[1].Add(TrackItem);
end;
end;
我写了以上的代码,但在删除Item是delphi出错,错误为:'List Index Out of bounds(0)',但我检查了代码,没发现有错。
请高手指点指点,谢谢!!