代码如下:
procedure ClearEdit(Form: TForm);
var i: integer;
begin
for i:=0 to form.ComponentCount-1 do
begin
if (form.Components[i] is Tedit) then
(form.Components[i] as Tedit).Text:='';
if (form.Components[i] is TDBedit) then
(form.Components[i] as TDBEdit).Text:='';
end;
end;执行过程发现无效果,请大家解答
procedure ClearEdit(Form: TForm);
var i: integer;
begin
for i:=0 to form.ComponentCount-1 do
begin
if (form.Components[i] is Tedit) then
(form.Components[i] as Tedit).Text:='';
if (form.Components[i] is TDBedit) then
(form.Components[i] as TDBEdit).Text:='';
end;
end;执行过程发现无效果,请大家解答
var i: integer;
begin
for i:=0 to wc.ControlCount-1 do
begin
if (wc.Controls[i] is Tedit) then
(wc.Controls[i] as Tedit).Text:=''
else if (wc.Controls[i] is TDBedit) then
(wc.Controls[i] as TDBEdit).Text:=''
else if (wc.Controls[i] is TWinControl then
ClearEdit(wc);
end;
end;
var i: integer;
begin
for i:=0 to form.ComponentCount-1 do
begin
if (form.Components[i] is Tedit) then
(form.Components[i] as Tedit).Text:='';
if (form.Components[i] is TDBedit) then
(form.Components[i] as TDBEdit).Text:='';
end;
end;找不出什么错误,不过TDBEdit可以删除掉内容吗。看看Form参数传入有没有问题。
var i: integer;
begin
for i:=0 to form1.ComponentCount-1 do
begin
if (form1.Components[i] is Tedit) then
(form1.Components[i] as Tedit).Text:='';
if (form1.Components[i] is TDBedit) then
(form1.Components[i] as TDBEdit).Text:='';
end;
end;没问题啊!
你调用了ClearEdit么
如果是动态创建的话,你就要看看owner是谁!
DBedit的数据可以用(form1.Components[i] as TDBEdit).EditText:='';来清空
------------------
测试通过!多谢,可是谁能告诉我为什么必须是self呢?准备揭贴
procedure TFormCYBase.ClearText(AControl:TWinControl);
var
I: Integer;
begin
for I := 0 to AControl.ControlCount - 1 do // Iterate
begin
//需清空处理控件
if AControl.Controls[i] is TCustomEdit then
begin
(AControl.Controls[i] as TCustomEdit).Text:='';
end;
if AControl.Controls[i] is TCustomComboBox then
begin
(AControl.Controls[i] as TCustomComboBox).ClearSelection;
end;
//可以 作为 父亲的控件处理事件。
if AControl.Controls[i] is TCustomControl then
begin
ClearText(AControl.Controls[i] as TCustomControl);
end;
end;
end;procedure TFormCYBase.BitBtn1Click(Sender: TObject);
begin
ClearText(self);
end;
Panel,GroupBox 都有可能
self相当于引用
form1相当于传值当然只有引用才起效果。
在form1中要清空form2中的内容怎么办,那么self就救不了你了!
procedure ClearEdit(Form: TForm);试一下刷新,或跟踪一下是否你要清空的edit执行了你清空的代码。
var i: integer;
begin
for i:=0 to form1.ComponentCount-1 do
begin
if (form1.Components[i] is Tedit) then
(form1.Components[i] as Tedit).Text:='';
if (form1.Components[i] is TDBedit) then
(form1.Components[i] as TDBEdit).Text:='';
end;
end;
代码没问题,看看是不是别的地方的错误。
所以必须有个递归来循环设置 form 上的所有容器控件内的 edit 才有效
ok,揭贴