Problem with ControlCount
Posted on 2000-03-17
I have components titled zComp1, zComp2, zComp3, etc. I want to be able to change the parent of the components, but only those with the letter z. They are in a ScrollBox, and I want to change the parent to the Panel.
for num := 0 to ScrollBox1.ControlCount - 1 do begin
ChildControl := ScrollBox1.Controls[num];
if ChildControl.Name = 'z' then
ChildControl.Parent := Panel1;
This code works, except not with the Name. If I wrote:
if ChildControl.Name = 'zComp1' then
Then it would work fine. But I want to check for all components that start with the letter z. It has a list index out of bounds error. If I type:
for num := 0 to ScrollBox1.ControlCount - 2 do begin
Then it works also, but it always leaves one of the controls on the ScrollBox. I don't understand why I am getting the error. Any help would be appreciated.