Answer the question
In order to leave comments, you need to log in
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
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;
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 questionAsk a Question
731 491 924 answers to any question