Topic: How To edit Loop For Clear Multiple Edit Box ?

I want to clear multiple edit boxes using the Loop method to reduce the number of lines in scripting.
Normally I write

Form1.Edit1.Clear ;
Form1.Edit2.Clear ;
Form1.Edit3.Clear ;
Form1.Edit4.Clear ;
Form1.Edit5.Clear ;
Form1.Edit6.Clear ;
Form1.Edit7.Clear ;
Form1.Edit8.Clear ;
Form1.Edit9.Clear ;
Form1.Edit10.Clear;

But if I want to write a Loop?

For i := 1 To 10 do
  begin
    Form1.Edit[i].Clear ; // How To Edit Script 
  end;

Help Me Please ?

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How To edit Loop For Clear Multiple Edit Box ?

Hello Prahousefamily
You could use this snippet.
often use it and it makes the job.
JB

Re: How To edit Loop For Clear Multiple Edit Box ?

Oups I've forgotten the snippet
JB

Post's attachments

Attachment icon Example.txt 451 b, 43 downloads since 2024-06-27 

4 (edited by prahousefamily 2024-06-28 03:19:08)

Re: How To edit Loop For Clear Multiple Edit Box ?

jean.brezhonek wrote:

Oups I've forgotten the snippet
JB


Thank  JB Script It

procedure frmEmployee_OnClose (Sender: string; Action: string);
var     i,c: integer;
begin
    c := frmEmployee.ComponentCount-1;
    for i := 0 to c do
    begin
        if frmEmployee.Components[i] is TdbEdit then TdbEdit(frmEmployee.Components[i]).Clear;       //  Dans le cas d'un TEdit
        if frmEmployee.Components[i] is TdbMemo then TdbMemo(frmEmployee.Components[i]).Clear;       //  Dans le cas d'un TMemo
    end;
end;
JB

✓ Check IF TdbEdit >>> Clear Thank you JB

Um..... And IF
1. TdbEdit ✓
2. copy(Component_Name,5,Length(Component_Name)) MOD 2 = 0
How Do Edit Scipt ???

Form1.Edit1.Text
Form1.Edit2.Clear // Because (1. TdbEdit)+ (2. Component_Name MOD 2 = 0)
Form1.Edit3.Text
Form1.Edit4.Clear // Because (1. TdbEdit)+ (2. Component_Name MOD 2 = 0)
My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How To edit Loop For Clear Multiple Edit Box ?

It's not entirely clear what you want to achieve?
Decide on your goal.
It all depends on your task.
1 For example, fields that need to be cleared constantly may have a different name, even with numbers.
You can search by the initial letters of the name on the form and clear them. For example ClrEdit2, ClrEdit11.
2 You can assign a unique TAG to such EDITs and then access them by searching for the value in the TAG.
3 If you want to use a parity check, select for such Edits, for example, the range Edit21...Edit39. Take the name, read 2 characters from the end, convert to an integer, check parity and clear.
But is all this worth replacing 10 lines of code Edit1.clear...Edit10.clear.
If you want to reduce the number of lines in the script, write this:

Form1.Edit1.Clear; Form1.Edit2.Clear; Form1.Edit3.Clear; Form1.Edit4.Clear; Form1.Edit5.Clear;
Form1.Edit6.Clear; Form1.Edit7.Clear; Form1.Edit8.Clear; Form1.Edit9.Clear; Form1.Edit10.Clear;

This is also possible and only two lines.