我的程序大概如下:
for i:=0 to n do
cheader:=Tqrlabel.create(qrlistform.QuickRep1);
with qrlistform do
begin
cheader.Parent:=qrlistform.ColumnHeaderBand1;
cheader.Caption:=a[i];
cheader.Width:=(ColumnHeaderBand1.width div n);
cheader.Height:=ColumnHeaderBand1.Height;
top:=2;
end;
。
。
。
。
for i:=1 to n-1 do
begin
shap:=Tqrshape.create(qrlistform.DetailBand1);
with qrlistform do
begin
shap.Parent:=qrlistform.DetailBand1;
shap.Width:=1;
shap.Height:=qrlistform.DetailBand1.Height;
shap.Left:=leftv+((ColumnHeaderBand1.width div n)*(i))-5;
top:=0;
end;
end ;
qrlistform.QuickRep1.Preview;
shap.Free;
detailtext.Free;
cheader.Free;
但是再次运行时它就有上一次所创建的东西,什么才能把上一次所有所创建的都弃放掉呢??
for i:=0 to n do
cheader:=Tqrlabel.create(qrlistform.QuickRep1);
with qrlistform do
begin
cheader.Parent:=qrlistform.ColumnHeaderBand1;
cheader.Caption:=a[i];
cheader.Width:=(ColumnHeaderBand1.width div n);
cheader.Height:=ColumnHeaderBand1.Height;
top:=2;
end;
。
。
。
。
for i:=1 to n-1 do
begin
shap:=Tqrshape.create(qrlistform.DetailBand1);
with qrlistform do
begin
shap.Parent:=qrlistform.DetailBand1;
shap.Width:=1;
shap.Height:=qrlistform.DetailBand1.Height;
shap.Left:=leftv+((ColumnHeaderBand1.width div n)*(i))-5;
top:=0;
end;
end ;
qrlistform.QuickRep1.Preview;
shap.Free;
detailtext.Free;
cheader.Free;
但是再次运行时它就有上一次所创建的东西,什么才能把上一次所有所创建的都弃放掉呢??
2 释放使用FreeAndNil
要不直接把窗体释放掉更好了
最好,你将整个窗口都释放掉,再用时重新建立!
要么,你也可用
var i: integer;for i:=0 to ComponentCount-1 do
FreeAndNil(Components[i]);将所有创建的控件释放!!
遍历所有控件,检查到你创建的,你就释放掉