[Lazarus] Foreach?

Sven Barth pascaldragon at googlemail.com
Sat Jun 8 21:35:32 CEST 2013


On 08.06.2013 19:52, Antônio wrote:
> That is not so bad, since what FindComponent loop does is the same as
> Barth done with his loop, matching the name of the component.

Thinking about it a bit more in the end both approaches should be O(n):

In my approach you have the loop over all Controls and then the "loop" 
when doing the Pos. The latter can be seen as neglectable and by using 
Copy + "=" this can be reduced to a constant time. So it's O(n).

Your approach first has the constant loop from 1 to 10, then the 
FindComponent loop which is O(n) and the way of finding the correct 
component name which can be considered constant again.

So only difference might be execution speed and that would need to be 
tested especially with a random distribution of the Button controls 
among the Controls array.

Sidenote: I prefer being called by my first name on the mailing list.

Regards,
Sven







More information about the Lazarus mailing list