DELPHI TListBox (TStringsÀà)ɾ³ý¿ÕÐеķ½·¨
֮ǰ×öÒ»¸ö³ÌÐò£¬ÓÃListBox¶ÁÈëÒ»¸öÎı¾Îļþ£¬µ«Îı¾ÖÐÓпÕÐУ¬ÎªÁËɾ³ýÆäÖеĿÕÐУ¬ÕÛÌÚÁ˺ó¤Ê±¼ä¡£
Ïȸø³öÒ»¶Î´úÂë¸ø´ó¼Ò¿´
var
i:Integer;
begin
ListBox1.Items.LoadfromFile('data.txt');
for i:=0 to ListBox1.Count - 1 do
begin
if Trim(ListBox1.Items.Strings[i])='' Then
ListBox1.Items.Delete(i);
end;
end;
ÏàÐŲ»ÉÙÈË»áÕâÑùд£¨°üÀ¨ÎÒÒÔÇ°Ò²ÊÇ£©£¬ÌرðÊÇÐÂÊÖ£¬µ«ÊÇÕâÊÇÐв»Í¨µÄ£¬ÔËÐÐʱ¸ø³ö list index out of bounds ´íÎó£¨Ï±곬½ç£©£¬ÎªÊ²Ã´»áÕâÑùÄØ£¿
Ö÷ÒªÊÇÕâ¸öforÑ»·ÖÐtoºóÃæµÄ ListBox1.Count ÒÑÊÇ×÷Ϊһ¸ö¹Ì¶¨Öµ£¬²»»á¸Ä±äµÄ£¬¶øÏÂÃæÖ´ÐÐÁËListBox1.Items.Delete(i); £¬µ¼ÖÂListBox1 ÖеÄÊýÄ¿¼õÉÙ£¬ËùÒÔ»á³öÏÖϱ곬½çµÄ´íÎó¡£
Æäʵ½â¾öÕâ¸öÎÊÌâºÜ¼òµ¥£¬¸Ä±äÒ»ÏÂ˼ά·½Ê½¾Í¿ÉÒÔÁË£¬½«forÑ»·¸ÄΪ
i:=ListBox1.Count - 1;
while(i>0)do
begin
if Trim(ListBox1.Items.Strings[i])='' Then
ListBox1.Items.Delete(i);
Dec(i);
end;
ÑÝʾ³ÌÐò£¨Ô´Â룩ÎÒÒѾ´ò°üÉÏ´«ÁË£¬´ó¼Ò¿ÉÒÔÏÂÔØ¿´¿´
ÑÝʾ³ÌÐòÏÂÔØ
Ïà¹ØÎĵµ£º
±¾ÎÄתÔØ:http://rabbitfox.blog.sohu.com/29948084.html
http://delphi.about.com/od/fileio/a/fileof_delphi.htm
Ê×ÏÈÏò×÷Õß±íʾ¸Ðл£¡
¡¶ÀûÓÃDelphiµÄ“File Of
Type”´´½¨²¢¹ÜÀíÊôÓÚÄã×Ô¼ºµÄ“Êý¾Ý¿â”¡·
Ô×÷Õߣ ......
Ë÷ÒýÊÇitemindex
itemÊÇÀïÃæµÄÄÚÈÝ
Ë÷ÒýµÄ»°£¬ÊÇ´Ó0¿ªÊ¼
item itemindex
A 1
B 2
C 3
listbox1.items.count¾ÍÊÇÕâ¸öÁбí¿òÀï×ܹ²ÓжàÉÙÏî. ......
Delphi Äܲ»ÄÜ´ÓRing 3½øÈëRing 0?
Â¥Ö÷skyworld_xm£¨skyworld£©2004-11-19 09:58:55 ÔÚ Delphi / Windows SDK/API ÌáÎÊ
Delphi Äܲ»ÄÜ´ÓRing 3½øÈëRing 0?
ÓÐÀý×ÓÂð?
¶àл. ÎÊÌâµãÊý£º100¡¢»Ø¸´´ÎÊý£º20Top
1 Â¥jinjazz£¨½üÉí¼ô£©»Ø¸´ÓÚ 2004-11-19 10:13:27 µÃ ......