读书人

Delphi 中小弟我动态创建memo 组件

发布时间: 2012-03-22 17:43:57 作者: rapoo

Delphi 中,我动态创建memo 组件,如何释放掉他呢
我根据combobox中的值,动态的创建了几个memo 组件,假如combobox中的值改变时,如果创建的组件没有释放,则报错,想问下如何释放掉,代码:
procedure Tf_brgh.ComboBox3Change(Sender: TObject); //添加医生 ,价格

var i:integer;
jg,sqlstr,rq,time,name:string;
myimage:array[0..8] ;
var button:Tbutton;
var memo :Tmemo;
begin

rq:=formatdatetime( 'yyyy-mm-dd ', now());
if radiobutton3.Checked=true then
begin
sxw:= '上午 '
end;
if radiobutton4.Checked=true then
begin
sxw:= '下午 '
end;
sqlstr:= 'select * from hmis_MZGH_hb where ks= ' ' '+trim(combobox3.text)+ ' ' 'and sxw= ' ' '+sxw+ ' ' 'and rq= ' ' '+rq+ ' ' ' ';
if radiobutton5.Checked=true then
begin
sxw:= '急诊 ';
sqlstr:= 'select * from hmis_MZGH_hb where ks= ' ' '+trim(combobox3.text)+ ' ' 'and hb= ' ' '+sxw+ ' ' 'and rq= ' ' '+rq+ ' ' ' ';
end;
{ if Sender is Tmemo then
begin
name:=Tmemo(Sender).Name;

end; }


with f_db.ghcx do
begin
close;
CommandText:=sqlstr;
open;
recordcount1:=recordcount;
i:=0;

while not eof do
begin
memo:=Tmemo.Create(self);


memo.Parent :=self;
memo.Name:= 'N_ '+fieldbyname( 'id ').AsString;

memo.Lines.Add( '医师 '+ ': '+fieldbyname( 'ysxm ').AsString);
memo.Lines.Add( '号别 '+ ': '+fieldbyname( 'hb ').AsString);
memo.Lines.Add( '价格 '+ ': '+fieldbyname( 'jg ').AsString+ '元 ');
memo.Lines.Add( '限制号 '+ ': '+fieldbyname( 'xzh ').AsString);
memo.Left:=232+i*180;
memo.Width:=103;
if memo.Left> =768 then
begin
memo.Top:=323;
end
else
memo.Top:=248;
memo.Width:=150;
memo.Height:=100;

i:=i+1;
memo.OnClick:=myproc;


next;
end;
end;
end;
请各位高手帮帮忙咯,真的非常感谢的

[解决办法]
for i:=Self.ControlCount-1 downto 0 do
if (Self.Controls[i] is TMemo) then
Self.controls[i].Free;

读书人网 >.NET

热点推荐