for I:=0 to self.ComponentCount-1 do
begin
if self.Components.ClassName='TEdit' then
if (self.Components as tedit).Focused then
(self.Components as tedit).Color :=clblue
else (self.Components as tedit).Color :=clwhite;
end;
假設你有20個Edit;
在Edit1的OnEnter事件中寫:
TEdit(Sender).Color := clBlue;
在Edit1的OnExit事件中寫:
TEdit(Sender).Color := clWindow;
在窗體的Create事件中寫:
var i: Integer;
begin
for i := 0 to self.ComponentCount-1 do
if self.components is TEdit then
begin
TEdit(self.components).onEnter := Edit1Enter(TEdit(self.components ));
TEdit(self.components).OnExit := Edit1Enter(TEdit(self.components ));
end;
end;
或者直接在每個Edit的OnEnter和OnExit事件中選擇Edit1的事件。