動態產生的物件要釋放一直有問題? |
答題得分者是:cmf
|
kagaya
中階會員 發表:74 回覆:175 積分:59 註冊:2002-12-28 發送簡訊給我 |
原始碼如下.t4count是一個值.表示要產生的物件數量
t4count大於0時.表示已經有物件.先釋放之前產生的物件(數量為t4count)
再取得新的t4count來產生新的物件
但是t4count>0時在free時便出現錯誤訊息
不知道該怎麼做才能正常的釋放?謝謝 procedure TForm3.FormActivate(Sender: TObject);
var x, y, z: integer;
begin
kid.Caption := kk.id;
kname2.Caption := kk.name2 ' ';
klv.Caption := kk.lv;
kdis.Caption := floattostr(kk.discount) ' 折';
kmoney.Caption := inttostr(kk.money);
kpic.Caption := inttostr(kk.pic);
kpost.Caption := '0';
kpay.Caption := '0';
kpay2.Caption := '0';
kpay3.Caption := '0';
kuse46.Caption := '0';
memo1.Clear; if t4count > 0 then
begin
for z := 0 to 6 do
begin
if Assigned(ttitle[z]) then ttitle[z].Free;
end;
for z := 0 to t4count - 1 do
begin
if Assigned(tname[z]) then tname[z].Free;
if Assigned(tprice[z]) then tprice[z].Free;
if Assigned(ttotal[z]) then ttotal[z].Free;
if Assigned(tkill[z]) then tkill[z].Free;
if Assigned(tsize[z]) then tsize[z].Free;
if Assigned(tqty[z]) then tqty[z].Free;
if Assigned(ttext2[z]) then ttext2[z].Free;
end; end; t4count := form1.dr4.SelCount;
if t4count > 0 then
begin setlength(tname, t4count);
setlength(tprice, t4count);
setlength(ttotal, t4count);
setlength(tkill, t4count);
setlength(tsize, t4count);
setlength(tqty, t4count);
setlength(ttext2, t4count);
setlength(ttitle, 6); ttitle[0] := tlabel.Create(form3);
ttitle[0].Parent := box1;
ttitle[0].Width := 100;
ttitle[0].Height := 20;
ttitle[0].Left := 0;
ttitle[0].Top := 0;
ttitle[0].Caption := '檔名 ';
ttitle[0].Show; ttitle[1] := tlabel.Create(form3);
ttitle[1].Parent := box1;
ttitle[1].Width := 60;
ttitle[1].Height := 20;
ttitle[1].Left := 100;
ttitle[1].Top := 0;
ttitle[1].Caption := '裁切 ';
ttitle[1].Show; ttitle[2] := tlabel.Create(form3);
ttitle[2].Parent := box1;
ttitle[2].Width := 60;
ttitle[2].Height := 20;
ttitle[2].Left := 160;
ttitle[2].Top := 0;
ttitle[2].Caption := '尺寸 ';
ttitle[2].Show; ttitle[3] := tlabel.Create(form3);
ttitle[3].Parent := box1;
ttitle[3].Width := 60;
ttitle[3].Height := 20;
ttitle[3].Left := 220;
ttitle[3].Top := 0;
ttitle[3].Caption := '張數 ';
ttitle[3].Show; ttitle[4] := tlabel.Create(form3);
ttitle[4].Parent := box1;
ttitle[4].Width := 60;
ttitle[4].Height := 20;
ttitle[4].Left := 300;
ttitle[4].Top := 0;
ttitle[4].Caption := '單價 ';
ttitle[4].Show; ttitle[5] := tlabel.Create(form3);
ttitle[5].Parent := box1;
ttitle[5].Width := 60;
ttitle[5].Height := 20;
ttitle[5].Left := 380;
ttitle[5].Top := 0;
ttitle[5].Caption := '小計 ';
ttitle[5].Show; ttitle[6] := tlabel.Create(form3);
ttitle[6].Parent := box1;
ttitle[6].Width := 150;
ttitle[6].Height := 20;
ttitle[6].Left := 440;
ttitle[6].Top := 0;
ttitle[6].Caption := '附註 ';
ttitle[6].Show; z := 0;
for y := 0 to form1.dr4.Items.Count - 1 do
begin
if form1.dr4.Selected[y] = true then
begin
tname[z] := tlabel.Create(form3);
tname[z].Parent := box1;
tname[z].Width := 100;
tname[z].Height := 20;
tname[z].Left := 0;
tname[z].Top := z * 20 20;
tname[z].Caption := form1.dr4.Items.Strings[y];
tname[z].Show; tkill[z] := Tcombobox.Create(form3);
tkill[z].Parent := box1;
tkill[z].Width := 60;
tkill[z].Height := 18;
tkill[z].Left := 100;
tkill[z].Top := z * 20 20;
tkill[z].text := '是';
tkill[z].Items.Add('是');
tkill[z].Items.Add('否');
tkill[z].Show; tsize[z] := Tcombobox.Create(form3);
tsize[z].Parent := box1;
tsize[z].Width := 60;
tsize[z].Height := 18;
tsize[z].Left := 160;
tsize[z].Top := z * 20 20;
tsize[z].text := '4X6';
tsize[z].Items.Add('3X5');
tsize[z].Items.Add('4X6');
tsize[z].Items.Add('5X7');
tsize[z].Items.Add('6X8');
tsize[z].Items.Add('8X10');
tsize[z].Items.Add('10X12');
tsize[z].Items.Add('12X15');
tsize[z].Show;
tsize[z].Tag := z;
tsize[z].Onchange := yyyy2; tqty[z] := Tcombobox.Create(form3);
tqty[z].Parent := box1;
tqty[z].Width := 60;
tqty[z].Height := 18;
tqty[z].Left := 220;
tqty[z].Top := z * 20 20;
tqty[z].text := '1';
for x := 1 to 100 do
tqty[z].Items.Add(inttostr(x));
tqty[z].Show;
tqty[z].Tag := z;
tqty[z].Onchange := yyyy2; tprice[z] := tlabel.Create(form3);
tprice[z].Parent := box1;
tprice[z].Width := 60;
tprice[z].Height := 20;
tprice[z].Left := 300;
tprice[z].Top := z * 20 20;
tprice[z].Caption := inttostr(kk.pre4);
tprice[z].Show; ttotal[z] := tlabel.Create(form3);
ttotal[z].Parent := box1;
ttotal[z].Width := 60;
ttotal[z].Height := 20;
ttotal[z].Left := 380;
ttotal[z].Top := z * 20 20;
ttotal[z].Caption := inttostr(kk.pre4);
ttotal[z].Show; ttext2[z] := tedit.Create(form3);
ttext2[z].Parent := box1;
ttext2[z].Width := 150;
ttext2[z].Height := 20;
ttext2[z].Left := 440;
ttext2[z].Top := z * 20 20;
ttext2[z].Show; z := z 1;
end;
end;
end;
howmuch;
end;
------
KUSO 無處不在 |
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
|
kagaya
中階會員 發表:74 回覆:175 積分:59 註冊:2002-12-28 發送簡訊給我 |
|
cmf
尊榮會員 發表:84 回覆:918 積分:1032 註冊:2002-06-26 發送簡訊給我 |
procedure TForm3.FormCreate(Sender: TObject);
var
z:integer;
begin
t4count:=0;
for z := 0 to 6 do
begin
ttitle[z]:=nil;
end; end; procedure TForm3.FormActivate(Sender: TObject);
var x, y, z: integer;
begin kid.Caption := kk.id;
kname2.Caption := kk.name2 + ' ';
klv.Caption := kk.lv;
kdis.Caption := floattostr(kk.discount) + ' 折';
kmoney.Caption := inttostr(kk.money);
kpic.Caption := inttostr(kk.pic);
kpost.Caption := '0';
kpay.Caption := '0';
kpay2.Caption := '0';
kpay3.Caption := '0';
kuse46.Caption := '0';
memo1.Clear; if t4count > 0 then
begin
for z := 0 to 6 do
begin
if Assigned(ttitle[z]) then
begin
try
ttitle[z].Free;
ttitle[z]:=nil;
except
showmessage('free ttitle['+ inttostr(z) +'] error');
end; end;
end; for z := 0 to t4count - 1 do
begin
try if Assigned(tname[z]) then FreeAndNil(tname[z]);
except
showmessage('free tname['+ inttostr(z) +'] error');
end; try
if Assigned(tprice[z]) then FreeAndNil(tprice[z]);
except
showmessage('free tprice['+ inttostr(z) +'] error');
end; try
if Assigned(ttotal[z]) then FreeAndNil(ttotal[z]);
except
showmessage('free ttotal['+ inttostr(z) +'] error');
end; try
if Assigned(tkill[z]) then FreeAndNil(tkill[z]);
except
showmessage('free tkill['+ inttostr(z) +'] error');
end; try
if Assigned(tsize[z]) then FreeAndNil(tsize[z]);
except
showmessage('free tsize['+ inttostr(z) +'] error');
end; try
if Assigned(tqty[z]) then FreeAndNil(tqty[z]);
except
showmessage('free tqty['+ inttostr(z) +'] error');
end; try
if Assigned(ttext2[z]) then FreeAndNil(ttext2[z]);
except
showmessage('free ttext2['+ inttostr(z) +'] error');
end; end; end; t4count := form1.dr4.SelCount; if t4count > 0 then
begin setlength(tname, t4count);
setlength(tprice, t4count);
setlength(ttotal, t4count);
setlength(tkill, t4count);
setlength(tsize, t4count);
setlength(tqty, t4count);
setlength(ttext2, t4count);
setlength(ttitle, 7); ttitle[0] := tlabel.Create(form3);
ttitle[0].Parent := box1;
ttitle[0].Width := 100;
ttitle[0].Height := 20;
ttitle[0].Left := 0;
ttitle[0].Top := 0;
ttitle[0].Caption := '檔名 ';
ttitle[0].Show; ttitle[1] := tlabel.Create(form3);
ttitle[1].Parent := box1;
ttitle[1].Width := 60;
ttitle[1].Height := 20;
ttitle[1].Left := 100;
ttitle[1].Top := 0;
ttitle[1].Caption := '裁切 ';
ttitle[1].Show; ttitle[2] := tlabel.Create(form3);
ttitle[2].Parent := box1;
ttitle[2].Width := 60;
ttitle[2].Height := 20;
ttitle[2].Left := 160;
ttitle[2].Top := 0;
ttitle[2].Caption := '尺寸 ';
ttitle[2].Show; ttitle[3] := tlabel.Create(form3);
ttitle[3].Parent := box1;
ttitle[3].Width := 60;
ttitle[3].Height := 20;
ttitle[3].Left := 220;
ttitle[3].Top := 0;
ttitle[3].Caption := '張數 ';
ttitle[3].Show; ttitle[4] := tlabel.Create(form3);
ttitle[4].Parent := box1;
ttitle[4].Width := 60;
ttitle[4].Height := 20;
ttitle[4].Left := 300;
ttitle[4].Top := 0;
ttitle[4].Caption := '單價 ';
ttitle[4].Show; ttitle[5] := tlabel.Create(form3);
ttitle[5].Parent := box1;
ttitle[5].Width := 60;
ttitle[5].Height := 20;
ttitle[5].Left := 380;
ttitle[5].Top := 0;
ttitle[5].Caption := '小計 ';
ttitle[5].Show; ttitle[6] := tlabel.Create(form3);
ttitle[6].Parent := box1;
ttitle[6].Width := 150;
ttitle[6].Height := 20;
ttitle[6].Left := 440;
ttitle[6].Top := 0;
ttitle[6].Caption := '附註 ';
ttitle[6].Show; z := 0;
for y := 0 to form1.dr4.Items.Count - 1 do
begin
if form1.dr4.Selected[y] = true then
begin
tname[z] := tlabel.Create(form3);
tname[z].Parent := box1;
tname[z].Width := 100;
tname[z].Height := 20;
tname[z].Left := 0;
tname[z].Top := z * 20 + 20;
tname[z].Caption := form1.dr4.Items.Strings[y];
tname[z].Show; tkill[z] := Tcombobox.Create(form3);
tkill[z].Parent := box1;
tkill[z].Width := 60;
tkill[z].Height := 18;
tkill[z].Left := 100;
tkill[z].Top := z * 20 + 20;
tkill[z].text := '是';
tkill[z].Items.Add('是');
tkill[z].Items.Add('否');
tkill[z].Show; tsize[z] := Tcombobox.Create(form3);
tsize[z].Parent := box1;
tsize[z].Width := 60;
tsize[z].Height := 18;
tsize[z].Left := 160;
tsize[z].Top := z * 20 + 20;
tsize[z].text := '4X6';
tsize[z].Items.Add('3X5');
tsize[z].Items.Add('4X6');
tsize[z].Items.Add('5X7');
tsize[z].Items.Add('6X8');
tsize[z].Items.Add('8X10');
tsize[z].Items.Add('10X12');
tsize[z].Items.Add('12X15');
tsize[z].Show;
tsize[z].Tag := z;
tsize[z].Onchange := yyyy2; tqty[z] := Tcombobox.Create(form3);
tqty[z].Parent := box1;
tqty[z].Width := 60;
tqty[z].Height := 18;
tqty[z].Left := 220;
tqty[z].Top := z * 20 + 20;
tqty[z].text := '1';
for x := 1 to 100 do
tqty[z].Items.Add(inttostr(x));
tqty[z].Show;
tqty[z].Tag := z;
tqty[z].Onchange := yyyy2; tprice[z] := tlabel.Create(form3);
tprice[z].Parent := box1;
tprice[z].Width := 60;
tprice[z].Height := 20;
tprice[z].Left := 300;
tprice[z].Top := z * 20 + 20;
tprice[z].Caption := inttostr(kk.pre4);
tprice[z].Show; ttotal[z] := tlabel.Create(form3);
ttotal[z].Parent := box1;
ttotal[z].Width := 60;
ttotal[z].Height := 20;
ttotal[z].Left := 380;
ttotal[z].Top := z * 20 + 20;
ttotal[z].Caption := inttostr(kk.pre4);
ttotal[z].Show; ttext2[z] := tedit.Create(form3);
ttext2[z].Parent := box1;
ttext2[z].Width := 150;
ttext2[z].Height := 20;
ttext2[z].Left := 440;
ttext2[z].Top := z * 20 + 20;
ttext2[z].Show; z := z + 1;
end; end;
end;
howmuch;
end;
------
︿︿ |
kagaya
中階會員 發表:74 回覆:175 積分:59 註冊:2002-12-28 發送簡訊給我 |
謝謝
執行時是每一個message都會秀出來(也就是只要free都有錯)
不過可以執行了.謝謝
改成如下
for z := 0 to 6 do
begin
if Assigned(ttitle[z]) then
begin
try
ttitle[z].Free;
ttitle[z] := nil;
except
//showmessage('free ttitle[' inttostr(z) '] error');
end;
end;
end; for z := 0 to t4count - 1 do
begin try if Assigned(tname[z]) then FreeAndNil(tname[z]);
except
// showmessage('free tname[' inttostr(z) '] error');
end; try
if Assigned(tprice[z]) then FreeAndNil(tprice[z]);
except
// showmessage('free tprice[' inttostr(z) '] error');
end; try
if Assigned(ttotal[z]) then FreeAndNil(ttotal[z]);
except
// showmessage('free ttotal[' inttostr(z) '] error');
end; try
if Assigned(tkill[z]) then FreeAndNil(tkill[z]);
except
// showmessage('free tkill[' inttostr(z) '] error');
end; try
if Assigned(tsize[z]) then FreeAndNil(tsize[z]);
except
// showmessage('free tsize[' inttostr(z) '] error');
end; try
if Assigned(tqty[z]) then FreeAndNil(tqty[z]);
except
// showmessage('free tqty[' inttostr(z) '] error');
end; try
if Assigned(ttext2[z]) then FreeAndNil(ttext2[z]);
except
// showmessage('free ttext2[' inttostr(z) '] error');
end; end; end;
------
KUSO 無處不在 |
ramonliu
一般會員 發表:0 回覆:3 積分:0 註冊:2002-03-13 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |