窗体里有动态生成的控件,在关闭时报错?

killserver killserver 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
窗体里有tchart控件,动态生了一些checkbox,勾选checkbox作图,在关闭窗体时报错,代码如下:
//这是释放控件过程,在窗体close事件里有调用.
procedure TFrmHB.FreeFormCtrl();
var i,igroup:integer;
begin
try
for igroup:=self.PageControl1.PageCount-1 downto 0 do begin
for i:=self.PageControl1.Pages[igroup].ControlCount-1 downto 0 do begin
self.PageControl1.Pages[igroup].Controls[i].Free;
end;
end;
for i:=self.GroupBox1.ControlCount-1 downto 0 do begin
self.GroupBox1.Controls[i].Free;
end;
for i:=self.Chart1.SeriesCount-1 downto 0 do begin
self.Chart1.Series[i].Free;
end;

except
on e:erangeerror do
begin
messagedlg(e.Message,mterror,[mbok],0);
end;
end;
//这是生成控件的过程 在点击作图按留时调用
procedure TFrmHB.setItemView();
var
pColorBox: TColorBox;
pCheckBox: TCheckBox;
intTop,intLeft,intCell,colorid:integer;
ssql,itemcode,itemName:string;
begin
intCell:=1;inttop:=20;intleft:=10;
ssql:='SELECT * FROM V_UserView where userid=' + self.userid + ' and fitemcode<>''sstate'' order by forder';
customerdata.GetAdoQuery(ssql);
if customerdata.ADOQuery1.IsEmpty then exit;
try
while not customerdata.ADOQuery1.Eof do begin
if not customerdata.ADOQuery1.FieldByName('FitemName').IsNull then begin
itemName:= customerdata.ADOQuery1.FieldValues['FitemName'];
if not customerdata.ADOQuery1.FieldByName('fitemcode').IsNull then begin
itemcode:=customerdata.ADOQuery1.FieldValues['fitemcode'];
end;
if not customerdata.ADOQuery1.FieldByName('colorindex').IsNull then begin
colorid:=strtoint(customerdata.ADOQuery1.FieldValues['colorindex']);
end else begin
colorid:=0;
end;
pCheckBox:=TCheckBox.Create(self);
pcheckbox.Parent:=self.GroupBox1 ;
pCheckBox.Caption:= itemName;

pcheckbox.Name:='pcheckbox'+ itemcode;
pcheckbox.Hint:=inttostr(intCell);
if intcell<=2 then pcheckbox.Checked:=true;
pcheckbox.Width:=70;
pcheckbox.Top:=inttop;
pcheckbox.Left:= intLeft;
pcheckbox.OnClick:=myCheckBoxClick;

pColorBox:=TColorBox.Create(self);
pColorBox.Parent:=self.GroupBox1 ;
pColorBox.Name:='pColorBox' + itemcode;
pColorBox.Hint:=inttostr(intCell);
pColorBox.ItemIndex:=colorid;
pColorBox.Width:=40;
pColorBox.Top:= pcheckbox.top;
pColorBox.Left:=pcheckbox.Left+pcheckbox.Width;
pColorBox.OnChange:=myColorBoxChange;
intCell:=intCell+1;
if self.GroupBox1.ControlCount =10 then begin
inttop:=inttop+20;
intleft:=10;
end else begin
intleft:=intleft+pcolorbox.Width+pcheckbox.Width;
end;
end;
customerdata.ADOQuery1.Next;
end;
finally
customerdata.ADOQuery1.Close;
customerdata.pubCnn.Close;
end;

end;
//这是作图的过程 在myColorBoxChange myCheckBoxClick都有调用
procedure TFrmHB.DrawWhole();
var
pSeries:tFastLineSeries;
i,ii,intSeries,intCell:integer;
tmpHorizAxis:TchartAxis;
pColorBox: TColorBox;
pCheckBox: TCheckBox;
colorboxname:string;
begin
if pUnitp=nil then exit ;
try
self.Chart1.CustomAxes.Clear;
self.Chart1.SeriesList.Clear;

for i:=0 to self.GroupBox1.ControlCount-1 do begin
if self.GroupBox1.Controls[i].ClassName='TCheckBox' then begin
pCheckBox:= TCheckBox(self.GroupBox1.Controls[i]);
if pCheckBox.Checked then begin
colorboxname:=stringreplace(pCheckBox.Name,'pcheckbox','pColorBox',[rfReplaceAll]);
pColorBox:=TColorBox(self.GroupBox1.FindChildControl(colorboxname));
pSeries:=TFastLineSeries.Create(self);
self.Chart1.AddSeries(pSeries);
pSeries.SeriesColor:= pColorBox.Selected;
pSeries.xValues.Order:=lonone;
pSeries.xValues.Sort;
pSeries.YValues.Order:=loascending;
pSeries.YValues.Sort;
pSeries.Title:=pCheckBox.Caption; {//}
intCell:=strtoint(pCheckBox.Hint);
for ii:=0 to high(pUnitp.arr_Sd_Jiao_P_T) do begin
pSeries.AddXY(strtofloat(self.StringGrid1.Cells[intCell,ii+1]),strtofloat(self.StringGrid1.Cells[0,ii+1]));
end;
if self.chbsame.Checked=false then begin
self.Chart1.CustomAxes.Add;
intSeries:= self.Chart1.CustomAxes.Count-1;
tmpHorizAxis:=self.Chart1.CustomAxes[intSeries];
tmpHorizAxis.Horizontal:=true;
tmpHorizAxis.Axis.Color:=pColorBox.Selected;
tmpHorizAxis.PositionPercent:=100+self.Chart1.CustomAxes.Count*3;
tmpHorizAxis.LabelsSize:=5;
tmpHorizAxis.LabelsFont.Size:=7;
self.Chart1.AxisBehind:=false;
pSeries.CustomHorizAxis:=tmpHorizAxis;
end;
end
end;
end;
except
on e:erangeerror do
messagedlg(e.Message,mterror,[mbok],0);
end;
end;
...全文

相关推荐

VB动态增加删除窗体控件元素

内容索引:VB源码,界面编程,控件,按钮  VB动态增加删除窗体控件元素,比如本实例在窗体上动态添加一个按钮,同时还可以删除它,方法很简单,但是挺有用的功能,有必要掌握哦。

weixin_38675815

KonopkaControls控件库:Delphi桌面开发的安装与核心控件实战指南

在Windows桌面应用开发中,原生窗口控件的交互体验和视觉风格往往难以统一,而基于Delphi VCL的第三方控件库能够显著改善这一问题。Konopka Controls是一套免费开源的VCL控件库,采用纯VCL实现且不依赖额外运行时,通过GDI自绘机制提供按钮、滑块、仪表盘、进度条等高度可定制的交互组件。其中TtkGauge可快速构建半圆或全圆仪表盘,TtkSlider适合高精度连续量调节,在工业控制、医疗仪器、数据采集等上位机桌面工具中应用广泛。内容涵盖环境检查与版本选择、运行期包编译、设计期包安装、

weixin_30709061

过往总结——Allegro报错自动关闭问题

自己在用Allegro SPB 16.3中的Allegro PCB Design GXL绘制PCB时,曾经两次遇到过报错自动关闭的问题,换用Allegro PCB Design XL后可以正常运行,虽然自己绘制的PCB并不复杂,XL足以满足要求,但总觉得很不舒服。

weixin_38684806

关于Allegro报错自动关闭问题

在网上搜索了很多解决方法,诸如使用DB doctor进行检查等方法,都不见有作用。

weixin_38621630

关于Allegro报错自动关闭的问题

本文将介绍关于Allegro报错自动关闭问题

weixin_38555616
评论 9
收藏 已收藏
分享
返回顶部
killserver
Delphi 5,944 成员 262,941 内容