線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1369
推到 Plurk!
推到 Facebook!

動能產生和free元件??

答題得分者是:andersonhsieh
jck1
一般會員


發表:53
回覆:67
積分:24
註冊:2002-05-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-08-30 16:50:10 IP:211.22.xxx.xxx 未訂閱
我動態產生了200個元件 但在free他們時 會出現list index out of bounds 103 不知道是哪裡錯誤了。 form的一開始有兩個button 及一個label 和一個 edit    
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
  aedt: tedit;
  albl: tlabel;
begin
  for i:= 1 to 100 do begin
    aedt:= tedit.create(self);
    aedt.parent:= self;
    aedt.visible:= true;
    aedt.tag:= 9000   i;
    aedt.top:= i * 20;
  end;
  for i:= 1 to 100 do begin
    albl:= tlabel.create(self);
    albl.parent:= self;
    albl.visible:= true;
    albl.tag:= 9000   i;
    albl.top:= i * 20;
    albl.left:= 300;
    albl.caption:= inttostr(i);
  end;    end;    procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i := componentCount -1 downto 1 do begin
    if(components[i] is tedit)then begin
      if(tedit(components[i]).tag > 9000)then begin
        tedit(components[i]).visible:= false;
        tedit(components[i]).free;
      end;
    end;
    if(components[i] is tlabel)then begin
      if(tlabel(components[i]).tag > 9000)then begin
        tlabel(components[i]).visible:= false;
        tlabel(components[i]).free;
      end;
    end;
  end;
end;
andersonhsieh
版主


發表:33
回覆:531
積分:439
註冊:2002-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-08-30 17:01:52 IP:211.20.xxx.xxx 未訂閱
procedure TForm1.Button2Click(Sender: TObject); var   i: integer; begin   for i := componentCount -1 downto 1 do begin     if(components[i] is tedit)then begin       if(tedit(components[i]).tag > 9000)then begin         tedit(components[i]).visible:= false;         tedit(components[i]).free;       end;     end; else if(components[i] is tlabel)then begin//修改這裡 if(tlabel(components[i]).tag > 9000)then begin tlabel(components[i]).visible:= false; tlabel(components[i]).free; end; end; end; end; 原因是因為當components[i] is tedit時會被你free掉,就不能被你拿來做任何的動作 @@~~飛翔在天際的精靈~~@@ 發表人 - andersonhsieh 於 2002/08/30 17:04:29
------
@@~~飛翔在天際的精靈~~@@
jck1
一般會員


發表:53
回覆:67
積分:24
註冊:2002-05-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-08-30 17:08:46 IP:211.22.xxx.xxx 未訂閱
引言: procedure TForm1.Button2Click(Sender: TObject); var i: integer; begin for i := componentCount -1 downto 1 do begin if(components[i] is tedit)then begin if(tedit(components[i]).tag > 9000)then begin tedit(components[i]).visible:= false; tedit(components[i]).free; end; end; else if(components[i] is tlabel)then begin//修改這裡 if(tlabel(components[i]).tag > 9000)then begin tlabel(components[i]).visible:= false; tlabel(components[i]).free; end; end; end; end; 原因是因為當components[i] is tedit時會被你free掉,就不能被你拿來做任何的動作 @@~~飛翔在天際的精靈~~@@ 發表人 - andersonhsieh 於 2002/08/30 17:04:29
這個錯誤我找了好久 原來是這樣喔 謝謝版主 ^^
系統時間:2024-04-18 18:47:40
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!