R
R
Rphoenix2018-02-22 23:05:44
Delphi
Rphoenix, 2018-02-22 23:05:44

Loop through elements?

Hello!
I'm learning Delphi on my own. Here is a question. Let's say I have 100 buttons (N0..N99) on the form. I need to hide them except for some 5 (N98,N7,N3,N85,N12) i.e. form1.N26.Visible:=False - for example.
It turns out that I need a for loop from 0 to 99. Where if [i] in (3,7...98), then form1.N26.Visible:=true, else form1.N[i].Visible:=False.
Correctly? or what is the best way to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Forxxx, 2018-02-26
@Forxxx

I would advise you to deal with is and as, and, as mentioned above, use tag

for i := 0 to Form1.ComponentCount - 1 do
    if (Form1.Components[i] is TButton) then
      if (Form1.Components[i] as TButton).Tag in [1,2,3] then
        (Form1.Components[i] as TButton).Enabled := false;

K
Konstantin Tsvetkov, 2018-02-22
@tsklab

Correctly?
Yes. Although it is not clear how you use the name and number of the cycle at the same time? I would use the .tag property for the button number .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question