它的安全结算组件?
Its safe clearing component?
我使用此代码清空填写表格:
var
i: integer;
for i:=0 to componentcounts-1 do
begin
if component[i] is TEdit then
(component[i] as Tedit).text:='';
.....another component also include
end;
但我更喜欢在表单之外使用此代码,以便其他表单可以使用它
然后我创建一个过程
procedure emptyForm(f:Tform)
var
i:integer;
begin
with f do
begin
for i:=0 to componentcounts-1 do
begin
if component[i] is TEdit then
(component[i] as Tedit).text:='';
//.....another component also include
end;
end;
end;
它的保存方式是这样的?
我想没问题,但使用 'with' 有点危险。要了解原因,请记住 TForm 是 TComponent 的后代,并且具有许多与 Component[i] 相同的属性,这会导致潜在的混淆和错误。我更喜欢以下
procedure emptyForm(f:Tform);
var
i:integer;
iComponent : TComponent;
begin
for i:=0 to f.componentcount-1 do
begin
iComponent := f.Components[ I ];
if iComponent is TEdit then
begin
(iComponent as Tedit).text:='';
end;
//.....another component also include
end;
end;
我使用此代码清空填写表格:
var
i: integer;
for i:=0 to componentcounts-1 do
begin
if component[i] is TEdit then
(component[i] as Tedit).text:='';
.....another component also include
end;
但我更喜欢在表单之外使用此代码,以便其他表单可以使用它
然后我创建一个过程
procedure emptyForm(f:Tform)
var
i:integer;
begin
with f do
begin
for i:=0 to componentcounts-1 do
begin
if component[i] is TEdit then
(component[i] as Tedit).text:='';
//.....another component also include
end;
end;
end;
它的保存方式是这样的?
我想没问题,但使用 'with' 有点危险。要了解原因,请记住 TForm 是 TComponent 的后代,并且具有许多与 Component[i] 相同的属性,这会导致潜在的混淆和错误。我更喜欢以下
procedure emptyForm(f:Tform);
var
i:integer;
iComponent : TComponent;
begin
for i:=0 to f.componentcount-1 do
begin
iComponent := f.Components[ I ];
if iComponent is TEdit then
begin
(iComponent as Tedit).text:='';
end;
//.....another component also include
end;
end;