hidrau
asked on
How to clean all components in a scrollbox?
Hello guys,
something simple but I can't reach it so far.
I create a simple an example, maybe I am doing something wrong in my code that I haven't figured out so far.
Please, take a look at the code
As you can see, first I create some labes in a scrollbox but I can't clear it with my code to free all labels, why?
thanks
Alex
something simple but I can't reach it so far.
I create a simple an example, maybe I am doing something wrong in my code that I haven't figured out so far.
Please, take a look at the code
procedure TForm1.sSpeedButton3Click(Sender: TObject);
var
i, x : Integer;
L : TLabel;
begin
x := 10;
for i := 0 to 20 do
Begin
L := TLabel.Create(self);
L.Parent := ScrollBox1;
L.Name := 'L' + IntToStr(i);
L.top := x;
L.Caption := 'Teste_' + IntToStr(i);
Inc(x,20);
End;
end;
procedure TForm1.sSpeedButton4Click(Sender: TObject);
var
i : Integer;
begin
for i := ScrollBox1.ComponentCount-1 downto 0 do
Begin
if ScrollBox1.Components[i] is TLabel Then
TLabel(ScrollBox1.Components[i]).Free
End;
end;
As you can see, first I create some labes in a scrollbox but I can't clear it with my code to free all labels, why?
thanks
Alex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
there is another thread that I opened, if you can, please help on that.
ASKER
thanks
ASKER
Sinisav, something that I noticed,
For labels is ok, but I am having problem with edits.
When I created some Edits.create(scrollbox1) I wasn't able to use this code:
TEdit(Findcomponent('ED0') ).setFocus
How can I find my first Edit now?
For labels is ok, but I am having problem with edits.
When I created some Edits.create(scrollbox1) I wasn't able to use this code:
TEdit(Findcomponent('ED0')
How can I find my first Edit now?
ASKER
I got it this way
for X := 0 to sScrollBox1.ComponentCount-1 do
Begin
if UpperCase(sScrollBox1.Components[X].Name) = 'ED0' Then
Begin
TsEdit( sScrollBox1.Components[X] ).SetFocus;
Break;
End;
End;
and that is right way... .ComponentCount and Components iterate child components under parent....
ASKER
I also understood my mistake now