There are 10 edit controls, named Edt1,edt2,edt3 ... EDT10, how do you know which edit control's value is empty with a loop? Procedure Tform1.button2click (Sender:tobject);
Var
I:integer;
Begin
For i:=0 to Self.componentcount-1 Do//self.componentcount is the number of controls TForm1
Begin
If Self.components[i] is tedit then//Judging if the control is Tedit
Begin
if (Self.components[i] as Tedit). Text= "then ShowMessage (self.components[i). Name);
End
End
End
With this function findcomponent (const name:string) you can find any control you want and then determine if it is empty. Using the Tedit.findcomponents (edit (I)) function, I is the ordinal of the control, specifically look at the help!
Another way is to give their tag the same value, such as 1, the other default is zero, the program is as follows:
Procedure Tform1.button2click (Sender:tobject);
Var
I:integer;
Begin
For i:=0 to Self.componentcount-1 Do//self.componentcount is the number of controls TForm1
Begin
If Self.components[i] is tedit then//Judging if the control is Tedit
Begin
if (Self.components[i] as Tedit). Text= ")
and (Self.components[i] as Tedit). tag=1) Then
ShowMessage (Self.components[i]. Name);
End
End
End
Delphi Traversal Control